Reputation: 466
I'd like to list the symbols a program loads from a specific library. You can list the needed libraries with ldd:
ldd -v myExecutable
This gives something like the following output:
libgcc_s.so.1 (GCC_3.0) => /lib/i386-linux-gnu/libgcc_s.so.1
libc.so.6 (GLIBC_2.1) => /lib/i386-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.11) => /lib/i386-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.1.3) => /lib/i386-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.0) => /lib/i386-linux-gnu/libc.so.6
Now I'd like to know which symbols are loaded from which library. Specifically, in my case I'd like to find those that are loaded from GLIBC_2.11 and eventually get rid of them.
(I'm already using ligcc to avoid linking against new symbols - now I'd like to see which symbols are not available before 2.11)
Upvotes: 5
Views: 4422
Reputation: 136198
Use LD_DEBUG
environment variable. E.g.:
$ LD_USE_LOAD_BIAS=0 LD_DEBUG=all ls |& grep binding
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `_res' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `_IO_file_close' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `stderr' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `error_one_per_line' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__malloc_initialize_hook' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol `_dl_starting_up' [GLIBC_PRIVATE]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__morecore' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__key_encryptsession_pk_LOCAL' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__progname_full' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__ctype32_tolower' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `_environ' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol `_rtld_global' [GLIBC_PRIVATE]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__progname' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `argp_err_exit_status' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `mallwatch' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `__rcmd_errstr' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/libc.so.6 [0]: normal symbol `svcauthdes_stats' [GLIBC_2.2.5]
22160: binding file /lib64/libc.so.6 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol `__libc_enable_secure' [GLIBC_PRIVATE]
[...]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__libc_start_main' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `strrchr' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `setlocale' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `bindtextdomain' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `textdomain' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__cxa_atexit' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `isatty' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `getenv' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__ctype_b_loc' [GLIBC_2.3]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__errno_location' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `strtoul' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `ioctl' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `getopt_long' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `malloc' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `memcpy' [GLIBC_2.14]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `strlen' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `opendir' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `readdir' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `closedir' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `free' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `_setjmp' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `strcoll' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__ctype_get_mb_cur_max' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `fwrite_unlocked' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `exit' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__fpending' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `fileno' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `__freading' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `fflush' [GLIBC_2.2.5]
22160: binding file ls [0] to /lib64/libc.so.6 [0]: normal symbol `fclose' [GLIBC_2.2.5]
For more details see man ld.so
.
Upvotes: 2
Reputation: 3688
nm
might satisfy what you're after. Just used it on my executable, and it does give versions of the library along with the symbol. eg:
U tan@@GLIBC_2.0
so you could do a grep to find only the version you're interested in.
Upvotes: 3