溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

GNU Binutils中readelf命令怎么用

發(fā)布時(shí)間:2021-11-20 17:32:17 來(lái)源:億速云 閱讀:195 作者:小新 欄目:互聯(lián)網(wǎng)科技

這篇文章主要介紹GNU Binutils中readelf命令怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

在調(diào)試libdrm時(shí),查看libdrm.so依賴哪些庫(kù),用到了readelf命令,簡(jiǎn)單記錄下該命令的用法。

1、顯示ELF文件頭信息

root@ubuntu:/home/run/code# readelf -h libdrm.so.2.4.0ELF Header:  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  Class:                             ELF64  Data:                              2's complement, little endian  Version:                           1 (current)  OS/ABI:                            UNIX - System V  ABI Version:                       0  Type:                              DYN (Shared object file)  Machine:                           AArch74  Version:                           0x1  Entry point address:               0x3cb0  Start of program headers:          64 (bytes into file)  Start of section headers:          58304 (bytes into file)  Flags:                             0x0  Size of this header:               64 (bytes)  Size of program headers:           56 (bytes)  Number of program headers:         6  Size of section headers:           64 (bytes)  Number of section headers:         25  Section header string table index: 24

2、顯示動(dòng)態(tài)段信息

root@ubuntu:/home/run/code# readelf -d libdrm.so.2.4.0Dynamic section at offset 0xddb8 contains 27 entries:  Tag        Type                         Name/Value 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6] 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6] 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-aarch74.so.1] 0x000000000000000e (SONAME)             Library soname: [libdrm.so.2] 0x000000000000000c (INIT)               0x3720 0x000000000000000d (FINI)               0xbc34 0x0000000000000019 (INIT_ARRAY)         0x1dda0 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes) 0x000000000000001a (FINI_ARRAY)         0x1dda8 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes) 0x000000006ffffef5 (GNU_HASH)           0x1b8 0x0000000000000005 (STRTAB)             0x1e08 0x0000000000000006 (SYMTAB)             0x728 0x000000000000000a (STRSZ)              3554 (bytes) 0x000000000000000b (SYMENT)             24 (bytes) 0x0000000000000003 (PLTGOT)             0x1dfe8 0x0000000000000002 (PLTRELSZ)           2040 (bytes) 0x0000000000000014 (PLTREL)             RELA 0x0000000000000017 (JMPREL)             0x2f28 0x0000000000000007 (RELA)               0x2e38 0x0000000000000008 (RELASZ)             240 (bytes) 0x0000000000000009 (RELAENT)            24 (bytes) 0x000000006ffffffe (VERNEED)            0x2dd8 0x000000006fffffff (VERNEEDNUM)         3 0x000000006ffffff0 (VERSYM)             0x2bea 0x000000006ffffff9 (RELACOUNT)          3 0x0000000000000000 (NULL)               0x0

該命令可查看該動(dòng)態(tài)庫(kù)依賴哪些庫(kù),方便動(dòng)態(tài)庫(kù)調(diào)試時(shí),更新所需的動(dòng)態(tài)庫(kù)。

readelf可查看:可執(zhí)行文件,動(dòng)態(tài)庫(kù)(.so)和靜態(tài)庫(kù)(.a)。

3.顯示段表信息

root@ubuntu:/home/run/code# readelf -S libdrm.so.2.4.0There are 25 section headers, starting at offset 0xe3c0:Section Headers:  [Nr] Name              Type             Address           Offset       Size              EntSize          Flags  Link  Info  Align  [ 0]                   NULL             0000000000000000  00000000       0000000000000000  0000000000000000           0     0     0  [ 1] .note.gnu.build-i NOTE             0000000000000190  00000190       0000000000000024  0000000000000000   A       0     0     4  [ 2] .gnu.hash         GNU_HASH         00000000000001b8  000001b8       000000000000056c  0000000000000000   A       3     0     8  [ 3] .dynsym           DYNSYM           0000000000000728  00000728       00000000000016e0  0000000000000018   A       4     3     8  [ 4] .dynstr           STRTAB           0000000000001e08  00001e08       0000000000000de2  0000000000000000   A       0     0     1  [ 5] .gnu.version      VERSYM           0000000000002bea  00002bea       00000000000001e8  0000000000000002   A       3     0     2  [ 6] .gnu.version_r    VERNEED          0000000000002dd8  00002dd8       0000000000000060  0000000000000000   A       4     3     8  [ 7] .rela.dyn         RELA             0000000000002e38  00002e38       00000000000000f0  0000000000000018   A       3     0     8  [ 8] .rela.plt         RELA             0000000000002f28  00002f28       00000000000007f8  0000000000000018  AI       3    20     8  [ 9] .init             PROGBITS         0000000000003720  00003720       0000000000000014  0000000000000000  AX       0     0     4  [10] .plt              PROGBITS         0000000000003740  00003740       0000000000000570  0000000000000010  AX       0     0     16  [11] .text             PROGBITS         0000000000003cb0  00003cb0       0000000000007f84  0000000000000000  AX       0     0     8  [12] .fini             PROGBITS         000000000000bc34  0000bc34       0000000000000010  0000000000000000  AX       0     0     4  [13] .rodata           PROGBITS         000000000000bc48  0000bc48       0000000000001658  0000000000000000   A       0     0     8  [14] .eh_frame         PROGBITS         000000000000d2a0  0000d2a0       0000000000000004  0000000000000000   A       0     0     4  [15] .init_array       INIT_ARRAY       000000000001dda0  0000dda0       0000000000000008  0000000000000008  WA       0     0     8  [16] .fini_array       FINI_ARRAY       000000000001dda8  0000dda8       0000000000000008  0000000000000008  WA       0     0     8  [17] .jcr              PROGBITS         000000000001ddb0  0000ddb0       0000000000000008  0000000000000000  WA       0     0     8  [18] .dynamic          DYNAMIC          000000000001ddb8  0000ddb8       00000000000001f0  0000000000000010  WA       4     0     8  [19] .got              PROGBITS         000000000001dfa8  0000dfa8       0000000000000040  0000000000000008  WA       0     0     8  [20] .got.plt          PROGBITS         000000000001dfe8  0000dfe8       00000000000002c0  0000000000000008  WA       0     0     8  [21] .data             PROGBITS         000000000001e2a8  0000e2a8       0000000000000008  0000000000000000  WA       0     0     8  [22] .bss              NOBITS           000000000001e2b0  0000e2b0       00000000000009b8  0000000000000000  WA       0     0     8  [23] .gnu_debuglink    PROGBITS         0000000000000000  0000e2b0       0000000000000034  0000000000000000           0     0     1  [24] .shstrtab         STRTAB           0000000000000000  0000e2e4       00000000000000da  0000000000000000           0     0     1Key to Flags:  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),  L (link order), O (extra OS processing required), G (group), T (TLS),  C (compressed), x (unknown), o (OS specific), E (exclude),  p (processor specific)

4)顯示符號(hào)表信息

root@ubuntu:/home/run/code# readelf -s libdrm.so.2.4.0Symbol table '.dynsym' contains 244 entries:   Num:    Value          Size Type    Bind   Vis      Ndx Name     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND     1: 0000000000003720     0 SECTION LOCAL  DEFAULT    9     2: 000000000001ddb0     0 SECTION LOCAL  DEFAULT   17     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND memcpy@GLIBC_2.17 (2)     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND memmove@GLIBC_2.17 (2)     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strlen@GLIBC_2.17 (2)     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __sprintf_chk@GLIBC_2.17 (2)     7: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab     8: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND readlink@GLIBC_2.17 (2)     9: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.17 (2)    10: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND opendir@GLIBC_2.17 (2)    11: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND clock_gettime@GLIBC_2.17 (2)    12: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND stderr@GLIBC_2.17 (2)    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND qsort@GLIBC_2.17 (2)    ...

符號(hào)表保存程序定義或使用的所有全局變量和函數(shù)。

5)顯示所有信息

等同于-h -l -S -s -r -d -V -A -I。

root@ubuntu:/home/run/code# readelf -a libdrm.so.2.4.0ELF Header:  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  Class:                             ELF64  Data:                              2's complement, little endian  Version:                           1 (current)  OS/ABI:                            UNIX - System V  ABI Version:                       0  Type:                              DYN (Shared object file)  Machine:                           AArch74  Version:                           0x1  Entry point address:               0x3cb0  Start of program headers:          64 (bytes into file)  Start of section headers:          58304 (bytes into file)  Flags:                             0x0  Size of this header:               64 (bytes)  Size of program headers:           56 (bytes)  Number of program headers:         6  Size of section headers:           64 (bytes)  Number of section headers:         25  Section header string table index: 24Section Headers:  [Nr] Name              Type             Address           Offset       Size              EntSize          Flags  Link  Info  Align  [ 0]                   NULL             0000000000000000  00000000       0000000000000000  0000000000000000           0     0     0  [ 1] .note.gnu.build-i NOTE             0000000000000190  00000190       0000000000000024  0000000000000000   A       0     0     4  [ 2] .gnu.hash         GNU_HASH         00000000000001b8  000001b8       000000000000056c  0000000000000000   A       3     0     8  [ 3] .dynsym           DYNSYM           0000000000000728  00000728       00000000000016e0  0000000000000018   A       4     3     8  [ 4] .dynstr           STRTAB           0000000000001e08  00001e08       0000000000000de2  0000000000000000   A       0     0     1  [ 5] .gnu.version      VERSYM           0000000000002bea  00002bea

readelf命令可以使用readelf -h獲取其它參數(shù)的用法。

以上是“GNU Binutils中readelf命令怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI