1

Assuming that you have the name of a symbol ( demangled or not ) and the name of a library dynamically linked to others, you want to find out which library is able to resolve that symbol.

I tried to use nm, objdump and readelf and I can't find good documentation about it, looks like it's not possible with this tools.

gdb offers something similar but it's a debugger, I need something for a quick lookup, Do you know how to do this without firing up a debug session?

user2485710
  • 9,451
  • 13
  • 58
  • 102

1 Answers1

1

You can use debugging facilities of ld-linux.so.2 to look for symbol resolution in elf objects (the example is for amd64, the dynamic loader name is reflecting this fact):

 LD_DEBUG=symbols,bindings /lib/ld-linux-x86-64.so.2 /bin/ls

The above will print lines to the tune:

 60157:     symbol=fclose;  lookup in file=/bin/ls [0]
 60157:     symbol=fclose;  lookup in file=/lib64/librt.so.1 [0]
 60157:     symbol=fclose;  lookup in file=/lib64/libcap.so.2 [0]
 60157:     symbol=fclose;  lookup in file=/lib64/libacl.so.1 [0]
 60157:     symbol=fclose;  lookup in file=/lib64/libc.so.6 [0]
 60157:     binding file /bin/ls [0] to /lib64/libc.so.6 [0]: normal symbol `fclose' [GLIBC_2.2.5]

Then you can grep the output to find whatever info you need.

You can call the linker on any elf object, libraries included:

LD_DEBUG=symbols,bindings /lib/ld-linux-x86-64.so.2 /lib/libm.so.6
oakad
  • 6,945
  • 1
  • 22
  • 31