344 lines · plain
1## In this file we have tests for the SHT_SYMTAB_SHNDX section2## and the DT_SYMTAB_SHNDX dynamic tag.3 4## Check that different SHT_SYMTAB_SHNDX sections can be used with different symbol tables.5## In this test we check that we print different section indexes for regular and dynamic6## symbol tables that are linked to different SHT_SYMTAB_SHNDX sections.7 8# RUN: yaml2obj --docnum=1 %s -o %t19# RUN: llvm-readelf --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=GNU10# RUN: llvm-readelf --symbols --dyn-syms --extra-sym-info %t1 2>&1 | FileCheck %s --check-prefix=GNUX11# RUN: llvm-readobj --symbols --dyn-syms %t1 2>&1 | FileCheck %s --check-prefix=LLVM12 13# GNU: Symbol table '.dynsym' contains 3 entries:14# GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name15# GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND16# GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 dynsym117# GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym218# GNU: Symbol table '.symtab' contains 3 entries:19# GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name20# GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND21# GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 sym122# GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 sym223 24# GNUX: Symbol table '.dynsym' contains 3 entries:25# GNUX-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]26# GNUX-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND27# GNUX-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 (.section3) dynsym128# GNUX-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 (.section2) dynsym229# GNUX: Symbol table '.symtab' contains 3 entries:30# GNUX-NEXT: Num: Value Size Type Bind Vis+Other Ndx(SecName) Name [+ Version Info]31# GNUX-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND32# GNUX-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 (.section2) sym133# GNUX-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 (.section1) sym234 35# LLVM: Symbols [36# LLVM-NEXT: Symbol {37# LLVM-NEXT: Name: (0)38# LLVM: Section: Undefined (0x0)39# LLVM-NEXT: }40# LLVM-NEXT: Symbol {41# LLVM-NEXT: Name: sym1 (6)42# LLVM: Section: .section2 (0x2)43# LLVM-NEXT: }44# LLVM-NEXT: Symbol {45# LLVM-NEXT: Name: sym2 (1)46# LLVM: Section: .section1 (0x1)47# LLVM-NEXT: }48# LLVM-NEXT: ]49# LLVM: DynamicSymbols [50# LLVM-NEXT: Symbol {51# LLVM-NEXT: Name: (0)52# LLVM: Section: Undefined (0x0)53# LLVM-NEXT: }54# LLVM-NEXT: Symbol {55# LLVM-NEXT: Name: dynsym1 (9)56# LLVM: Section: .section3 (0x3)57# LLVM-NEXT: }58# LLVM-NEXT: Symbol {59# LLVM-NEXT: Name: dynsym2 (1)60# LLVM: Section: .section2 (0x2)61# LLVM-NEXT: }62# LLVM-NEXT: ]63 64--- !ELF65FileHeader:66 Class: ELFCLASS3267 Data: ELFDATA2LSB68 Type: ET_REL69Sections:70 - Name: .section171 Type: SHT_PROGBITS72 - Name: .section273 Type: SHT_PROGBITS74 - Name: .section375 Type: SHT_PROGBITS76 - Name: .dynamic77 Type: SHT_DYNAMIC78 Flags: [ SHF_ALLOC ]79 Address: 0x100080 Offset: 0x100081 Entries:82 - Tag: [[TAGNAME=DT_SYMTAB_SHNDX]]83 Value: [[SYMTABSHNDX=0x2100]] ## Address of .bar section.84 - Tag: DT_NULL85 Value: 086## By naming the SHT_SYMTAB_SHNDX sections to .foo and .bar we verify that we87## don't use their names to locate them.88 - Name: .foo89 Type: SHT_SYMTAB_SHNDX90 Flags: [ SHF_ALLOC ]91 Link: [[SHNDXLINK=.symtab]]92 Entries: [ 0, 2, 1 ]93 Offset: 0x200094 Address: 0x200095 - Name: .bar96 Type: SHT_SYMTAB_SHNDX97 Flags: [ SHF_ALLOC ]98 Link: .dynsym99 Entries: [ 0, 3, 2 ]100 Offset: 0x2100101 Address: 0x2100102Symbols:103 - Name: sym1104 Index: SHN_XINDEX105 - Name: sym2106 Index: SHN_XINDEX107DynamicSymbols:108 - Name: dynsym1109 Index: SHN_XINDEX110 - Name: dynsym2111 Index: SHN_XINDEX112ProgramHeaders:113 - Type: PT_LOAD114 VAddr: 0x1000115 FirstSec: .dynamic116 LastSec: .bar117 - Type: PT_DYNAMIC118 VAddr: 0x1000119 FirstSec: .dynamic120 LastSec: .dynamic121 122## Check that we locate the SHT_SYMTAB_SHNDX section using the DT_SYMTAB_SHNDX123## dynamic tag when dumping dynamic symbols. In this case we make the value of124## DT_SYMTAB_SHNDX point to the SHT_SYMTAB_SHNDX section that is125## linked with the static symbol table and check that we use it.126 127# RUN: yaml2obj --docnum=1 -DSYMTABSHNDX=0x2000 %s -o %t2128# RUN: llvm-readelf --dyn-syms %t2 2>&1 | FileCheck %s --check-prefix=DYNTAG-GNU129# RUN: llvm-readobj --dyn-syms %t2 2>&1 | FileCheck %s --check-prefix=DYNTAG-LLVM130 131# DYNTAG-GNU: Symbol table '.dynsym' contains 3 entries:132# DYNTAG-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name133# DYNTAG-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND134# DYNTAG-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym1135# DYNTAG-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 1 dynsym2136 137# DYNTAG-LLVM: Name: dynsym1 (9)138# DYNTAG-LLVM: Section: .section2 (0x2)139# DYNTAG-LLVM-NEXT: }140# DYNTAG-LLVM-NEXT: Symbol {141# DYNTAG-LLVM-NEXT: Name: dynsym2 (1)142# DYNTAG-LLVM: Section: .section1 (0x1)143# DYNTAG-LLVM-NEXT: }144# DYNTAG-LLVM-NEXT: ]145 146## Check that we report a warning when we dump a dynamic symbol table that147## contains symbols with extended indices, but we don't have a DT_SYMTAB_SHNDX tag to locate148## the corresponding extended indexes table.149 150# RUN: yaml2obj --docnum=1 -DTAGNAME=0x0 -DSYMTABSHNDX=0x0 %s -o %t3151# RUN: llvm-readelf --symbols --dyn-syms %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=NOTAG-GNU152# RUN: llvm-readobj --symbols --dyn-syms %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=NOTAG-LLVM153 154# NOTAG-GNU: Symbol table '.dynsym' contains 3 entries:155# NOTAG-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name156# NOTAG-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND157# NOTAG-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table158# NOTAG-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym1159# NOTAG-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table160# NOTAG-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym2161 162# NOTAG-LLVM: Symbol {163# NOTAG-LLVM: Name: dynsym1 (9)164# NOTAG-LLVM-NEXT: Value: 0x0165# NOTAG-LLVM-NEXT: Size: 0166# NOTAG-LLVM-NEXT: Binding: Local (0x0)167# NOTAG-LLVM-NEXT: Type: None (0x0)168# NOTAG-LLVM-NEXT: Other: 0169# NOTAG-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table170# NOTAG-LLVM-NEXT: Section: Reserved (0xFFFF)171# NOTAG-LLVM-NEXT: }172# NOTAG-LLVM-NEXT: Symbol {173# NOTAG-LLVM-NEXT: Name: dynsym2 (1)174# NOTAG-LLVM-NEXT: Value: 0x0175# NOTAG-LLVM-NEXT: Size: 0176# NOTAG-LLVM-NEXT: Binding: Local (0x0)177# NOTAG-LLVM-NEXT: Type: None (0x0)178# NOTAG-LLVM-NEXT: Other: 0179# NOTAG-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table180# NOTAG-LLVM-NEXT: Section: Reserved (0xFFFF)181# NOTAG-LLVM-NEXT: }182 183## In this case we have a SHT_SYMTAB_SHNDX section with a sh_link field that has a184## value that is larger than the number of sections. Check we report a warning.185 186# RUN: yaml2obj --docnum=1 -DSHNDXLINK=0xFF %s -o %t4187# RUN: llvm-readelf --symbols --dyn-syms %t4 2>&1 | \188# RUN: FileCheck %s -DFILE=%t4 --check-prefixes=BROKENLINK,BROKENLINK-GNU --implicit-check-not=warning:189# RUN: llvm-readobj --symbols --dyn-syms %t4 2>&1 | \190# RUN: FileCheck %s -DFILE=%t4 --check-prefixes=BROKENLINK,BROKENLINK-LLVM --implicit-check-not=warning:191 192# BROKENLINK: warning: '[[FILE]]': unable to get the associated symbol table for SHT_SYMTAB_SHNDX section with index 5: sh_link (255) is greater than or equal to the total number of sections (12)193 194# BROKENLINK-GNU: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table195# BROKENLINK-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] sym1196# BROKENLINK-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table197# BROKENLINK-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] sym2198 199# BROKENLINK-LLVM: Symbol {200# BROKENLINK-LLVM: Name: sym1 (6)201# BROKENLINK-LLVM: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table202# BROKENLINK-LLVM-NEXT: Section: Reserved (0xFFFF)203# BROKENLINK-LLVM-NEXT: }204# BROKENLINK-LLVM-NEXT: Symbol {205# BROKENLINK-LLVM-NEXT: Name: sym2 (1)206# BROKENLINK-LLVM: warning: '[[FILE]]': found an extended symbol index (2), but unable to locate the extended symbol index table207# BROKENLINK-LLVM-NEXT: Section: Reserved (0xFFFF)208# BROKENLINK-LLVM-NEXT: }209 210## Check we report a warning when multiple SHT_SYMTAB_SHNDX sections are linked to a symbol table.211## In this case, 2 sections are linked to the dynamic symbol table. Check it doesn't affect212## anything, because the SHT_SYMTAB_SHNDX section specified by the DT_SYMTAB_SHNDX tag is still used.213 214# RUN: yaml2obj --docnum=1 -DSHNDXLINK=.dynsym %s -o %t.multiple215# RUN: llvm-readelf --symbols --dyn-syms %t.multiple 2>&1 | \216# RUN: FileCheck %s -DFILE=%t.multiple --check-prefix=MULTIPLE-GNU217# RUN: llvm-readobj --symbols --dyn-syms %t.multiple 2>&1 | \218# RUN: FileCheck %s -DFILE=%t.multiple --check-prefix=MULTIPLE-LLVM219 220# MULTIPLE-GNU: warning: '[[FILE]]': multiple SHT_SYMTAB_SHNDX sections are linked to SHT_SYMTAB_SHNDX section with index 6221# MULTIPLE-GNU: Symbol table '.dynsym' contains 3 entries:222# MULTIPLE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name223# MULTIPLE-GNU-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND224# MULTIPLE-GNU-NEXT: 1: 00000000 0 NOTYPE LOCAL DEFAULT 3 dynsym1225# MULTIPLE-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT 2 dynsym2226 227# MULTIPLE-LLVM: Symbol {228# MULTIPLE-LLVM: Name: dynsym1 (9)229# MULTIPLE-LLVM-NEXT: Value: 0x0230# MULTIPLE-LLVM-NEXT: Size: 0231# MULTIPLE-LLVM-NEXT: Binding: Local (0x0)232# MULTIPLE-LLVM-NEXT: Type: None (0x0)233# MULTIPLE-LLVM-NEXT: Other: 0234# MULTIPLE-LLVM-NEXT: Section: .section3 (0x3)235# MULTIPLE-LLVM-NEXT: }236# MULTIPLE-LLVM-NEXT: Symbol {237# MULTIPLE-LLVM-NEXT: Name: dynsym2 (1)238# MULTIPLE-LLVM-NEXT: Value: 0x0239# MULTIPLE-LLVM-NEXT: Size: 0240# MULTIPLE-LLVM-NEXT: Binding: Local (0x0)241# MULTIPLE-LLVM-NEXT: Type: None (0x0)242# MULTIPLE-LLVM-NEXT: Other: 0243# MULTIPLE-LLVM-NEXT: Section: .section2 (0x2)244# MULTIPLE-LLVM-NEXT: }245 246## In this case we have a SHT_SYMTAB_SHNDX section placed right before247## the end of the file. This table is broken: it contains fewer entries than248## the number of dynamic symbols.249## Check we report a warning when trying to read an extended symbol index past250## the end of the file.251 252# RUN: yaml2obj --docnum=2 %s -o %t.pastend253# RUN: llvm-readelf --dyn-syms %t.pastend 2>&1 | \254# RUN: FileCheck %s -DFILE=%t.pastend --check-prefix=PASTEND-GNU --implicit-check-not=warning:255# RUN: llvm-readobj --dyn-syms %t.pastend 2>&1 | \256# RUN: FileCheck %s -DFILE=%t.pastend --check-prefix=PASTEND-LLVM --implicit-check-not=warning:257 258# PASTEND-GNU: 1: 00000000 0 NOTYPE LOCAL DEFAULT 1 dynsym1259# PASTEND-GNU-NEXT: warning: '[[FILE]]': unable to read an extended symbol table at index 2: can't read past the end of the file260# PASTEND-GNU-NEXT: 2: 00000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff] dynsym2261 262# PASTEND-LLVM: Symbol {263# PASTEND-LLVM: Name: dynsym2 (1)264# PASTEND-LLVM-NEXT: Value: 0x0265# PASTEND-LLVM-NEXT: Size: 0266# PASTEND-LLVM-NEXT: Binding: Local (0x0)267# PASTEND-LLVM-NEXT: Type: None (0x0)268# PASTEND-LLVM-NEXT: Other: 0269# PASTEND-LLVM-NEXT: warning: '[[FILE]]': unable to read an extended symbol table at index 2: can't read past the end of the file270# PASTEND-LLVM-NEXT: Section: Reserved (0xFFFF)271# PASTEND-LLVM-NEXT: }272 273--- !ELF274FileHeader:275 Class: ELFCLASS32276 Data: ELFDATA2LSB277 Type: ET_REL278Sections:279 - Name: .section1280 Type: SHT_PROGBITS281 - Name: .section2282 Type: SHT_PROGBITS283 - Name: .dynamic284 Type: SHT_DYNAMIC285 Flags: [ SHF_ALLOC ]286 Address: 0x1000287 Offset: 0x1000288 Entries:289 - Tag: DT_SYMTAB290 Value: 0x1500291 - Tag: DT_HASH292 Value: 0x1600293 - Tag: DT_STRTAB294 Value: 0x1700295 - Tag: DT_STRSZ296 Value: 17 ## ".dynsym1.dynsym2."297 - Tag: DT_SYMTAB_SHNDX298 Value: 0x2000299 - Tag: DT_NULL300 Value: 0301 - Name: .dynsym302 Type: SHT_DYNSYM303 Flags: [ SHF_ALLOC ]304 Offset: 0x1500305 Address: 0x1500306## We need the .hash table to infer the number307## of dynamic symbols.308 - Name: .hash309 Type: SHT_HASH310 Flags: [ SHF_ALLOC ]311 Offset: 0x1600312 Address: 0x1600313 Bucket: [ 1 ]314 Chain: [ 1, 2, 3 ]315 - Name: .dynstr316 Type: SHT_STRTAB317 Flags: [ SHF_ALLOC ]318 Offset: 0x1700319 Address: 0x1700320 - Name: .strtab321 Type: SHT_STRTAB322 - Name: .symtab_shndx323 Type: SHT_SYMTAB_SHNDX324 Flags: [ SHF_ALLOC ]325 Entries: [ 0, 1 ]326 Offset: 0x2000327 Address: 0x2000328 - Type: SectionHeaderTable329 NoHeaders: true330DynamicSymbols:331 - Name: dynsym1332 Index: SHN_XINDEX333 - Name: dynsym2334 Index: SHN_XINDEX335ProgramHeaders:336 - Type: PT_LOAD337 VAddr: 0x1000338 FirstSec: .dynamic339 LastSec: .symtab_shndx340 - Type: PT_DYNAMIC341 VAddr: 0x1000342 FirstSec: .dynamic343 LastSec: .dynamic344