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.o 5# RUN: llvm-nm --dynamic %t1.o | \ 6# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM 7# RUN: llvm-nm -D %t1.o | \ 8# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM 9 10# DYNSYM: U globalsym 11# DYNSYM-NEXT: U localsym1 12# DYNSYM-NEXT:0000000000000000 n localsym2 13# DYNSYM-EMPTY: 14 15--- !ELF 16FileHeader: 17 Class: ELFCLASS64 18 Data: ELFDATA2LSB 19 Type: ET_DYN 20 Machine: EM_X86_64 21Sections: 22 - Name: section 23 Type: SHT_PROGBITS 24DynamicSymbols: 25 - Name: localsym1 26 Type: STT_OBJECT 27 - Name: localsym2 28 Section: section 29 - Name: globalsym 30 Type: STT_OBJECT 31 Binding: STB_GLOBAL 32 33## Test llvm-nm dumping ELF file without a .dynsym section. 34# RUN: yaml2obj --docnum=2 %s -o %t2.o 35# RUN: llvm-nm --dynamic %t2.o 2>&1 | \ 36# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t2.o --check-prefix NO-SYMS 37 38# NO-SYMS:[[FILE]]: no symbols 39# NO-SYMS-EMPTY: 40 41--- !ELF 42FileHeader: 43 Class: ELFCLASS64 44 Data: ELFDATA2LSB 45 Type: ET_DYN 46 Machine: EM_X86_64 47 48## Test llvm-nm dumping ELF file with an empty .dynsym section. 49# RUN: yaml2obj --docnum=3 %s -o %t3.o 50# RUN: llvm-nm --dynamic %t3.o 2>&1 | \ 51# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t3.o --check-prefix NO-SYMS 52 53--- !ELF 54FileHeader: 55 Class: ELFCLASS64 56 Data: ELFDATA2LSB 57 Type: ET_DYN 58 Machine: EM_X86_64 59Sections: 60 - Name: .dynsym 61 Type: SHT_DYNSYM 62 Size: 0 63 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.o 69# 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-SYMS 72 73# RUN: yaml2obj --docnum=4 -DINDEX=0x1 %s -o %t4-def.o 74# 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-SYMS 77 78# VERSIONED-SYMS: [[TYPE]] globalversym 79# VERSIONED-SYMS-NEXT: [[TYPE]] localversym 80# VERSIONED-UNDEF-SYMS-NEXT: [[TYPE]] version2sym@v2 81# VERSIONED-DEF-SYMS-NEXT: [[TYPE]] version2sym@@v2 82# VERSIONED-SYMS-NEXT: [[TYPE]] version3sym@v3hidden 83# VERSIONED-SYMS-NEXT: [[TYPE]] version4sym@v4 84# VERSIONED-SYMS-NEXT: [[TYPE]] version5sym@v5hidden 85 86--- !ELF 87FileHeader: 88 Class: ELFCLASS64 89 Data: ELFDATA2LSB 90 Type: ET_DYN 91Sections: 92 - Name: .gnu.version 93 Type: SHT_GNU_versym 94 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_d 99 Type: SHT_GNU_verdef 100 Flags: [ SHF_ALLOC ] 101 Link: .dynstr 102 AddressAlign: 0x4 103 Info: 0x2 104 ShOffset: [[VERDEFOFFSET=<none>]] 105 Entries: 106 - VersionNdx: 2 107 Names: 108 - v2 109 - VersionNdx: 3 110 Names: 111 - v3hidden 112 - Name: .gnu.version_r 113 Type: SHT_GNU_verneed 114 Flags: [ SHF_ALLOC ] 115 Link: .dynstr 116 Info: 0x2 117 Dependencies: 118 - Version: 1 119 File: file1.so 120 Entries: 121 - Name: v4 122 Hash: 0 123 Flags: 0 124 Other: 4 125 - Version: 1 126 File: file2.0 127 Entries: 128 - Name: v5hidden 129 Hash: 0 130 Flags: 0 131 Other: 5 132 - Name: .dynsym 133 Type: SHT_DYNSYM 134 EntSize: [[ENTSIZE=<none>]] 135DynamicSymbols: 136 - Name: localversym 137 Index: [[INDEX=<none>]] 138 - Name: globalversym 139 Index: [[INDEX=<none>]] 140 - Name: version2sym 141 Index: [[INDEX=<none>]] 142 - Name: version3sym 143 Index: [[INDEX=<none>]] 144 - Name: version4sym 145 Index: [[INDEX=<none>]] 146 - Name: version5sym 147 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 versions 153## from a broken SHT_GNU_verdef section. In this case its sh_offset 154## field has a too large value that goes past the EOF. 155 156# RUN: yaml2obj --docnum=4 -DVERDEFOFFSET=0xffffffff %s -o %t4-broken-verdef.o 157# RUN: llvm-nm --dynamic %t4-broken-verdef.o 2>&1 | \ 158# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR1 159 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 missing 163 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.o 175# RUN: llvm-nm --dynamic %t4-broken-versym.o 2>&1 | \ 176# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR2 177 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.o 182# RUN: llvm-nm --dynamic %t4-broken-index.o 2>&1 | \ 183# RUN: FileCheck %s --check-prefixes=VERSION-ERR,VERSION-ERR3 184 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.o 189# RUN: not llvm-nm --dynamic %t4-broken-dynsym.o 2>&1 | \ 190# RUN: FileCheck %s -DFILE=%t4-broken-dynsym.o --check-prefix=VERSION-ERR4 191 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 255 193# VERSION-ERR4: error: [[FILE]]: section [index 4] has invalid sh_entsize: expected 24, but got 255 194