我想列出程序从特定库加载的符号。您可以使用ldd:
列出所需的库 ldd -v myExecutable
这给出了类似下面的输出:
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
现在我想知道从哪个库加载了哪些符号。具体来说,在我的情况下,我想找到那些从GLIBC_2.11加载并最终摆脱它们。
(我已经使用ligcc来避免链接新符号 - 现在我想看看在2.11之前哪些符号不可用了)
答案 0 :(得分:1)
使用LD_DEBUG
环境变量。 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]
有关详细信息,请参阅man ld.so
。
答案 1 :(得分:1)
nm
可能会满足你所追求的目标。刚刚在我的可执行文件中使用它,它确实提供了库的版本以及符号。例如:
U tan@@GLIBC_2.0
所以你可以做一个grep来找到你感兴趣的版本。