lua-users home
lua-l archive

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


Short question: what is the rationale for Lua loading Cextensions as RTLD_LOCAL by default?
Long story: I have several C extensions with dependenciesbetween them.
         +---+     +-->| A |<--+     |   +---+   |     |           |   +---+       +---+   | B |       | C |   +---+       +---+
These dependencies are C-level dependencies; ie. A containsa C function foo() that B and C call.
Now I could tell the linker about these dependencies whenI compile these modules.  That would make the OS aware ofthese dependencies, and make it automatically load A whenB or C are loaded.
But this approach has a couple downsides:
1. Users now need to set both LUA_CPATH *and* LD_LIBRARY_PATH   correctly.  Kind of a big pain, especially since the two   have different failures modes so it's not immediately   obvious which one you got wrong.  Also, the LD_LIBRARY_PATH   part is inherently OS-specific, and is different on OS X.
2. If the user wants to install your library, they will expect   to *not* have to set LD_LIBRARY_PATH, so you have to install   into /usr/lib or /usr/local/lib, and give it an soname that   won't conflict with anything else on the system.  But this   is a little weird, because the library isn't intended to   be used from C, it's *only* intended to be loaded by Lua.
What I wish I could do is just provide, from Lua, that A is alwaysloaded before B or C.  This is easy to do with some trivialwrappers:
-- b.luaimport("a")return import("b_cext")
-- c.luaimport("a")return import("c_cext")
This would be a really nice solution that solves both of theabove problems.  But unfortunately it is not possible becauserequire() loads C libraries with RTLD_LOCAL.  That means thatthe symbols loaded in A are not available to be linked againstfrom B or C.
Any thoughts or workarounds?
Thanks,Josh