brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.9 KiB · 97caf60 Raw
314 lines · plain
1## Show that llvm-readobj prints symbol shndxes correctly, for valid indexes,2## invalid indexes (i.e. section indexes that don't correspond to a real3## section), reserved values and processor/os-specific index values, for both GNU4## and LLVM styles.5 6# RUN: yaml2obj --docnum=1 %s -o %t17# RUN: llvm-readobj --symbols %t1 | FileCheck %s --check-prefix=LLVM18# RUN: llvm-readelf --symbols %t1 | FileCheck %s --check-prefix=GNU19 10# LLVM1: Name:    undef11# LLVM1: Section:12# LLVM1-SAME:     Undefined (0x0)13# LLVM1: Name:    normal14# LLVM1: Section:15# LLVM1-SAME:     .text (0x1)16# LLVM1: Name:    common17# LLVM1: Section:18# LLVM1-SAME:     Common (0xFFF2)19# LLVM1: Name:    absolute20# LLVM1: Section:21# LLVM1-SAME:     Absolute (0xFFF1)22# LLVM1: Name:    proc23# LLVM1: Section:24# LLVM1-SAME:     Processor Specific (0xFF01)25# LLVM1: Name:    os26# LLVM1: Section:27# LLVM1-SAME:     Operating System Specific (0xFF21)28# LLVM1: Name:    reserved29# LLVM1: Section:30# LLVM1-SAME:     Reserved (0xFFFE)31# LLVM1: Name:    xindex32# LLVM1: Section:33# LLVM1:          .text (0x1)34 35# GNU1:      Symbol table '.symtab' contains 9 entries:36# GNU1-NEXT:   Num: {{.*}} Ndx Name37# GNU1-NEXT:     0: {{.*}} UND38# GNU1-NEXT:     1: {{.*}} UND undef39# GNU1-NEXT:     2: {{.*}}   1 normal40# GNU1-NEXT:     3: {{.*}} COM common41# GNU1-NEXT:     4: {{.*}} ABS absolute42# GNU1-NEXT:     5: {{.*}} PRC[0xff01] proc43# GNU1-NEXT:     6: {{.*}} OS[0xff21] os44# GNU1-NEXT:     7: {{.*}} RSV[0xfffe] reserved45# GNU1-NEXT:     8: {{.*}}   1 xindex46 47--- !ELF48FileHeader:49  Class: ELFCLASS3250  Data:  ELFDATA2LSB51  Type:  ET_REL52Sections:53  - Name: .text54    Type: SHT_PROGBITS55  - Name: .symtab_shndx56    Type: SHT_SYMTAB_SHNDX57    Link: .symtab58    Entries: [ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]59Symbols:60  - Name:    [[NAME=undef]]61    Binding: STB_GLOBAL62    Type:    [[TYPE=STT_NOTYPE]]63  - Name:    [[NAME=normal]]64    Section: .text65    Binding: STB_GLOBAL66    Type:    [[TYPE=STT_NOTYPE]]67  - Name:    [[NAME=common]]68    Index:   SHN_COMMON69    Binding: STB_GLOBAL70    Type:    [[TYPE=STT_NOTYPE]]71  - Name:    [[NAME=absolute]]72    Index:   SHN_ABS73    Binding: STB_GLOBAL74    Type:    [[TYPE=STT_NOTYPE]]75  - Name:    [[NAME=proc]]76    Index:   0xff0177    Binding: STB_GLOBAL78    Type:    [[TYPE=STT_NOTYPE]]79  - Name:    [[NAME=os]]80    Index:   0xff2181    Binding: STB_GLOBAL82    Type:    [[TYPE=STT_NOTYPE]]83  - Name:    [[NAME=reserved]]84    Index:   0xfffe85    Binding: STB_GLOBAL86    Type:    [[TYPE=STT_NOTYPE]]87  - Name:    [[NAME=xindex]]88    Index:   SHN_XINDEX89    Binding: STB_GLOBAL90    Type:    [[TYPE=STT_NOTYPE]]91 92## Check the behavior for section symbols.93# RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION %s -o %t1-sec94# RUN: llvm-readobj --symbols %t1-sec | FileCheck %s --check-prefix=LLVM195# RUN: llvm-readelf --symbols %t1-sec | FileCheck %s --check-prefix=GNU196 97## Check the behavior for unnamed section symbols.98# RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION -DNAME="''" %s -o %t1-sec-unnamed99# RUN: llvm-readobj --symbols %t1-sec-unnamed 2>&1 | \100# RUN:   FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=LLVM1-SEC-SYMS101# RUN: llvm-readelf --symbols %t1-sec-unnamed 2>&1 | \102# RUN:   FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=GNU1-SEC-SYMS103 104# LLVM1-SEC-SYMS:      Symbols [105# LLVM1-SEC-SYMS-NEXT:   Symbol {106# LLVM1-SEC-SYMS-NEXT:     Name:  (0)107# LLVM1-SEC-SYMS:          Section: Undefined (0x0)108# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)109# LLVM1-SEC-SYMS-NEXT:   Symbol {110# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)111# LLVM1-SEC-SYMS:          Section: Undefined (0x0)112# LLVM1-SEC-SYMS:        Symbol {113# LLVM1-SEC-SYMS-NEXT:     Name: .text (0)114# LLVM1-SEC-SYMS:          Section: .text (0x1)115# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)116# LLVM1-SEC-SYMS-NEXT:   Symbol {117# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)118# LLVM1-SEC-SYMS:          Section: Common (0xFFF2)119# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)120# LLVM1-SEC-SYMS-NEXT:   Symbol {121# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)122# LLVM1-SEC-SYMS:          Section: Absolute (0xFFF1)123# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)124# LLVM1-SEC-SYMS-NEXT:   Symbol {125# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)126# LLVM1-SEC-SYMS:          Section: Processor Specific (0xFF01)127# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)128# LLVM1-SEC-SYMS-NEXT:   Symbol {129# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)130# LLVM1-SEC-SYMS:          Section: Operating System Specific (0xFF21)131# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)132# LLVM1-SEC-SYMS-NEXT:   Symbol {133# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)134# LLVM1-SEC-SYMS:          Section: Reserved (0xFFFE)135# LLVM1-SEC-SYMS:        Symbol {136# LLVM1-SEC-SYMS-NEXT:     Name: .text (0)137# LLVM1-SEC-SYMS:          Section: .text (0x1)138 139# GNU1-SEC-SYMS:      Num: {{.*}} Ndx Name140# GNU1-SEC-SYMS-NEXT:   0: {{.*}} UND {{$}}141# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)142# GNU1-SEC-SYMS-NEXT:   1: {{.*}} UND <?>143# GNU1-SEC-SYMS-NEXT:   2: {{.*}}   1 .text144# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)145# GNU1-SEC-SYMS-NEXT:   3: {{.*}} COM <?>146# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)147# GNU1-SEC-SYMS-NEXT:   4: {{.*}} ABS <?>148# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)149# GNU1-SEC-SYMS-NEXT:   5: {{.*}} PRC[0xff01] <?>150# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)151# GNU1-SEC-SYMS-NEXT:   6: {{.*}} OS[0xff21] <?>152# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)153# GNU1-SEC-SYMS-NEXT:   7: {{.*}} RSV[0xfffe] <?>154# GNU1-SEC-SYMS-NEXT:   8: {{.*}}   1 .text155 156## In this case, the index does not correspond to a real section. Check that GNU157## style just prints the section index as normal and LLVM style prints a warning158## (but only once for each warning).159# RUN: yaml2obj --docnum=2 %s -o %t2160# RUN: llvm-readobj --symbols %t2 2> %t2.llvm.err | FileCheck %s --check-prefix=LLVM2161# RUN: FileCheck %s --input-file=%t2.llvm.err --check-prefix=BAD-SHNDX --implicit-check-not=warning162# RUN: llvm-readelf --symbols %t2 2> %t2.gnu.err | FileCheck %s --check-prefix=GNU2163# RUN: FileCheck %s --input-file=%t2.gnu.err --allow-empty --implicit-check-not={{.}}164 165# LLVM2: Name: bad166# LLVM2: Section:167# LLVM2-SAME:     <?> (0x42)168# LLVM2: Name: bad2169# LLVM2: Section:170# LLVM2-SAME:     <?> (0x42)171# LLVM2: Name: bad3172# LLVM2: Section:173# LLVM2-SAME:     <?> (0x43)174# LLVM2: Name: invalid_shndx175# LLVM2: Section:176# LLVM2-SAME:     <?> (0x9)177# LLVM2: Name: invalid_shndx2178# LLVM2: Section:179# LLVM2-SAME:     <?> (0x9)180# LLVM2: Name: invalid_shndx3181# LLVM2: Section:182# LLVM2-SAME:     <?> (0xA)183 184# GNU2:      Symbol table '.symtab' contains 7 entries:185# GNU2-NEXT:   Num: {{.*}} Ndx Name186# GNU2-NEXT:     0: {{.*}} UND187# GNU2-NEXT:     1: {{.*}}  66 bad188# GNU2-NEXT:     2: {{.*}}  66 bad2189# GNU2-NEXT:     3: {{.*}}  67 bad3190# GNU2-NEXT:     4: {{.*}}   9 invalid_shndx191# GNU2-NEXT:     5: {{.*}}   9 invalid_shndx2192# GNU2-NEXT:     6: {{.*}}  10 invalid_shndx3193 194# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 66195# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 67196# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 9197# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 10198 199--- !ELF200FileHeader:201  Class: ELFCLASS32202  Data:  ELFDATA2LSB203  Type:  ET_REL204Sections:205  - Name: .symtab_shndx206    Type: SHT_SYMTAB_SHNDX207    Link: .symtab208    Entries: [ 0, 0, 0, 0, 9, 9, 10 ]209Symbols:210  - Name:    bad211    Index:   0x42212  - Name:    bad2213    Index:   0x42214  - Name:    bad3215    Index:   0x43216  - Name:    invalid_shndx217    Index:   SHN_XINDEX218  - Name:    invalid_shndx2219    Index:   SHN_XINDEX220  - Name:    invalid_shndx3221    Index:   SHN_XINDEX222 223## In this case, the symtab shndx section is missing, so symbols with section224## indexes of SHN_XINDEX print as Reserved symbols.225# RUN: yaml2obj --docnum=3 %s -o %t3226# RUN: llvm-readobj --symbols %t3 2> %t3.llvm.err | FileCheck %s --check-prefix=LLVM3227# RUN: FileCheck %s --input-file=%t3.llvm.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning228# RUN: llvm-readelf --symbols %t3 2> %t3.gnu.err | FileCheck %s --check-prefix=GNU3229# RUN: FileCheck %s --input-file=%t3.gnu.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning230 231# LLVM3: Name: no_shndx232# LLVM3: Section:233# LLVM3-SAME:     Reserved (0xFFFF)234# LLVM3: Name: no_shndx2235# LLVM3: Section:236# LLVM3-SAME:     Reserved (0xFFFF)237 238# GNU3:      Symbol table '.symtab' contains 3 entries:239# GNU3-NEXT:   Num: {{.*}} Ndx Name240# GNU3-NEXT:     0: {{.*}} UND241# GNU3-NEXT:     1: {{.*}} RSV[0xffff] no_shndx242# GNU3-NEXT:     2: {{.*}} RSV[0xffff] no_shndx2243 244# NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (1), but unable to locate the extended symbol index table245# NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (2), but unable to locate the extended symbol index table246 247--- !ELF248FileHeader:249  Class: ELFCLASS32250  Data:  ELFDATA2LSB251  Type:  ET_REL252Symbols:253  - Name:  no_shndx254    Index: SHN_XINDEX255  - Name:  no_shndx2256    Index: SHN_XINDEX257 258## Check we can dump symbols even when the number of entries in the259## SHT_SYMTAB_SHNDX section doesn't match the number of symbols in the symbol table.260 261# RUN: yaml2obj --docnum=4 %s -o %t4262# RUN: llvm-readelf --symbols %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=SHNDX-ERR-GNU263# RUN: llvm-readobj --symbols %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=SHNDX-ERR-LLVM264 265#       SHNDX-ERR-GNU: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2266# SHNDX-ERR-GNU-EMPTY:267#  SHNDX-ERR-GNU-NEXT: Symbol table '.symtab' contains 2 entries:268#  SHNDX-ERR-GNU-NEXT:    Num:    Value          Size Type    Bind   Vis       Ndx Name269#  SHNDX-ERR-GNU-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND270#  SHNDX-ERR-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table271#  SHNDX-ERR-GNU-NEXT:      1: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   RSV[0xffff]272# SHNDX-ERR-GNU-EMPTY:273#   SHNDX-ERR-GNU-NOT:{{.}}274 275# SHNDX-ERR-LLVM: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2276# SHNDX-ERR-LLVM:      Format: elf64-unknown277# SHNDX-ERR-LLVM-NEXT: Arch: unknown278# SHNDX-ERR-LLVM-NEXT: AddressSize: 64bit279# SHNDX-ERR-LLVM-NEXT: LoadName: <Not found>280# SHNDX-ERR-LLVM-NEXT: Symbols [281# SHNDX-ERR-LLVM-NEXT:   Symbol {282# SHNDX-ERR-LLVM-NEXT:     Name:  (0)283# SHNDX-ERR-LLVM-NEXT:     Value: 0x0284# SHNDX-ERR-LLVM-NEXT:     Size: 0285# SHNDX-ERR-LLVM-NEXT:     Binding: Local (0x0)286# SHNDX-ERR-LLVM-NEXT:     Type: None (0x0)287# SHNDX-ERR-LLVM-NEXT:     Other: 0288# SHNDX-ERR-LLVM-NEXT:     Section: Undefined (0x0)289# SHNDX-ERR-LLVM-NEXT:   }290# SHNDX-ERR-LLVM-NEXT:   Symbol {291# SHNDX-ERR-LLVM-NEXT:     Name:  (0)292# SHNDX-ERR-LLVM-NEXT:     Value: 0x0293# SHNDX-ERR-LLVM-NEXT:     Size: 0294# SHNDX-ERR-LLVM-NEXT:     Binding: Local (0x0)295# SHNDX-ERR-LLVM-NEXT:     Type: None (0x0)296# SHNDX-ERR-LLVM-NEXT:     Other: 0297# SHNDX-ERR-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table298# SHNDX-ERR-LLVM-NEXT:     Section: Reserved (0xFFFF)299# SHNDX-ERR-LLVM-NEXT:   }300# SHNDX-ERR-LLVM-NEXT: ]301 302--- !ELF303FileHeader:304  Class: ELFCLASS64305  Data:  ELFDATA2LSB306  Type:  ET_REL307Sections:308  - Name:    .symtab_shndx309    Type:    SHT_SYMTAB_SHNDX310    Entries: [ 0, 1, 2 ]311    Link:    .symtab312Symbols:313  - Index: SHN_XINDEX314