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