Dlopen with two shared libraries, export symbols

I have a linux shared library, foo.so, which is loaded from an executable using dlopen("foo.so", RTLD_NOW | RTLD_LOCAL) . From foo.so, I would like to dlopen another bar.so library that references the characters defined in foo.so, but the linker does not find them. I canโ€™t change RTLD_LOCAL to RTLD_GLOBAL because I donโ€™t have the source of the executable loading the file. I thought that -Wl,--export-dynamic , when the foo.so link can help, but does not undo the local flag in dlopen. The visibility function of the new GCC attribute is not like it is offering an answer.

Is there a way that I can give the linker the linker to allow references to undefined characters in bar.so for these definitions in foo.so, without binding the line with -lfoo or similarity of moving characters in the 3rd library and linking both foo and the bar against it ? The only thing that happens to me is dlopen foo.so with RTLD_GLOBAL from foo.so itself, then dlopen bar.so, but it hits me like a bit of a mess. Thanks.

+6
linux shared-libraries dlopen
source share
1 answer

Link foo.so to bar.so

When the dlopen() foo.so , bar.so .

Alternatively, a binary-patch executable to add RTLD_GLOBAL to the flags for calling dlopen() . The code will look something like this:

  movl $2, 4(%esp) # $2 == RTLD_NOW; RTLD_LOCAL is 0 movl $0xNNNNN, (%esp) # $0xNNNNN == &"foo.so" call dlopen 

movl $0x102, 4(%esp) instead of movl $0x102, 4(%esp) ( RTLD_GLOBAL == 0x100 ) and voilร .

EDIT:
If you know the name bar.so , you can associate foo.so with the stub bar.so It does not matter that you do not have a "real" bar.so ; all that matters is that foo.so has a dependency on it. At run time, this dependency will load bar.so when foo.so loaded.

+4
source share

All Articles