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 want 7## to document the --dyn-symbols behavior. 8## There is no need to check ET_EXEC inputs because for dumpers there is no difference 9## 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 %t64 14# RUN: llvm-readobj --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM 15# RUN: llvm-readelf --symbols %t64 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64 16# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_REL -o %t32 17# RUN: llvm-readobj --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM 18# RUN: llvm-readelf --symbols %t32 | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32 19## b) Check dynamic objects. 20# RUN: yaml2obj %s -DBITS=64 -DTYPE=ET_DYN -o %t64.so 21# RUN: llvm-readobj --symbols %t64.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM 22# RUN: llvm-readelf --symbols %t64.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU64 23# RUN: yaml2obj %s -DBITS=32 -DTYPE=ET_DYN -o %t32.so 24# RUN: llvm-readobj --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-LLVM 25# RUN: llvm-readelf --symbols %t32.so | FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SYMBOLS-GNU32 26 27# SYMBOLS-LLVM:Symbols [ 28# SYMBOLS-LLVM-NEXT: Symbol { 29# SYMBOLS-LLVM-NEXT: Name: (0) 30# SYMBOLS-LLVM-NEXT: Value: 0x0 31# SYMBOLS-LLVM-NEXT: Size: 0 32# SYMBOLS-LLVM-NEXT: Binding: Local (0x0) 33# SYMBOLS-LLVM-NEXT: Type: None (0x0) 34# SYMBOLS-LLVM-NEXT: Other: 0 35# SYMBOLS-LLVM-NEXT: Section: Undefined (0x0) 36# SYMBOLS-LLVM-NEXT: } 37# SYMBOLS-LLVM-NEXT: Symbol { 38# SYMBOLS-LLVM-NEXT: Name: foo (5) 39# SYMBOLS-LLVM-NEXT: Value: 0x1 40# SYMBOLS-LLVM-NEXT: Size: 0 41# SYMBOLS-LLVM-NEXT: Binding: Local (0x0) 42# SYMBOLS-LLVM-NEXT: Type: None (0x0) 43# SYMBOLS-LLVM-NEXT: Other: 0 44# SYMBOLS-LLVM-NEXT: Section: Undefined (0x0) 45# SYMBOLS-LLVM-NEXT: } 46# SYMBOLS-LLVM-NEXT: Symbol { 47# SYMBOLS-LLVM-NEXT: Name: bar (1) 48# SYMBOLS-LLVM-NEXT: Value: 0x2 49# SYMBOLS-LLVM-NEXT: Size: 0 50# SYMBOLS-LLVM-NEXT: Binding: Local (0x0) 51# SYMBOLS-LLVM-NEXT: Type: None (0x0) 52# SYMBOLS-LLVM-NEXT: Other: 0 53# SYMBOLS-LLVM-NEXT: Section: Undefined (0x0) 54# SYMBOLS-LLVM-NEXT: } 55# SYMBOLS-LLVM-NEXT:] 56 57# SYMBOLS-GNU64:Symbol table '.symtab' contains 3 entries: 58# SYMBOLS-GNU64-NEXT: Num: Value Size Type Bind Vis Ndx Name 59# SYMBOLS-GNU64-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 60# SYMBOLS-GNU64-NEXT: 1: 0000000000000001 0 NOTYPE LOCAL DEFAULT UND foo 61# SYMBOLS-GNU64-NEXT: 2: 0000000000000002 0 NOTYPE LOCAL DEFAULT UND bar 62 63# SYMBOLS-GNU32:Symbol table '.symtab' contains 3 entries: 64# SYMBOLS-GNU32-NEXT: Num: Value Size Type Bind Vis Ndx Name 65# SYMBOLS-GNU32-NEXT: 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 66# SYMBOLS-GNU32-NEXT: 1: 00000001 0 NOTYPE LOCAL DEFAULT UND foo 67# SYMBOLS-GNU32-NEXT: 2: 00000002 0 NOTYPE LOCAL DEFAULT UND bar 68 69## Case 2: Check flag aliases produce identical output 70# RUN: llvm-readobj --symbols %t64 > %t.symbols 71# RUN: llvm-readobj --syms %t64 > %t.syms 72# RUN: cmp %t.symbols %t.syms 73# RUN: llvm-readobj -t %t64 > %t.t 74# RUN: cmp %t.symbols %t.t 75# RUN: llvm-readelf -s --elf-output-style=LLVM %t64 > %t.lowers 76# RUN: cmp %t.symbols %t.lowers 77 78# RUN: llvm-readelf --symbols %t64 > %t.symbols.gnu 79# RUN: llvm-readelf --syms %t64 > %t.syms.gnu 80# RUN: cmp %t.symbols.gnu %t.syms.gnu 81 82## -s is an llvm-readobj option to dump sections. 83# RUN: llvm-readobj -s --elf-output-style=GNU %t64 | FileCheck %s --implicit-check-not="Symbol table" 84 85## Case 3: Test that both regular and dynamic symbols are dumped when `--symbols` and `--dyn-symbols` 86## are specified together. Note that the order is different for different styles. 87# RUN: llvm-readobj --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-LLVM 88# RUN: llvm-readelf --symbols --dyn-symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU 89 90# BOTH-LLVM: Symbols [ 91# BOTH-LLVM: DynamicSymbols [ 92 93# BOTH-GNU: Symbol table '.dynsym' 94# BOTH-GNU: Symbol table '.symtab' 95 96## Case 4: --symbols implies --dyn-symbols for llvm-readelf. 97# RUN: llvm-readobj --symbols %t64 | FileCheck %s --implicit-check-not="DynamicSymbols [" 98# RUN: llvm-readelf --symbols %t64 | FileCheck %s --check-prefix=BOTH-GNU 99 100## Case 5: Test that `--dyn-symbols` does not trigger `--symbols` implicitly. 101# RUN: llvm-readobj --dyn-symbols %t64 | FileCheck %s --implicit-check-not="{{^}}Symbols [" 102# RUN: llvm-readelf --dyn-symbols %t64 | FileCheck %s --implicit-check-not="Symbol table '.symtab'" 103 104## Case 6: Test that the Num index starts from zero at every new symbol table. 105# RUN: llvm-readelf --symbols %t64 %t64 | FileCheck %s --check-prefix=NUM-INDEX 106 107# NUM-INDEX: Symbol table '.symtab' contains 3 entries: 108# NUM-INDEX-NEXT: Num: {{.*}} 109# NUM-INDEX-NEXT: 0: {{.*}} 110# NUM-INDEX: Symbol table '.symtab' contains 3 entries: 111# NUM-INDEX-NEXT: Num: {{.*}} 112# NUM-INDEX-NEXT: 0: {{.*}} 113 114--- !ELF 115FileHeader: 116 Class: ELFCLASS[[BITS]] 117 Data: ELFDATA2LSB 118 Type: [[TYPE]] 119Symbols: 120 - Name: foo 121 Value: 0x1 122 - Name: bar 123 Value: 0x2 124DynamicSymbols: 125 - Name: zed 126 127## Check the behavior when we are unable to print symbols due to an error. 128 129## Case 1: check we are able to dump symbols even when can't get the string table for the 130## SHT_SYMTAB section because of invalid sh_link value. 131# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t64.err1 132# RUN: llvm-readobj --symbols %t64.err1 2>&1 | \ 133# RUN: FileCheck %s -DFILE=%t64.err1 --check-prefix=STRTAB-LINK-ERR-LLVM 134# RUN: llvm-readelf --symbols %t64.err1 2>&1 | \ 135# RUN: FileCheck %s -DFILE=%t64.err1 --check-prefix=STRTAB-LINK-ERR-GNU 136 137# STRTAB-LINK-ERR-LLVM: Symbols [ 138# STRTAB-LINK-ERR-LLVM-NEXT: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255 139# STRTAB-LINK-ERR-LLVM-NEXT: Symbol { 140# STRTAB-LINK-ERR-LLVM-NEXT: Name: <?> (0) 141# STRTAB-LINK-ERR-LLVM-NEXT: Value: 0x0 142# STRTAB-LINK-ERR-LLVM-NEXT: Size: 0 143# STRTAB-LINK-ERR-LLVM-NEXT: Binding: Local (0x0) 144# STRTAB-LINK-ERR-LLVM-NEXT: Type: None (0x0) 145# STRTAB-LINK-ERR-LLVM-NEXT: Other: 0 146# STRTAB-LINK-ERR-LLVM-NEXT: Section: Undefined (0x0) 147# STRTAB-LINK-ERR-LLVM-NEXT: } 148# STRTAB-LINK-ERR-LLVM-NEXT: Symbol { 149# STRTAB-LINK-ERR-LLVM-NEXT: Name: <?> (1) 150# STRTAB-LINK-ERR-LLVM-NEXT: Value: 0x1 151# STRTAB-LINK-ERR-LLVM-NEXT: Size: 0 152# STRTAB-LINK-ERR-LLVM-NEXT: Binding: Global (0x1) 153# STRTAB-LINK-ERR-LLVM-NEXT: Type: None (0x0) 154# STRTAB-LINK-ERR-LLVM-NEXT: Other: 0 155# STRTAB-LINK-ERR-LLVM-NEXT: Section: .symtab (0x1) 156# STRTAB-LINK-ERR-LLVM-NEXT: } 157# STRTAB-LINK-ERR-LLVM-NEXT: ] 158 159# STRTAB-LINK-ERR-GNU: warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255 160# STRTAB-LINK-ERR-GNU: Symbol table '.symtab' contains 2 entries: 161# STRTAB-LINK-ERR-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name 162# STRTAB-LINK-ERR-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND <?> 163# STRTAB-LINK-ERR-GNU-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT 1 <?> 164 165--- !ELF 166FileHeader: 167 Class: ELFCLASS64 168 Data: ELFDATA2LSB 169 Type: ET_REL 170 EShStrNdx: [[SHSTRTAB=2]] 171Sections: 172 - Name: .symtab 173 Type: SHT_SYMTAB 174 Link: [[LINK=.strtab]] 175 EntSize: [[ENTSIZE=0x18]] 176## Define the .shstrtab section to reveal its position. 177 - Name: .shstrtab 178 Type: SHT_STRTAB 179Symbols: 180 - Name: foo 181 Value: 0x1 182 Binding: STB_GLOBAL 183 Index: 1 184 185## Case 2: check we report a warning when we are unable to read symbols 186## from the the SHT_SYMTAB section. 187# RUN: yaml2obj --docnum=2 -DENTSIZE=0xFF %s -o %t64.err2 188# RUN: llvm-readobj --symbols %t64.err2 2>&1 | \ 189# RUN: FileCheck %s -DFILE=%t64.err2 --check-prefix=SYMTAB-ENTSIZE-ERR-LLVM 190# RUN: llvm-readelf --symbols %t64.err2 2>&1 | \ 191# RUN: FileCheck %s -DFILE=%t64.err2 --check-prefix=SYMTAB-ENTSIZE-ERR-GNU 192 193# SYMTAB-ENTSIZE-ERR-LLVM: Symbols [ 194# SYMTAB-ENTSIZE-ERR-LLVM-NEXT: warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has an invalid sh_entsize: 255 195# SYMTAB-ENTSIZE-ERR-LLVM: ] 196 197# SYMTAB-ENTSIZE-ERR-GNU: warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 1] has an invalid sh_entsize: 255 198# SYMTAB-ENTSIZE-ERR-GNU-NOT: {{.}} 199 200## Case 3: check we report a warning, but continue dumping, when we are unable to read the name of the SHT_SYMTAB section. 201## In this case we set the e_shstrndx field to an invalid index so that the .shstrtab section can't be located. 202# RUN: yaml2obj --docnum=2 -DSHSTRTAB=0xff %s -o %t64.err3 203# RUN: llvm-readobj --symbols %t64.err3 2>&1 | \ 204# RUN: FileCheck %s -DFILE=%t64.err3 --check-prefix=SYMTAB-SHSTRTAB-ERR-LLVM --implicit-check-not=warning: 205# RUN: llvm-readelf --symbols %t64.err3 2>&1 | \ 206# RUN: FileCheck %s -DFILE=%t64.err3 --check-prefix=SYMTAB-SHSTRTAB-ERR-GNU --implicit-check-not=warning: 207 208# SYMTAB-SHSTRTAB-ERR-LLVM: Symbols [ 209# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Symbol { 210# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Name: (0) 211# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Value: 0x0 212# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Size: 0 213# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Binding: Local (0x0) 214# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Type: None (0x0) 215# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Other: 0 216# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Section: Undefined (0x0) 217# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: } 218# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Symbol { 219# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Name: foo (1) 220# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Value: 0x1 221# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Size: 0 222# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Binding: Global (0x1) 223# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Type: None (0x0) 224# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Other: 0 225# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: warning: '[[FILE]]': section header string table index 255 does not exist 226# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: Section: <?> (0x1) 227# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: } 228# SYMTAB-SHSTRTAB-ERR-LLVM-NEXT: ] 229 230# 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 exist 231# SYMTAB-SHSTRTAB-ERR-GNU: Symbol table '<?>' contains 2 entries: 232# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name 233# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 234# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT 1 foo 235