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