readelf.test 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. elf=$FILES/elf/ndk-elf-note
  5. # toybox uses Linux kernel architecture names, so rewrite binutils with sed.
  6. NOSPACE=1 testing "-h" "readelf -hW $elf-full | sed s/AArch64/arm64/g" \
  7. "ELF Header:
  8. Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  9. Class: ELF64
  10. Data: 2's complement, little endian
  11. Version: 1 (current)
  12. OS/ABI: UNIX - System V
  13. ABI Version: 0
  14. Type: DYN (Shared object file)
  15. Machine: arm64
  16. Version: 0x1
  17. Entry point address: 0x660
  18. Start of program headers: 64 (bytes into file)
  19. Start of section headers: 7776 (bytes into file)
  20. Flags: 0x0
  21. Size of this header: 64 (bytes)
  22. Size of program headers: 56 (bytes)
  23. Number of program headers: 9
  24. Size of section headers: 64 (bytes)
  25. Number of section headers: 32
  26. Section header string table index: 29
  27. " "" ""
  28. # We format the key to flags differently and don't include obsolete ones.
  29. NOSPACE=1 testing "-S" "readelf -SW $elf-full | head -36" \
  30. "There are 32 section headers, starting at offset 0x1e60:
  31. Section Headers:
  32. [Nr] Name Type Address Off Size ES Flg Lk Inf Al
  33. [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
  34. [ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
  35. [ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
  36. [ 3] .note.gnu.build-id NOTE 00000000000002e8 0002e8 000024 00 A 0 0 4
  37. [ 4] .hash HASH 0000000000000310 000310 000048 04 A 5 0 8
  38. [ 5] .dynsym DYNSYM 0000000000000358 000358 000138 18 A 6 3 8
  39. [ 6] .dynstr STRTAB 0000000000000490 000490 000097 00 A 0 0 1
  40. [ 7] .gnu.version VERSYM 0000000000000528 000528 00001a 02 A 5 0 2
  41. [ 8] .gnu.version_r VERNEED 0000000000000548 000548 000020 00 A 6 1 8
  42. [ 9] .rela.dyn RELA 0000000000000568 000568 000060 18 A 5 0 8
  43. [10] .rela.plt RELA 00000000000005c8 0005c8 000048 18 AI 5 19 8
  44. [11] .plt PROGBITS 0000000000000610 000610 000050 10 AX 0 0 16
  45. [12] .text PROGBITS 0000000000000660 000660 00008c 00 AX 0 0 4
  46. [13] .eh_frame_hdr PROGBITS 00000000000006ec 0006ec 000014 00 A 0 0 4
  47. [14] .eh_frame PROGBITS 0000000000000700 000700 000030 00 A 0 0 8
  48. [15] .preinit_array PREINIT_ARRAY 0000000000010d68 000d68 000010 08 WA 0 0 8
  49. [16] .init_array INIT_ARRAY 0000000000010d78 000d78 000010 08 WA 0 0 8
  50. [17] .fini_array FINI_ARRAY 0000000000010d88 000d88 000010 08 WA 0 0 8
  51. [18] .dynamic DYNAMIC 0000000000010d98 000d98 000210 10 WA 6 0 8
  52. [19] .got PROGBITS 0000000000010fa8 000fa8 000058 08 WA 0 0 8
  53. [20] .bss NOBITS 0000000000011000 001000 000008 00 WA 0 0 8
  54. [21] .comment PROGBITS 0000000000000000 001000 000107 01 MS 0 0 1
  55. [22] .debug_pubnames PROGBITS 0000000000000000 001107 00001b 00 0 0 1
  56. [23] .debug_info PROGBITS 0000000000000000 001122 00004b 00 0 0 1
  57. [24] .debug_abbrev PROGBITS 0000000000000000 00116d 000037 00 0 0 1
  58. [25] .debug_line PROGBITS 0000000000000000 0011a4 00003f 00 0 0 1
  59. [26] .debug_str PROGBITS 0000000000000000 0011e3 000138 01 MS 0 0 1
  60. [27] .debug_macinfo PROGBITS 0000000000000000 00131b 000001 00 0 0 1
  61. [28] .debug_pubtypes PROGBITS 0000000000000000 00131c 00001a 00 0 0 1
  62. [29] .shstrtab STRTAB 0000000000000000 001d0c 000151 00 0 0 1
  63. [30] .symtab SYMTAB 0000000000000000 001338 0007e0 18 31 68 8
  64. [31] .strtab STRTAB 0000000000000000 001b18 0001f4 00 0 0 1
  65. " "" ""
  66. testing "-l" "readelf -lW $elf-short" "
  67. Elf file type is DYN (Shared object file)
  68. Entry point 0x1001
  69. There are 10 program headers, starting at offset 52
  70. Program Headers:
  71. Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
  72. PHDR 0x000034 0x00000034 0x00000034 0x00140 0x00140 R 0x4
  73. INTERP 0x000174 0x00000174 0x00000174 0x00013 0x00013 R 0x1
  74. [Requesting program interpreter: /system/bin/linker]
  75. LOAD 0x000000 0x00000000 0x00000000 0x00404 0x00404 R 0x1000
  76. LOAD 0x001000 0x00001000 0x00001000 0x00140 0x00140 R E 0x1000
  77. LOAD 0x002000 0x00002000 0x00002000 0x00144 0x00144 RW 0x1000
  78. DYNAMIC 0x002018 0x00002018 0x00002018 0x00100 0x00100 RW 0x4
  79. GNU_RELRO 0x002000 0x00002000 0x00002000 0x00144 0x01000 R 0x1
  80. GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
  81. NOTE 0x000188 0x00000188 0x00000188 0x00038 0x00038 R 0x4
  82. EXIDX 0x0001c0 0x000001c0 0x000001c0 0x00030 0x00030 R 0x4
  83. Section to Segment mapping:
  84. Segment Sections...
  85. 00
  86. 01 .interp
  87. 02 .interp .note.android.ident .note.gnu.build-id .ARM.exidx .dynsym .gnu.version .gnu.version_r .gnu.hash .dynstr .rel.dyn .relr.dyn .rel.plt
  88. 03 .text .plt
  89. 04 .preinit_array .init_array .fini_array .dynamic .got .got.plt
  90. 05 .dynamic
  91. 06 .preinit_array .init_array .fini_array .dynamic .got .got.plt
  92. 07
  93. 08 .note.android.ident .note.gnu.build-id
  94. 09 .ARM.exidx
  95. " "" ""
  96. # binutils doesn't line up the column headers for 64-bit ELF files.
  97. # TODO: binutils readelf lies about trailing NULL entires binutils ld produces
  98. NOSPACE=1 toyonly testing "-d" "readelf -dW $elf-full" "
  99. Dynamic section at offset 0xd98 contains 33 entries:
  100. Tag Type Name/Value
  101. 0x0000000000000001 (NEEDED) Shared library: [libc.so]
  102. 0x0000000000000001 (NEEDED) Shared library: [libm.so]
  103. 0x0000000000000001 (NEEDED) Shared library: [libdl.so]
  104. 0x0000000000000020 (PREINIT_ARRAY) 0x10d68
  105. 0x0000000000000021 (PREINIT_ARRAYSZ) 0x10
  106. 0x0000000000000019 (INIT_ARRAY) 0x10d78
  107. 0x000000000000001b (INIT_ARRAYSZ) 16 (bytes)
  108. 0x000000000000001a (FINI_ARRAY) 0x10d88
  109. 0x000000000000001c (FINI_ARRAYSZ) 16 (bytes)
  110. 0x0000000000000004 (HASH) 0x310
  111. 0x0000000000000005 (STRTAB) 0x490
  112. 0x0000000000000006 (SYMTAB) 0x358
  113. 0x000000000000000a (STRSZ) 151 (bytes)
  114. 0x000000000000000b (SYMENT) 24 (bytes)
  115. 0x0000000000000015 (DEBUG) 0x0
  116. 0x0000000000000003 (PLTGOT) 0x10fa8
  117. 0x0000000000000002 (PLTRELSZ) 72 (bytes)
  118. 0x0000000000000014 (PLTREL) RELA
  119. 0x0000000000000017 (JMPREL) 0x5c8
  120. 0x0000000000000007 (RELA) 0x568
  121. 0x0000000000000008 (RELASZ) 96 (bytes)
  122. 0x0000000000000009 (RELAENT) 24 (bytes)
  123. 0x000000000000001e (FLAGS) BIND_NOW
  124. 0x000000006ffffffb (FLAGS_1) Flags: NOW
  125. 0x000000006ffffffe (VERNEED) 0x548
  126. 0x000000006fffffff (VERNEEDNUM) 1
  127. 0x000000006ffffff0 (VERSYM) 0x528
  128. 0x000000006ffffff9 (RELACOUNT) 4
  129. 0x0000000000000000 (NULL) 0x0
  130. 0x0000000000000000 (NULL) 0x0
  131. 0x0000000000000000 (NULL) 0x0
  132. 0x0000000000000000 (NULL) 0x0
  133. 0x0000000000000000 (NULL) 0x0
  134. " "" ""
  135. # toybox does a better job of decoding Android's ELF notes than binutils.
  136. toyonly testing "-n" "readelf -nW $elf-short" "
  137. Displaying notes found in: .note.android.ident
  138. Owner Data size Description
  139. Android 0x00000004 NT_VERSION API level 28
  140. Displaying notes found in: .note.gnu.build-id
  141. Owner Data size Description
  142. GNU 0x00000010 NT_GNU_BUILD_ID da6a5f4ca8da163b9339326e626d8a3c
  143. " "" ""
  144. testing "-p" "readelf -p22 $elf-short" "
  145. String dump of section '.shstrtab':
  146. [ 1] .preinit_array
  147. [ 10] .init_array
  148. [ 1c] .fini_array
  149. [ 28] .ARM.exidx
  150. [ 33] .text
  151. [ 39] .got
  152. [ 3e] .note.android.ident
  153. [ 52] .got.plt
  154. [ 5b] .rel.plt
  155. [ 64] .ARM.attributes
  156. [ 74] .dynstr
  157. [ 7c] .gnu.version_r
  158. [ 8b] .interp
  159. [ 93] .relr.dyn
  160. [ 9d] .rel.dyn
  161. [ a6] .gnu.version
  162. [ b3] .dynsym
  163. [ bb] .gnu.hash
  164. [ c5] .note.gnu.build-id
  165. [ d8] .dynamic
  166. [ e1] .shstrtab
  167. [ eb] .gnu_debugdata
  168. " "" ""
  169. testing "-x" "readelf -x22 $elf-short" "
  170. Hex dump of section '.shstrtab':
  171. 0x00000000 002e7072 65696e69 745f6172 72617900 ..preinit_array.
  172. 0x00000010 2e696e69 745f6172 72617900 2e66696e .init_array..fin
  173. 0x00000020 695f6172 72617900 2e41524d 2e657869 i_array..ARM.exi
  174. 0x00000030 6478002e 74657874 002e676f 74002e6e dx..text..got..n
  175. 0x00000040 6f74652e 616e6472 6f69642e 6964656e ote.android.iden
  176. 0x00000050 74002e67 6f742e70 6c74002e 72656c2e t..got.plt..rel.
  177. 0x00000060 706c7400 2e41524d 2e617474 72696275 plt..ARM.attribu
  178. 0x00000070 74657300 2e64796e 73747200 2e676e75 tes..dynstr..gnu
  179. 0x00000080 2e766572 73696f6e 5f72002e 696e7465 .version_r..inte
  180. 0x00000090 7270002e 72656c72 2e64796e 002e7265 rp..relr.dyn..re
  181. 0x000000a0 6c2e6479 6e002e67 6e752e76 65727369 l.dyn..gnu.versi
  182. 0x000000b0 6f6e002e 64796e73 796d002e 676e752e on..dynsym..gnu.
  183. 0x000000c0 68617368 002e6e6f 74652e67 6e752e62 hash..note.gnu.b
  184. 0x000000d0 75696c64 2d696400 2e64796e 616d6963 uild-id..dynamic
  185. 0x000000e0 002e7368 73747274 6162002e 676e755f ..shstrtab..gnu_
  186. 0x000000f0 64656275 67646174 61000000 000000 debugdata......
  187. " "" ""
  188. # TODO: remove the sed when we handle symbol versions
  189. testing "-s" "readelf -s $elf-short | sed s/@.*//" "
  190. Symbol table '.dynsym' contains 11 entries:
  191. Num: Value Size Type Bind Vis Ndx Name
  192. 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
  193. 1: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_init
  194. 2: 00000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail
  195. 3: 00000000 0 OBJECT GLOBAL DEFAULT UND __stack_chk_guard
  196. 4: 00000000 0 FUNC GLOBAL DEFAULT UND memset
  197. 5: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr
  198. 6: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr4
  199. 7: 000010d8 12 FUNC GLOBAL DEFAULT 13 __aeabi_memclr8
  200. 8: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset
  201. 9: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset4
  202. 10: 000010c8 16 FUNC GLOBAL DEFAULT 13 __aeabi_memset8
  203. " "" ""