1 ## This is a test for --dynamic/-D option.
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
11 # DYNSYM-NEXT: U localsym1
12 # DYNSYM-NEXT:0000000000000000 n localsym2
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
38 # NO-SYMS:[[FILE]]: no symbols
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
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.
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
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
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
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
104 ShOffset: [[VERDEFOFFSET=<none>]]
112 - Name: .gnu.version_r
113 Type: SHT_GNU_verneed
134 EntSize: [[ENTSIZE=<none>]]
137 Index: [[INDEX=<none>]]
139 Index: [[INDEX=<none>]]
141 Index: [[INDEX=<none>]]
143 Index: [[INDEX=<none>]]
145 Index: [[INDEX=<none>]]
147 Index: [[INDEX=<none>]]
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.
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.
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
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
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{{$}}
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.
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
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.
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
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.
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
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