all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacs25 dynamic module dlopen flags
@ 2016-09-13  0:16 hx
  2016-09-13  6:25 ` Philipp Stephani
  0 siblings, 1 reply; 5+ messages in thread
From: hx @ 2016-09-13  0:16 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

current dlopen flag is RTLD_LAZY,
//src/dynlib.c

dynlib_handle_ptr
dynlib_open (const char *path)
{
  return dlopen (path, RTLD_LAZY);
}

my module will also load other shared libs, I got some error like
symbol undefined,

I found this article http://www.perlmonks.org/?node_id=673396 ,

after I changed dlopen flags to RTLD_LAZY|RTLD_GLOBAL in src/dynlib.c,
the problem is solved.


could emacs developer consider to add the RTLD_GLOBAL flag in emacs's
source code ?

thanks!

[-- Attachment #2: Type: text/html, Size: 1132 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: emacs25 dynamic module dlopen flags
  2016-09-13  0:16 emacs25 dynamic module dlopen flags hx
@ 2016-09-13  6:25 ` Philipp Stephani
  2016-09-13  8:44   ` hx
  0 siblings, 1 reply; 5+ messages in thread
From: Philipp Stephani @ 2016-09-13  6:25 UTC (permalink / raw)
  To: hx, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 786 bytes --]

hx <silent2600@gmail.com> schrieb am Di., 13. Sep. 2016 um 02:17 Uhr:

> current dlopen flag is RTLD_LAZY,
> //src/dynlib.c
>
> dynlib_handle_ptr
> dynlib_open (const char *path)
> {
>   return dlopen (path, RTLD_LAZY);
> }
>
> my module will also load other shared libs, I got some error like symbol undefined,
>
> I found this article http://www.perlmonks.org/?node_id=673396 ,
>
> after I changed dlopen flags to RTLD_LAZY|RTLD_GLOBAL in src/dynlib.c, the problem is solved.
>
>
> could emacs developer consider to add the RTLD_GLOBAL flag in emacs's source code ?
>
>
>
Reading the manpage of dlopen, I don't think this flag should be added.
Emacs modules should typically export only two symbols
(plugin_is_GPL_compatible and emacs_module_init), which aren't useful
outside Emacs.

[-- Attachment #2: Type: text/html, Size: 2093 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: emacs25 dynamic module dlopen flags
  2016-09-13  6:25 ` Philipp Stephani
@ 2016-09-13  8:44   ` hx
  2017-02-26 15:43     ` Philipp Stephani
  2017-03-06 21:24     ` Davis Herring
  0 siblings, 2 replies; 5+ messages in thread
From: hx @ 2016-09-13  8:44 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1884 bytes --]

On Tue, Sep 13, 2016 at 2:25 PM, Philipp Stephani <p.stephani2@gmail.com>
wrote:

>
>
> hx <silent2600@gmail.com> schrieb am Di., 13. Sep. 2016 um 02:17 Uhr:
>
>> current dlopen flag is RTLD_LAZY,
>> //src/dynlib.c
>>
>> dynlib_handle_ptr
>> dynlib_open (const char *path)
>> {
>>   return dlopen (path, RTLD_LAZY);
>> }
>>
>> my module will also load other shared libs, I got some error like symbol undefined,
>>
>> I found this article http://www.perlmonks.org/?node_id=673396 ,
>>
>> after I changed dlopen flags to RTLD_LAZY|RTLD_GLOBAL in src/dynlib.c, the problem is solved.
>>
>>
>> could emacs developer consider to add the RTLD_GLOBAL flag in emacs's source code ?
>>
>>
>>
> Reading the manpage of dlopen, I don't think this flag should be added.
> Emacs modules should typically export only two symbols
> (plugin_is_GPL_compatible and emacs_module_init), which aren't useful
> outside Emacs.
>


thanks for your reply,
here is the detail:
my emacs module linked with libperl.so,
when perl interpreter in the module execute some scripts, it may load other
.so files depending on which perl package is going to be loaded,
for example, DBD::mysql will load DBD/mysql/mysql.so, Socket will
load Socket.so,
without that flag, loading Socket.so will fail, the error message is like
Socket.so can't find some symbols from libperl.so .
it may look like the problem is in libperl.so,
but if I add RTLD_GLOBAL in emacs/src/dynlib.c, Socket.so will be loaded
successful,

if modify my module code and compile it as a standalone application, still
do same process(create perl interpreter and execute perl script), it also
can load Socket.pm and Socket.so.

so I think lack of RTLD_GLOBAL in emacs stops libperl.so loading Socket.so .

# nm -a mymodule.so |grep PL_thr
         U PL_thr_key

I did see error message complain symbol PL_thr_key is undefined when
loading other perl *.so.

[-- Attachment #2: Type: text/html, Size: 3704 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: emacs25 dynamic module dlopen flags
  2016-09-13  8:44   ` hx
@ 2017-02-26 15:43     ` Philipp Stephani
  2017-03-06 21:24     ` Davis Herring
  1 sibling, 0 replies; 5+ messages in thread
From: Philipp Stephani @ 2017-02-26 15:43 UTC (permalink / raw)
  To: hx; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2312 bytes --]

hx <silent2600@gmail.com> schrieb am Di., 13. Sep. 2016 um 10:45 Uhr:

>
> On Tue, Sep 13, 2016 at 2:25 PM, Philipp Stephani <p.stephani2@gmail.com>
> wrote:
>
>
>
> hx <silent2600@gmail.com> schrieb am Di., 13. Sep. 2016 um 02:17 Uhr:
>
> current dlopen flag is RTLD_LAZY,
> //src/dynlib.c
>
> dynlib_handle_ptr
> dynlib_open (const char *path)
> {
>   return dlopen (path, RTLD_LAZY);
> }
>
> my module will also load other shared libs, I got some error like symbol undefined,
>
> I found this article http://www.perlmonks.org/?node_id=673396 ,
>
> after I changed dlopen flags to RTLD_LAZY|RTLD_GLOBAL in src/dynlib.c, the problem is solved.
>
>
> could emacs developer consider to add the RTLD_GLOBAL flag in emacs's source code ?
>
>
>
> Reading the manpage of dlopen, I don't think this flag should be added.
> Emacs modules should typically export only two symbols
> (plugin_is_GPL_compatible and emacs_module_init), which aren't useful
> outside Emacs.
>
>
>
> thanks for your reply,
> here is the detail:
> my emacs module linked with libperl.so,
> when perl interpreter in the module execute some scripts, it may load
> other .so files depending on which perl package is going to be loaded,
> for example, DBD::mysql will load DBD/mysql/mysql.so, Socket will
> load Socket.so,
> without that flag, loading Socket.so will fail, the error message is like
> Socket.so can't find some symbols from libperl.so .
> it may look like the problem is in libperl.so,
> but if I add RTLD_GLOBAL in emacs/src/dynlib.c, Socket.so will be loaded
> successful,
>
> if modify my module code and compile it as a standalone application, still
> do same process(create perl interpreter and execute perl script), it also
> can load Socket.pm and Socket.so.
>
> so I think lack of RTLD_GLOBAL in emacs stops libperl.so loading Socket.so
> .
>
> # nm -a mymodule.so |grep PL_thr
>          U PL_thr_key
>
> I did see error message complain symbol PL_thr_key is undefined when
> loading other perl *.so.
>
>
>
Unfortunately I know too little about shared objects to provide an
authoritative answer, but IIUC plugin systems should always use RTLD_LOCAL
so that separate plugins can define the same symbols without interfering
with each other. But a person who is more knowledgeable about shared object
should probably comment.

[-- Attachment #2: Type: text/html, Size: 5579 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: emacs25 dynamic module dlopen flags
  2016-09-13  8:44   ` hx
  2017-02-26 15:43     ` Philipp Stephani
@ 2017-03-06 21:24     ` Davis Herring
  1 sibling, 0 replies; 5+ messages in thread
From: Davis Herring @ 2017-03-06 21:24 UTC (permalink / raw)
  To: hx, Philipp Stephani; +Cc: emacs-devel

> my emacs module linked with libperl.so,
> when perl interpreter in the module execute some scripts, it may load other
> .so files depending on which perl package is going to be loaded,
> for example, DBD::mysql will load DBD/mysql/mysql.so, Socket will
> load Socket.so,
> without that flag, loading Socket.so will fail, the error message is like
> Socket.so can't find some symbols from libperl.so .
> it may look like the problem is in libperl.so,
> but if I add RTLD_GLOBAL in emacs/src/dynlib.c, Socket.so will be loaded
> successful,

I've had the same issues with Python (playing the role of Emacs here): 
it uses RTLD_LOCAL, which is fine for the "top level" .so but bad for 
the (DT_NEEDED) dependencies because they should be made available to 
other things which might have them as dependencies.  (Otherwise you can 
get duplicate symbols loaded, which breaks things that have vague 
linkage (from C++) or which have static duration variables.)

Unfortunately, the fixed names that Philipp mentioned prevent this from 
working: you can't load two such things with RTLD_GLOBAL because the 
names will collide.  Python doesn't have that problem because it looks 
for a symbol initfoo in a module named foo.  If modules are careful to 
make all their other symbols have internal linkage (or have hidden ELF 
visibility), it should be an improvement (although Ulrich Drepper's 
piece on the subject calls RTLD_GLOBAL "usually a very bad idea").

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or 
too sparse, it is because mass-energy conversion has occurred during 
shipping.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-06 21:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-13  0:16 emacs25 dynamic module dlopen flags hx
2016-09-13  6:25 ` Philipp Stephani
2016-09-13  8:44   ` hx
2017-02-26 15:43     ` Philipp Stephani
2017-03-06 21:24     ` Davis Herring

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.