Sunday, 15 September 2013

linux - How to make dlerror() report *all* unresolved symbols from dlopen() failure to load shared library? -


I try to report all unsuccessful symbols to a shared library on a failed call by reporting to Dlpann () I am here. I have tried both RTLD_LAZY and RTLD_NOW as the flag for the delplay call. I know that 10 missing symbols in the shared library (i.e. if you have blasted a static link G +: link 10 will fail from missing symbols). I have to get a DelRar (), to tell me about all the 10 missing symbols during the failed load.

Does anyone know how this is happening? I have been seen from the man page that the dealer () returns the final error; So maybe I'm asking too much but I wonder if someone knows.

Thank you very much,

Can the loader report the error as soon as it shows that the library can not be loaded (as soon as it searches for the first missing symbol) the loader does not have any meaning And it's not so.

However, you can simulate using ldd -r by using LD_PRELOAD and LD_TRACE_LOADED_OBJECTS Example:

 Include  $ cat main.c # & lt; Dlfcn.h & gt; # Include & lt; Stdio.h & gt; Int main () {void * p = dlopen (". / Foo.so", RTLD_NOW); If (p == NULL) {printf ("% s \ n", dealer ()); Return 1; } Return 0; } $ Cat foo.c int bar (), falcon (); // is not defined anywhere foo () {return bar () + baz (); } $ Gcc main.c -ldl; GCC-FPIC-SHARE -OU FU.SU FUO. Co .. / AA.T. / FOSO: Undefined Symbol: Falcon # Only the first symbol is reported in $ ldd -r ./a.out linux-vdso.so .1 = & gt; (0x00007fff52ddc000) libdl.so.2 = & gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f158e48d000) libc.so.6 = & gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f158e0ce000) /lib64/ld-linux-x86-64.so.2 (0x00007f158e6b2000)   

This does not work , Because your program was not executed, and thus never loaded foo.so . But for the rescue LD_PRELOAD :

  $ LD_BIND_NOW = 1 LD_WARN = 1 LD_TRACE_LOADED_OBJECTS = 1 LD_PRELOAD =. / Foo.so./a.out linux-vdso.so1 = & gt; (0x00007fff3c1b6000) ./foo.so (0x00007ffd33212000) libdl.so.2 = & gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffd3300e000) libc.so.6 = & gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffd32c4f000) /lib64/ld-linux-x86-64.so.2 (0x00007ffd33414000) Undefined Symbol: Falcon (./foo.so) Undefined Icons: Bar ( ./foo.so)   

WILE: Now all unresolved symbols have been reported.

No comments:

Post a Comment