194 lines · plain
1## This is a test for --dynamic/-D option.2 3## Test llvm-nm dumping ELF file with valid .dynsym section.4# RUN: yaml2obj --docnum=1 %s -o %t1.o5# RUN: llvm-nm --dynamic %t1.o | \6# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM7# RUN: llvm-nm -D %t1.o | \8# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM9 10# DYNSYM: U globalsym11# DYNSYM-NEXT: U localsym112# DYNSYM-NEXT:0000000000000000 n localsym213# DYNSYM-EMPTY:14 15--- !ELF16FileHeader:17 Class: ELFCLASS6418 Data: ELFDATA2LSB19 Type: ET_DYN20 Machine: EM_X86_6421Sections:22 - Name: section23 Type: SHT_PROGBITS24DynamicSymbols:25 - Name: localsym126 Type: STT_OBJECT27 - Name: localsym228 Section: section29 - Name: globalsym30 Type: STT_OBJECT31 Binding: STB_GLOBAL32 33## Test llvm-nm dumping ELF file without a .dynsym section.34# RUN: yaml2obj --docnum=2 %s -o %t2.o35# RUN: llvm-nm --dynamic %t2.o 2>&1 | \36# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t2.o --check-prefix NO-SYMS37 38# NO-SYMS:[[FILE]]: no symbols39# NO-SYMS-EMPTY:40 41--- !ELF42FileHeader:43 Class: ELFCLASS6444 Data: ELFDATA2LSB45 Type: ET_DYN46 Machine: EM_X86_6447 48## Test llvm-nm dumping ELF file with an empty .dynsym section.49# RUN: yaml2obj --docnum=3 %s -o %t3.o50# RUN: llvm-nm --dynamic %t3.o 2>&1 | \51# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t3.o --check-prefix NO-SYMS52 53--- !ELF54FileHeader:55 Class: ELFCLASS6456 Data: ELFDATA2LSB57 Type: ET_DYN58 Machine: EM_X86_6459Sections:60 - Name: .dynsym61 Type: SHT_DYNSYM62 Size: 063 64## Check we print symbol versions, when they are available.65## A default version is one that is contained in the version table (SHT_GNU_versym)66## and only available for defined symbols. Check we use the "@@" prefix to print it.67 68# RUN: yaml2obj --docnum=4 %s -o %t4-undef.o69# RUN: llvm-nm --dynamic %t4-undef.o 2>&1 | \70# RUN: FileCheck %s -DFILE=%t4-undef.o -DTYPE=U \71# RUN: --check-prefixes=VERSIONED-SYMS,VERSIONED-UNDEF-SYMS72 73# RUN: yaml2obj --docnum=4 -DINDEX=0x1 %s -o %t4-def.o74# RUN: llvm-nm --dynamic %t4-def.o 2>&1 | \75# RUN: FileCheck %s -DFILE=%t4-def.o -DTYPE=r \76# RUN: --check-prefixes=VERSIONED-SYMS,VERSIONED-DEF-SYMS77 78# VERSIONED-SYMS: [[TYPE]] globalversym79# VERSIONED-SYMS-NEXT: [[TYPE]] localversym80# VERSIONED-UNDEF-SYMS-NEXT: [[TYPE]] version2sym@v281# VERSIONED-DEF-SYMS-NEXT: [[TYPE]] version2sym@@v282# VERSIONED-SYMS-NEXT: [[TYPE]] version3sym@v3hidden83# VERSIONED-SYMS-NEXT: [[TYPE]] version4sym@v484# VERSIONED-SYMS-NEXT: [[TYPE]] version5sym@v5hidden85 86--- !ELF87FileHeader:88 Class: ELFCLASS6489 Data: ELFDATA2LSB90 Type: ET_DYN91Sections:92 - Name: .gnu.version93 Type: SHT_GNU_versym94 Flags: [ SHF_ALLOC ]95## 0x8000 is a special VERSYM_HIDDEN bit.96 Entries: [ 0, 0, 1, [[VERSYMENTRY=2]], 0x8003, 4, 0x8005 ]97 ShSize: [[VERSYMSIZE=<none>]]98 - Name: .gnu.version_d99 Type: SHT_GNU_verdef100 Flags: [ SHF_ALLOC ]101 Link: .dynstr102 AddressAlign: 0x4103 Info: 0x2104 ShOffset: [[VERDEFOFFSET=<none>]]105 Entries:106 - VersionNdx: 2107 Names:108 - v2109 - VersionNdx: 3110 Names:111 - v3hidden112 - Name: .gnu.version_r113 Type: SHT_GNU_verneed114 Flags: [ SHF_ALLOC ]115 Link: .dynstr116 Info: 0x2117 Dependencies:118 - Version: 1119 File: file1.so120 Entries:121 - Name: v4122 Hash: 0123 Flags: 0124 Other: 4125 - Version: 1126 File: file2.0127 Entries:128 - Name: v5hidden129 Hash: 0130 Flags: 0131 Other: 5132 - Name: .dynsym133 Type: SHT_DYNSYM134 EntSize: [[ENTSIZE=<none>]]135DynamicSymbols:136 - Name: localversym137 Index: [[INDEX=<none>]]138 - Name: globalversym139 Index: [[INDEX=<none>]]140 - Name: version2sym141 Index: [[INDEX=<none>]]142 - Name: version3sym143 Index: [[INDEX=<none>]]144 - Name: version4sym145 Index: [[INDEX=<none>]]146 - Name: version5sym147 Index: [[INDEX=<none>]]148 149## In the following cases we check we report warnings when unable to read symbol version.150## Check that we still print unversioned symbol names.151 152## Case 1: check we report a warning when unable to read symbol versions153## from a broken SHT_GNU_verdef section. In this case its sh_offset154## field has a too large value that goes past the EOF.155 156# RUN: yaml2obj --docnum=4 -DVERDEFOFFSET=0xffffffff %s -o %t4-broken-verdef.o157# RUN: llvm-nm --dynamic %t4-broken-verdef.o 2>&1 | \158# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR1159 160# VERSION-ERR1: warning: unable to read symbol versions: cannot read content of SHT_GNU_verdef section with index 2: section [index 2] has a sh_offset (0xffffffff) + sh_size (0x38) that is greater than the file size (0x438)161# VERSION-ERR2: warning: unable to read symbol versions: unable to read an entry with index 1 from SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_size (255) which is not a multiple of its sh_entsize (2)162# VERSION-ERR3: warning: unable to read symbol versions: unable to get a version for entry 3 of SHT_GNU_versym section with index 1: SHT_GNU_versym section refers to a version index 255 which is missing163 164# VERSION-ERR-NEXT: U globalversym{{$}}165# VERSION-ERR-NEXT: U localversym{{$}}166# VERSION-ERR-NEXT: U version2sym{{$}}167# VERSION-ERR-NEXT: U version3sym{{$}}168# VERSION-ERR-NEXT: U version4sym{{$}}169# VERSION-ERR-NEXT: U version5sym{{$}}170 171## Case 2: check we report a warning when we are unable to read a SHT_GNU_versym section entry.172## In this case, the section has a size that is not a multiple of its sh_entsize.173 174# RUN: yaml2obj --docnum=4 -DVERSYMSIZE=0xff %s -o %t4-broken-versym.o175# RUN: llvm-nm --dynamic %t4-broken-versym.o 2>&1 | \176# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR2177 178## Case 3: check we report a warning when we are unable to get a version for a SHT_GNU_versym section entry.179## In this case the SHT_GNU_versym section refers to a version index 255 which is missing.180 181# RUN: yaml2obj --docnum=4 -DVERSYMENTRY=0xff %s -o %t4-broken-index.o182# RUN: llvm-nm --dynamic %t4-broken-index.o 2>&1 | \183# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR3184 185## Case 4: check we report a warning when we are unable to get symbol flags.186## In this case the dynamic symbol table has a wrong sh_entsize and we can't read a symbol.187 188# RUN: yaml2obj --docnum=4 -DENTSIZE=0xff %s -o %t4-broken-dynsym.o189# RUN: not llvm-nm --dynamic %t4-broken-dynsym.o 2>&1 | \190# RUN: FileCheck %s -DFILE=%t4-broken-dynsym.o --check-prefix=VERSION-ERR4191 192# VERSION-ERR4: warning: unable to read symbol versions: unable to read flags for symbol with index 1: section [index 4] has invalid sh_entsize: expected 24, but got 255193# VERSION-ERR4: error: [[FILE]]: section [index 4] has invalid sh_entsize: expected 24, but got 255194