lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 21.09.2013 09:23 schröbte Francesco Santini:
Il 19/09/2013 18:19, Philipp Janda ha scritto:
There is a glibc-specific dlopen-flag (man 3 dlopen):
RTLD_NOLOAD (since glibc 2.2)
     Don't load the library. This can be used to test if the library is
already resident (dlopen() returns NULL if it is not, or the library's
handle if it is resident). This flag can also be used to promote the
flags on a library that is already loaded. For example, a library that
was previously loaded with RTLD_LOCAL can be reopened with RTLD_NOLOAD |
RTLD_GLOBAL. This flag is not specified in POSIX.1-2001.

I don't know if this also works from within the dynamically loaded
library, but you can try (and tell us how it went) ...

Thank you Philipp for the great explanation, it was very informative.
What you proposed eventually did not work (it seems that a library
cannot call dlopen on itself) but it pointed me in the right directon.

I'm glad that you got it to work. But I can confirm that reloading the library from within itself also works, even if Lua is linked in dynamically (which surprised me). Maybe your plugin wasn't in the default library search path? Did you use a path name (containing a slash), or a file name for your dlopen call?


What I did was to call dlopen("libluajit.so", RTLD_NOW | RTLD_GLOBAL)
from within the library so that the lua symbols were loaded in the
global namespace and therefore available for the subsequent modules.

The man page only states that:
[...] But a subsequent call with RTLD_NOW may force symbol resolution for a library earlier loaded with RTLD_LAZY.
Apparently this forced symbol resolution also applies the other flags.
Just make sure that you are not accidentally linking in a second luajit runtime different from the one your plugin is linked to ...
This is something that cannot happen if you use RTLD_NOLOAD.


Now everything works again and I didn't have to change anything in the
modules!

Francesco


Philipp