知识库

个人知识管理

用户工具

站点工具


linux:linux下查看so库的一些工具

linux下查看so库的一些工具

查看文件类型

命令: file

样例:

file /bin/ls

输出:

/bin/ls: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=8d0966ce81ec6609bbf4aa439c77138e2f48a471, stripped

查看可执行命令依赖的so库

命令: ldd

样例:

ldd /bin/ls

输出

ldd /bin/ls
  linux-vdso.so.1 =>  (0x00007ffc7fb7d000)
  libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f5c6dbd2000)
  libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f5c6d9ca000)
  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5c6d600000)
  libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f5c6d3c2000)
  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5c6d1be000)
  /lib64/ld-linux-x86-64.so.2 (0x00005568aba14000)
  libattr.so.1 => /lib/x86_64-linux-gnu/libattr.so.1 (0x00007f5c6cfb8000)

查看可执行文件的so库依赖关系

命令: readelf

样例:

readelf -d /bin/ls

输出

Dynamic section at offset 0x19e08 contains 26 entries:
    Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [libselinux.so.1]
0x0000000000000001 (NEEDED)             Shared library: [libacl.so.1]
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
0x000000000000000c (INIT)               0x402168
0x000000000000000d (FINI)               0x411efc
0x0000000000000019 (INIT_ARRAY)         0x619df0
0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
0x000000000000001a (FINI_ARRAY)         0x619df8
0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
0x000000006ffffef5 (GNU_HASH)           0x400298
0x0000000000000005 (STRTAB)             0x400f18
0x0000000000000006 (SYMTAB)             0x400300
0x000000000000000a (STRSZ)              1427 (bytes)
0x000000000000000b (SYMENT)             24 (bytes)
0x0000000000000015 (DEBUG)              0x0
0x0000000000000003 (PLTGOT)             0x61a000
0x0000000000000002 (PLTRELSZ)           2688 (bytes)
0x0000000000000014 (PLTREL)             RELA
0x0000000000000017 (JMPREL)             0x4016e8
0x0000000000000007 (RELA)               0x401640
0x0000000000000008 (RELASZ)             168 (bytes)
0x0000000000000009 (RELAENT)            24 (bytes)
0x000000006ffffffe (VERNEED)            0x4015b0
0x000000006fffffff (VERNEEDNUM)         2
0x000000006ffffff0 (VERSYM)             0x4014ac
0x0000000000000000 (NULL)               0x0

查看so库中提供了哪些方法

命令: nm

样例:

nm libhello.so | grep T

*注:* libhello.so的源文件如下:

#include "library.h"
#include <stdio.h>
void hello(void) {
  printf("Hello, World!\n");
}

输出:

00000000000006d8 T _fini
0000000000201000 d _GLOBAL_OFFSET_TABLE_
00000000000006c5 T hello
0000000000000580 T _init
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000200e00 d __JCR_LIST__
0000000000201038 d __TMC_END__
linux/linux下查看so库的一些工具.txt · 最后更改: 2019/09/11 00:49 (外部编辑)