brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.2 KiB · bb4e075 Raw
296 lines · plain
1## This is a general test for --symbols option and its aliases.2## There are also other symbols* tests that check specific things.3 4## For testing and behavior documenting purposes we are using ET_REL and ET_DYN inputs.5## Relocatable ELF objects are very different by nature from executables and dynamic libraries.6## They might never have dynamic symbols normally, for example, though we still want7## to document the --dyn-symbols behavior.8## There is no need to check ET_EXEC inputs because for dumpers there is no difference9## between them and ET_DYN inputs in the context of this test.10 11## Case 1: Test how llvm-readobj and llvm-readelf dumps symbols.12## a) Check relocatable objects.13# RUN: yaml2obj %s -DBITS=64 -DTYPE=ET_REL -o %t6414# RUN: llvm-readobj --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM15# RUN: llvm-readelf --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU6416# RUN: llvm-readelf -s --extra-sym-info %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64X17# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_REL -o %t3218# RUN: llvm-readobj --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM19# RUN: llvm-readelf --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU3220# RUN: llvm-readelf -s -X %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32X21## b) Check dynamic objects.22# RUN: yaml2obj %s -DBITS=64 -DTYPE=ET_DYN -o %t64.so23# RUN: llvm-readobj --symbols %t64.so > %t64llvm.txt24# RUN: FileCheck --input-file=%t64llvm.txt %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM25# RUN: llvm-readelf --symbols %t64.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU6426## --extra-sym-info is a no-op for llvm-readobj.27# RUN: llvm-readobj --symbols --extra-sym-info %t64.so | diff %t64llvm.txt -28# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_DYN -o %t32.so29# RUN: llvm-readobj --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM30# RUN: llvm-readelf --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU3231 32#      SYMBOLS-LLVM:Symbols [33# SYMBOLS-LLVM-NEXT:  Symbol {34# SYMBOLS-LLVM-NEXT:    Name:  (0)35# SYMBOLS-LLVM-NEXT:    Value: 0x036# SYMBOLS-LLVM-NEXT:    Size: 037# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)38# SYMBOLS-LLVM-NEXT:    Type: None (0x0)39# SYMBOLS-LLVM-NEXT:    Other: 040# SYMBOLS-LLVM-NEXT:    Section: Undefined (0x0)41# SYMBOLS-LLVM-NEXT:  }42# SYMBOLS-LLVM-NEXT:  Symbol {43# SYMBOLS-LLVM-NEXT:    Name: foo (5)44# SYMBOLS-LLVM-NEXT:    Value: 0x145# SYMBOLS-LLVM-NEXT:    Size: 046# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)47# SYMBOLS-LLVM-NEXT:    Type: None (0x0)48# SYMBOLS-LLVM-NEXT:    Other: 049# SYMBOLS-LLVM-NEXT:    Section: .text (0x1)50# SYMBOLS-LLVM-NEXT:  }51# SYMBOLS-LLVM-NEXT:  Symbol {52# SYMBOLS-LLVM-NEXT:    Name: bar (1)53# SYMBOLS-LLVM-NEXT:    Value: 0x254# SYMBOLS-LLVM-NEXT:    Size: 055# SYMBOLS-LLVM-NEXT:    Binding: Local (0x0)56# SYMBOLS-LLVM-NEXT:    Type: None (0x0)57# SYMBOLS-LLVM-NEXT:    Other: 058# SYMBOLS-LLVM-NEXT:    Section: Undefined (0x0)59# SYMBOLS-LLVM-NEXT:  }60# SYMBOLS-LLVM-NEXT:  Symbol {61# SYMBOLS-LLVM-NEXT:    Name: data (9)62# SYMBOLS-LLVM-NEXT:    Value: 0x363# SYMBOLS-LLVM-NEXT:    Size: 064# SYMBOLS-LLVM-NEXT:    Binding: Global (0x1)65# SYMBOLS-LLVM-NEXT:    Type: None (0x0)66# SYMBOLS-LLVM-NEXT:    Other: 067# SYMBOLS-LLVM-NEXT:    Section: .data (0x2)68# SYMBOLS-LLVM-NEXT:  }69# SYMBOLS-LLVM-NEXT:]70 71#      SYMBOLS-GNU64:Symbol table '.symtab' contains 4 entries:72# SYMBOLS-GNU64-NEXT:   Num:    Value          Size Type    Bind   Vis       Ndx Name73# SYMBOLS-GNU64-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 74# SYMBOLS-GNU64-NEXT:     1: 0000000000000001     0 NOTYPE  LOCAL  DEFAULT     1 foo75# SYMBOLS-GNU64-NEXT:     2: 0000000000000002     0 NOTYPE  LOCAL  DEFAULT   UND bar76# SYMBOLS-GNU64-NEXT:     3: 0000000000000003     0 NOTYPE  GLOBAL DEFAULT     2 data77 78#     SYMBOLS-GNU64X:Symbol table '.symtab' contains 4 entries:79#SYMBOLS-GNU64X-NEXT:   Num:    Value          Size Type    Bind   Vis+Other Ndx(SecName) Name [+ Version Info]80#SYMBOLS-GNU64X-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND          81#SYMBOLS-GNU64X-NEXT:     1: 0000000000000001     0 NOTYPE  LOCAL  DEFAULT     1 (.text)  foo82#SYMBOLS-GNU64X-NEXT:     2: 0000000000000002     0 NOTYPE  LOCAL  DEFAULT   UND          bar83#SYMBOLS-GNU64X-NEXT:     3: 0000000000000003     0 NOTYPE  GLOBAL DEFAULT     2 (.data)  data84 85#      SYMBOLS-GNU32:Symbol table '.symtab' contains 4 entries:86# SYMBOLS-GNU32-NEXT:   Num:    Value  Size Type    Bind   Vis       Ndx Name87# SYMBOLS-GNU32-NEXT:     0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND 88# SYMBOLS-GNU32-NEXT:     1: 00000001     0 NOTYPE  LOCAL  DEFAULT     1 foo89# SYMBOLS-GNU32-NEXT:     2: 00000002     0 NOTYPE  LOCAL  DEFAULT   UND bar90# SYMBOLS-GNU32-NEXT:     3: 00000003     0 NOTYPE  GLOBAL DEFAULT     2 data91 92#     SYMBOLS-GNU32X:Symbol table '.symtab' contains 4 entries:93#SYMBOLS-GNU32X-NEXT:   Num:    Value  Size Type    Bind   Vis+Other Ndx(SecName) Name [+ Version Info]94#SYMBOLS-GNU32X-NEXT:     0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND          95#SYMBOLS-GNU32X-NEXT:     1: 00000001     0 NOTYPE  LOCAL  DEFAULT     1 (.text)  foo96#SYMBOLS-GNU32X-NEXT:     2: 00000002     0 NOTYPE  LOCAL  DEFAULT   UND          bar97#SYMBOLS-GNU32X-NEXT:     3: 00000003     0 NOTYPE  GLOBAL DEFAULT     2 (.data)  data98 99## Case 2: Check flag aliases produce identical output100# RUN: llvm-readobj --symbols %t64 > %t.symbols101# RUN: llvm-readobj --syms %t64 > %t.syms102# RUN: cmp %t.symbols %t.syms103# RUN: llvm-readobj -s %t64 | diff %t.symbols -104# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 | diff %t.symbols -105 106# RUN: llvm-readelf --symbols %t64 > %t.symbols.gnu107# RUN: llvm-readelf --syms %t64 > %t.syms.gnu108# RUN: cmp %t.symbols.gnu %t.syms.gnu109# RUN: llvm-readelf -s %t64 | diff %t.symbols.gnu -110 111## Case 3: Test that both regular and dynamic symbols are dumped when `--symbols` and `--dyn-symbols`112##         are specified together. Note that the order is different for different styles.113# RUN: llvm-readobj --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-LLVM114# RUN: llvm-readelf --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU115 116# BOTH-LLVM: Symbols [117# BOTH-LLVM: DynamicSymbols [118 119# BOTH-GNU: Symbol table '.dynsym'120# BOTH-GNU: Symbol table '.symtab'121 122## Case 4: --symbols implies --dyn-symbols for llvm-readelf.123# RUN: llvm-readobj --symbols %t64 | FileCheck %s --implicit-check-not="DynamicSymbols ["124# RUN: llvm-readelf --symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU125 126## Case 5: Test that `--dyn-symbols` does not trigger `--symbols` implicitly.127# RUN: llvm-readobj --dyn-symbols %t64 | FileCheck %s --implicit-check-not="{{^}}Symbols ["128# RUN: llvm-readelf --dyn-symbols %t64 | FileCheck %s --implicit-check-not="Symbol table '.symtab'"129 130## Case 6: Test that the Num index starts from zero at every new symbol table.131# RUN: llvm-readelf --symbols %t64 %t64 | FileCheck %s --check-prefix=NUM-INDEX132 133# NUM-INDEX:      Symbol table '.symtab' contains 4 entries:134# NUM-INDEX-NEXT:    Num: {{.*}}135# NUM-INDEX-NEXT:      0: {{.*}}136# NUM-INDEX:      Symbol table '.symtab' contains 4 entries:137# NUM-INDEX-NEXT:    Num: {{.*}}138# NUM-INDEX-NEXT:      0: {{.*}}139 140--- !ELF141FileHeader:142  Class: ELFCLASS[[BITS]]143  Data:  ELFDATA2LSB144  Type:  [[TYPE]]145Sections:146  - Name:  .text147    Type: SHT_PROGBITS148  - Name:  .data149    Type: SHT_PROGBITS150Symbols:151  - Name:    foo152    Value:   0x1153    Section: .text154  - Name:    bar155    Value:   0x2156  - Name:    data157    Value:   0x3158    Binding: STB_GLOBAL159    Section: .data160DynamicSymbols:161  - Name:  zed162 163## Check the behavior when we are unable to print symbols due to an error.164 165## Case 1: check we are able to dump symbols even when can't get the string table for the166## SHT_SYMTAB section because of invalid sh_link value.167# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t64.err1168# RUN: llvm-readobj --symbols %t64.err1 2>&1 | \169# RUN:   FileCheck %s -DFILE=%t64.err1 --check-prefix=STRTAB-LINK-ERR-LLVM170# RUN: llvm-readelf --symbols %t64.err1 2>&1 | \171# RUN:   FileCheck %s -DFILE=%t64.err1 --check-prefix=STRTAB-LINK-ERR-GNU172 173# STRTAB-LINK-ERR-LLVM:      Symbols [174# STRTAB-LINK-ERR-LLVM-NEXT: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255175# STRTAB-LINK-ERR-LLVM-NEXT:   Symbol {176# STRTAB-LINK-ERR-LLVM-NEXT:     Name: <?> (0)177# STRTAB-LINK-ERR-LLVM-NEXT:     Value: 0x0178# STRTAB-LINK-ERR-LLVM-NEXT:     Size: 0179# STRTAB-LINK-ERR-LLVM-NEXT:     Binding: Local (0x0)180# STRTAB-LINK-ERR-LLVM-NEXT:     Type: None (0x0)181# STRTAB-LINK-ERR-LLVM-NEXT:     Other: 0182# STRTAB-LINK-ERR-LLVM-NEXT:     Section: Undefined (0x0)183# STRTAB-LINK-ERR-LLVM-NEXT:   }184# STRTAB-LINK-ERR-LLVM-NEXT:   Symbol {185# STRTAB-LINK-ERR-LLVM-NEXT:     Name: <?> (1)186# STRTAB-LINK-ERR-LLVM-NEXT:     Value: 0x1187# STRTAB-LINK-ERR-LLVM-NEXT:     Size: 0188# STRTAB-LINK-ERR-LLVM-NEXT:     Binding: Global (0x1)189# STRTAB-LINK-ERR-LLVM-NEXT:     Type: None (0x0)190# STRTAB-LINK-ERR-LLVM-NEXT:     Other: 0191# STRTAB-LINK-ERR-LLVM-NEXT:     Section: .symtab (0x1)192# STRTAB-LINK-ERR-LLVM-NEXT:   }193# STRTAB-LINK-ERR-LLVM-NEXT: ]194 195# STRTAB-LINK-ERR-GNU:      warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255196# STRTAB-LINK-ERR-GNU:      Symbol table '.symtab' contains 2 entries:197# STRTAB-LINK-ERR-GNU-NEXT:    Num:    Value          Size Type    Bind   Vis       Ndx Name198# STRTAB-LINK-ERR-GNU-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND <?>199# STRTAB-LINK-ERR-GNU-NEXT:      1: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT     1 <?>200 201--- !ELF202FileHeader:203  Class:     ELFCLASS64204  Data:      ELFDATA2LSB205  Type:      ET_REL206  EShStrNdx: [[SHSTRTAB=2]]207Sections:208  - Name:    .symtab209    Type:    SHT_SYMTAB210    Link:    [[LINK=.strtab]]211    EntSize: [[ENTSIZE=0x18]]212## Define the .shstrtab section to reveal its position.213  - Name: .shstrtab214    Type: SHT_STRTAB215Symbols:216  - Name: foo217    Value: 0x1218    Binding: STB_GLOBAL219    Index: 1220 221## Case 2: check we report a warning when we are unable to read symbols222##         from the the SHT_SYMTAB section.223# RUN: yaml2obj --docnum=2 -DENTSIZE=0xFF %s -o %t64.err2224# RUN: llvm-readobj --symbols %t64.err2 2>&1 | \225# RUN:  FileCheck %s -DFILE=%t64.err2 --check-prefix=SYMTAB-ENTSIZE-ERR-LLVM226# RUN: llvm-readelf --symbols %t64.err2 2>&1 | \227# RUN:  FileCheck %s -DFILE=%t64.err2 --check-prefix=SYMTAB-ENTSIZE-ERR-GNU228 229# SYMTAB-ENTSIZE-ERR-LLVM:      Symbols [230# SYMTAB-ENTSIZE-ERR-LLVM-NEXT:   warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has invalid sh_entsize: expected 24, but got 255231# SYMTAB-ENTSIZE-ERR-LLVM:      ]232 233# SYMTAB-ENTSIZE-ERR-GNU:     warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has invalid sh_entsize: expected 24, but got 255234# SYMTAB-ENTSIZE-ERR-GNU-NOT: {{.}}235 236## Case 3: check we report a warning, but continue dumping, when we are unable to read the name of the SHT_SYMTAB section.237##         In this case we set the e_shstrndx field to an invalid index so that the .shstrtab section can't be located.238# RUN: yaml2obj --docnum=2 -DSHSTRTAB=0xff %s -o %t64.err3239# RUN: llvm-readobj --symbols %t64.err3 2>&1 | \240# RUN:  FileCheck %s -DFILE=%t64.err3 --check-prefix=SYMTAB-SHSTRTAB-ERR-LLVM --implicit-check-not=warning:241# RUN: llvm-readelf --symbols %t64.err3 2>&1 | \242# RUN:  FileCheck %s -DFILE=%t64.err3 --check-prefix=SYMTAB-SHSTRTAB-ERR-GNU --implicit-check-not=warning:243 244# SYMTAB-SHSTRTAB-ERR-LLVM:      Symbols [245# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:   Symbol {246# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Name:  (0)247# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Value: 0x0248# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Size: 0249# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Binding: Local (0x0)250# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Type: None (0x0)251# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Other: 0252# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Section: Undefined (0x0)253# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:   }254# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:   Symbol {255# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Name: foo (1)256# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Value: 0x1257# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Size: 0258# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Binding: Global (0x1)259# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Type: None (0x0)260# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Other: 0261# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: warning: '[[FILE]]': section header string table index 255 does not exist262# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:     Section: <?> (0x1)263# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT:   }264# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: ]265 266# SYMTAB-SHSTRTAB-ERR-GNU:      warning: '[[FILE]]': unable to get the name of SHT_SYMTAB section with index 1: section header string table index 255 does not exist267# SYMTAB-SHSTRTAB-ERR-GNU:      Symbol table '<?>' contains 2 entries:268# SYMTAB-SHSTRTAB-ERR-GNU-NEXT:    Num:    Value          Size Type    Bind   Vis       Ndx Name269# SYMTAB-SHSTRTAB-ERR-GNU-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND270# SYMTAB-SHSTRTAB-ERR-GNU-NEXT:      1: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT     1 foo271 272## Test a symbol defined relative to a section with an invalid name.273# RUN: yaml2obj --docnum=3 %s -o %t64.err4274# RUN: llvm-readelf -s %t64.err4 2>&1 | FileCheck /dev/null --implicit-check-not=warning:275# RUN: llvm-readelf -s -X %t64.err4 2>&1 | \276# RUN:   FileCheck %s -DFILE=%t64.err4 --check-prefix=INVALID-SECNAME-GNU --implicit-check-not=warning:277 278# INVALID-SECNAME-GNU:      Num:    Value  Size Type    Bind   Vis+Other Ndx(SecName) Name [+ Version Info]279# INVALID-SECNAME-GNU-NEXT:   0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND          280# INVALID-SECNAME-GNU-NEXT: warning: '[[FILE]]': a section [index 1] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table281# INVALID-SECNAME-GNU-NEXT:   1: 00000000     0 NOTYPE  LOCAL  DEFAULT     1          foo282 283--- !ELF284FileHeader:285  Class:   ELFCLASS32286  Data:    ELFDATA2LSB287  Type:    ET_REL288  Machine: EM_X86_64289Sections:290  - Name:   .invalid291    Type:   SHT_PROGBITS292    ShName: 0xffff293Symbols:294  - Name:    foo295    Section: .invalid296