3

我想列出程序从特定库加载的符号。您可以使用 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 之前不可用)

4

2 回答 2

2

使用LD_DEBUG环境变量。例如:

$ 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

于 2012-09-18T14:40:07.510 回答
2

nm可能会满足你的追求。刚刚在我的可执行文件上使用了它,它确实提供了库的版本以及符号。例如:

U tan@@GLIBC_2.0

so you could do a grep to find only the version you're interested in.

于 2012-09-18T14:40:15.917 回答