[Bug dynamic-link/12939] resolving shared library symbols returns wrong file

alexander.long91 at gmail dot com sourceware-bugzilla@sourceware.org
Wed Jul 2 15:39:00 GMT 2014


https://sourceware.org/bugzilla/show_bug.cgi?id=12939

--- Comment #2 from Alex Long <alexander.long91 at gmail dot com> ---
As suggested in the dladdr() man-page, compiling your code to be position
independent, using -fPIC for example, may cause dladdr to return the path to
the shared library the symbol comes from rather than return the path to the
executable. 

However, one issue with this that I've noticed is that when building on or
cross-compiling for armv7l, dladdr will always return the path to the
executable for exported symbols that also happen to be called within the
program.

When compiled with 
/usr/bin/g++-4.7 main.cpp -o main-ARM -Wall -Wextra -ldl -fPIC

the attached example program prints
"printf comes from /lib/x86_64-linux-gnu/libc.so.6" on x86_64 machines
and
"printf comes from ./main" on armv7l

-- 
You are receiving this mail because:
You are on the CC list for the bug.



More information about the Glibc-bugs mailing list