|
| 1 | +## Check llvm-readelf is able to dump the content of hash sections correctly. |
| 2 | + |
| 3 | +## Check the output when both .hash and .gnu.hash sections are present. |
| 4 | + |
| 5 | +# RUN: yaml2obj --docnum=1 %s -o %t1-32.so |
| 6 | +# RUN: llvm-readelf --hash-symbols %t1-32.so \ |
| 7 | +# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix HASH-32 |
| 8 | + |
| 9 | +# HASH-32: Symbol table of .hash for image: |
| 10 | +# HASH-32-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name |
| 11 | +# HASH-32-NEXT: 1 0: 00000000 0 NOTYPE GLOBAL DEFAULT UND ccc |
| 12 | +# HASH-32-NEXT: 5 0: 00001001 0 NOTYPE WEAK DEFAULT 1 bbb |
| 13 | +# HASH-32-NEXT: 3 0: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd |
| 14 | +# HASH-32-NEXT: 2 0: 00001000 0 NOTYPE GLOBAL DEFAULT 1 aaa |
| 15 | +# HASH-32-NEXT: 4 0: 00000000 0 NOTYPE GLOBAL DEFAULT 2 eee |
| 16 | +# HASH-32-EMPTY: |
| 17 | +# HASH-32: Symbol table of .gnu.hash for image: |
| 18 | +# HASH-32-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name |
| 19 | +# HASH-32-NEXT: 2 1: 00001000 0 NOTYPE GLOBAL DEFAULT 1 aaa |
| 20 | +# HASH-32-NEXT: 3 1: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd |
| 21 | +# HASH-32-NEXT: 4 2: 00000000 0 NOTYPE GLOBAL DEFAULT 2 eee |
| 22 | +# HASH-32-NEXT: 5 2: 00001001 0 NOTYPE WEAK DEFAULT 1 bbb |
| 23 | +# HASH-32-NOT: {{.}} |
| 24 | + |
| 25 | +--- !ELF |
| 26 | +FileHeader: |
| 27 | + Class: ELFCLASS32 |
| 28 | + Data: ELFDATA2LSB |
| 29 | + Type: ET_DYN |
| 30 | + Machine: EM_386 |
| 31 | +Sections: |
| 32 | +## The contents of .hash and .gnu.hash were generated by a linker. |
| 33 | + - Name: .hash |
| 34 | + Type: SHT_HASH |
| 35 | + Flags: [ SHF_ALLOC ] |
| 36 | + Link: .dynsym |
| 37 | + Content: '0300000006000000010000000000000000000000000000000500000004000000020000000000000003000000' |
| 38 | + - Name: .gnu.hash |
| 39 | + Type: SHT_GNU_HASH |
| 40 | + Flags: [ SHF_ALLOC ] |
| 41 | + Link: .dynsym |
| 42 | + Content: 0300000002000000010000000500000048991200000000000200000004000000685C880B9169880BF46D880BCB60880B |
| 43 | + - Name: .dynamic |
| 44 | + Type: SHT_DYNAMIC |
| 45 | + Flags: [ SHF_ALLOC ] |
| 46 | + Link: .dynstr |
| 47 | + Entries: |
| 48 | +## PT_LOAD's p_vaddr is 0x0. PT_LOAD's p_offset = 0x1bc. DT_HASH value is 0x0. |
| 49 | +## llvm-readelf will read .hash content from p_offset + (p_vaddr - DT_HASH value) = 0x1bc. |
| 50 | +## This matches the file offset of the .hash section. |
| 51 | + - Tag: DT_HASH |
| 52 | + Value: 0x0000000000000000 |
| 53 | + - Tag: DT_GNU_HASH |
| 54 | +## PT_LOAD's p_vaddr is 0x0. PT_LOAD's p_offset = 0x1bc. DT_GNU_HASH value is 0x2c (size of .hash = 0x2c). |
| 55 | +## llvm-readelf will read .gnu.hash content from p_offset + (p_vaddr - DT_GNU_HASH value) = 0x1e8. |
| 56 | +## This matches the file offset of the .gnu.hash section. |
| 57 | + Value: 0x000000000000002C |
| 58 | + - Tag: DT_NULL |
| 59 | + Value: 0x0000000000000000 |
| 60 | +DynamicSymbols: |
| 61 | + - Name: ccc |
| 62 | + Binding: STB_GLOBAL |
| 63 | + - Name: aaa |
| 64 | + Section: .hash |
| 65 | + Binding: STB_GLOBAL |
| 66 | + Value: 0x0000000000001000 |
| 67 | + - Name: ddd |
| 68 | + Index: SHN_ABS |
| 69 | + Binding: STB_GLOBAL |
| 70 | + Value: 0x0000000000000001 |
| 71 | + - Name: eee |
| 72 | + Section: .gnu.hash |
| 73 | + Binding: STB_GLOBAL |
| 74 | + - Name: bbb |
| 75 | + Section: .hash |
| 76 | + Binding: STB_WEAK |
| 77 | + Value: 0x0000000000001001 |
| 78 | +ProgramHeaders: |
| 79 | + - Type: PT_LOAD |
| 80 | + Flags: [ PF_R, PF_X ] |
| 81 | + Sections: |
| 82 | + - Section: .hash |
| 83 | + - Section: .gnu.hash |
| 84 | + - Section: .dynamic |
| 85 | + |
| 86 | +## Check the output when only .hash section is present. |
| 87 | + |
| 88 | +# RUN: yaml2obj --docnum=2 %s -o %t2-32.so |
| 89 | +# RUN: llvm-readelf --hash-symbols %t2-32.so \ |
| 90 | +# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-HASH-32 |
| 91 | + |
| 92 | +# ONLY-HASH-32: Symbol table of .hash for image: |
| 93 | +# ONLY-HASH-32-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name |
| 94 | +# ONLY-HASH-32-NEXT: 1 0: 00000000 0 NOTYPE GLOBAL DEFAULT UND ccc |
| 95 | +# ONLY-HASH-32-NEXT: 5 0: 00001001 0 NOTYPE WEAK DEFAULT 1 bbb |
| 96 | +# ONLY-HASH-32-NEXT: 3 0: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd |
| 97 | +# ONLY-HASH-32-NEXT: 2 0: 00001000 0 NOTYPE GLOBAL DEFAULT 1 aaa |
| 98 | +# ONLY-HASH-32-NEXT: 4 0: 00000000 0 NOTYPE GLOBAL DEFAULT 2 eee |
| 99 | +# ONLY-HASH-32-NOT: {{.}} |
| 100 | + |
| 101 | +--- !ELF |
| 102 | +FileHeader: |
| 103 | + Class: ELFCLASS32 |
| 104 | + Data: ELFDATA2LSB |
| 105 | + Type: ET_DYN |
| 106 | + Machine: EM_386 |
| 107 | +Sections: |
| 108 | +## The contents of .hash was generated by a linker. |
| 109 | + - Name: .hash |
| 110 | + Type: SHT_HASH |
| 111 | + Flags: [ SHF_ALLOC ] |
| 112 | + Link: .dynsym |
| 113 | + Content: '0300000006000000010000000000000000000000000000000500000004000000020000000000000003000000' |
| 114 | + - Name: .dynamic |
| 115 | + Type: SHT_DYNAMIC |
| 116 | + Flags: [ SHF_ALLOC ] |
| 117 | + Link: .dynstr |
| 118 | + Entries: |
| 119 | + - Tag: DT_HASH |
| 120 | + Value: 0x0000000000000000 |
| 121 | + - Tag: DT_NULL |
| 122 | + Value: 0x0000000000000000 |
| 123 | +DynamicSymbols: |
| 124 | + - Name: ccc |
| 125 | + Binding: STB_GLOBAL |
| 126 | + - Name: aaa |
| 127 | + Section: .hash |
| 128 | + Binding: STB_GLOBAL |
| 129 | + Value: 0x0000000000001000 |
| 130 | + - Name: ddd |
| 131 | + Index: SHN_ABS |
| 132 | + Binding: STB_GLOBAL |
| 133 | + Value: 0x0000000000000001 |
| 134 | + - Name: eee |
| 135 | + Section: .dynamic |
| 136 | + Binding: STB_GLOBAL |
| 137 | + - Name: bbb |
| 138 | + Section: .hash |
| 139 | + Binding: STB_WEAK |
| 140 | + Value: 0x0000000000001001 |
| 141 | +ProgramHeaders: |
| 142 | + - Type: PT_LOAD |
| 143 | + Flags: [ PF_R, PF_X ] |
| 144 | + Sections: |
| 145 | + - Section: .hash |
| 146 | + - Section: .dynamic |
| 147 | + |
| 148 | +## Check the output when only .gnu.hash section is present. |
| 149 | + |
| 150 | +# RUN: yaml2obj --docnum=3 %s -o %t3-32.so |
| 151 | +# RUN: llvm-readelf --hash-symbols %t3-32.so \ |
| 152 | +# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-GNUHASH-32 |
| 153 | + |
| 154 | +# ONLY-GNUHASH-32: Symbol table of .gnu.hash for image: |
| 155 | +# ONLY-GNUHASH-32-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name |
| 156 | +# ONLY-GNUHASH-32-NEXT: 2 1: 00001000 0 NOTYPE GLOBAL DEFAULT 2 aaa |
| 157 | +# ONLY-GNUHASH-32-NEXT: 3 1: 00000001 0 NOTYPE GLOBAL DEFAULT ABS ddd |
| 158 | +# ONLY-GNUHASH-32-NEXT: 4 2: 00000000 0 NOTYPE GLOBAL DEFAULT 1 eee |
| 159 | +# ONLY-GNUHASH-32-NEXT: 5 2: 00001001 0 NOTYPE WEAK DEFAULT 2 bbb |
| 160 | +# ONLY-GNUHASH-32-NOT: {{.}} |
| 161 | + |
| 162 | +--- !ELF |
| 163 | +FileHeader: |
| 164 | + Class: ELFCLASS32 |
| 165 | + Data: ELFDATA2LSB |
| 166 | + Type: ET_DYN |
| 167 | + Machine: EM_386 |
| 168 | +Sections: |
| 169 | +## The contents of .gnu.hash was generated by a linker. |
| 170 | + - Name: .gnu.hash |
| 171 | + Type: SHT_GNU_HASH |
| 172 | + Flags: [ SHF_ALLOC ] |
| 173 | + Link: .dynsym |
| 174 | + Content: 0300000002000000010000000500000048991200000000000200000004000000685C880B9169880BF46D880BCB60880B |
| 175 | + - Name: .dynamic |
| 176 | + Type: SHT_DYNAMIC |
| 177 | + Flags: [ SHF_ALLOC ] |
| 178 | + Link: .dynstr |
| 179 | + Entries: |
| 180 | + - Tag: DT_GNU_HASH |
| 181 | + Value: 0x0000000000000000 |
| 182 | + - Tag: DT_NULL |
| 183 | + Value: 0x0000000000000000 |
| 184 | +DynamicSymbols: |
| 185 | + - Name: ccc |
| 186 | + Binding: STB_GLOBAL |
| 187 | + - Name: aaa |
| 188 | + Section: .dynamic |
| 189 | + Binding: STB_GLOBAL |
| 190 | + Value: 0x0000000000001000 |
| 191 | + - Name: ddd |
| 192 | + Index: SHN_ABS |
| 193 | + Binding: STB_GLOBAL |
| 194 | + Value: 0x0000000000000001 |
| 195 | + - Name: eee |
| 196 | + Section: .gnu.hash |
| 197 | + Binding: STB_GLOBAL |
| 198 | + - Name: bbb |
| 199 | + Section: .dynamic |
| 200 | + Binding: STB_WEAK |
| 201 | + Value: 0x0000000000001001 |
| 202 | +ProgramHeaders: |
| 203 | + - Type: PT_LOAD |
| 204 | + Flags: [ PF_R, PF_X ] |
| 205 | + Sections: |
| 206 | + - Section: .gnu.hash |
| 207 | + - Section: .dynamic |
| 208 | + |
| 209 | +## Show that if there are no hash sections, we do not print anything. |
| 210 | +# RUN: yaml2obj --docnum=4 %s -o %t4.so |
| 211 | +# RUN: llvm-readelf --hash-symbols %t4.so \ |
| 212 | +# RUN: | FileCheck %s --check-prefix NO-HASH --allow-empty |
| 213 | + |
| 214 | +# NO-HASH-NOT: {{.}} |
| 215 | + |
| 216 | +## Sanity check that we can still find the dynamic symbols (i.e. the above test |
| 217 | +## doesn't pass due to a mistake in the dynamic section). |
| 218 | +# RUN: llvm-readelf --dyn-symbols %t4.so | FileCheck %s --check-prefix DYNSYMS |
| 219 | + |
| 220 | +# DYNSYMS: Symbol table '.dynsym' contains 2 entries: |
| 221 | + |
| 222 | +--- !ELF |
| 223 | +FileHeader: |
| 224 | + Class: ELFCLASS64 |
| 225 | + Data: ELFDATA2LSB |
| 226 | + Type: ET_DYN |
| 227 | + Machine: EM_X86_64 |
| 228 | +Sections: |
| 229 | + - Name: .dynstr |
| 230 | + Type: SHT_STRTAB |
| 231 | + Flags: [ SHF_ALLOC ] |
| 232 | + AddressAlign: 0x100 |
| 233 | + EntSize: 0x1 |
| 234 | + - Name: .dynsym |
| 235 | + Type: SHT_DYNSYM |
| 236 | + Flags: [ SHF_ALLOC ] |
| 237 | + Link: .dynstr |
| 238 | + Address: 0x100 |
| 239 | + AddressAlign: 0x100 |
| 240 | + EntSize: 0x18 |
| 241 | + - Name: .dynamic |
| 242 | + Type: SHT_DYNAMIC |
| 243 | + Flags: [ SHF_ALLOC ] |
| 244 | + Address: 0x0000000000001000 |
| 245 | + Link: .dynstr |
| 246 | + AddressAlign: 0x0000000000001000 |
| 247 | + EntSize: 0x0000000000000010 |
| 248 | + Entries: |
| 249 | + - Tag: DT_STRTAB |
| 250 | + Value: 0x0000000000000000 |
| 251 | + - Tag: DT_STRSZ |
| 252 | + Value: 0x0000000000000009 |
| 253 | + - Tag: DT_SYMTAB |
| 254 | + Value: 0x0000000000000100 |
| 255 | + - Tag: DT_SYMENT |
| 256 | + Value: 0x0000000000000018 |
| 257 | + - Tag: DT_NULL |
| 258 | + Value: 0x0000000000000000 |
| 259 | + - Name: .text.foo |
| 260 | + Type: SHT_PROGBITS |
| 261 | + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ] |
| 262 | + Size: 0x40 |
| 263 | + Address: 0x2000 |
| 264 | + AddressAlign: 0x2000 |
| 265 | +DynamicSymbols: |
| 266 | + - Name: _Z3fooi |
| 267 | + Binding: STB_GLOBAL |
| 268 | +ProgramHeaders: |
| 269 | + - Type: PT_LOAD |
| 270 | + Flags: [ PF_R, PF_X ] |
| 271 | + VAddr: 0x0 |
| 272 | + PAddr: 0x0 |
| 273 | + Sections: |
| 274 | + - Section: .dynsym |
| 275 | + - Section: .dynstr |
| 276 | + - Section: .dynamic |
| 277 | + - Section: .text.foo |
| 278 | + - Type: PT_DYNAMIC |
| 279 | + Flags: [ PF_R ] |
| 280 | + VAddr: 0x1000 |
| 281 | + PAddr: 0x1000 |
| 282 | + Sections: |
| 283 | + - Section: .dynamic |
0 commit comments