1## Show that when "DATA" is used with an address, it forces the found location 2## to be symbolized as data, including the source information. 3 4# RUN: yaml2obj %s -o %t.so 5 6# RUN: llvm-symbolizer 'DATA 0x304d0' 'DATA 0x304d1' 'DATA 0x304d3' \ 7# RUN: 'DATA 0x304c0' 'DATA 0x304c8' 'DATA 0x304d4' 'DATA 0x304dc' \ 8# RUN: 'DATA 0x304d8' --obj=%t.so | FileCheck %s 9 10# CHECK: bss_global 11# CHECK-NEXT: {{[0-9]+}} 4 12# CHECK-NEXT: /tmp/file.cpp:1 13# CHECK-EMPTY: 14 15## Check that lookups in the middle of the symbol are also resolved correctly. 16# CHECK: bss_global 17# CHECK-NEXT: {{[0-9]+}} 4 18# CHECK-NEXT: /tmp/file.cpp:1 19# CHECK-EMPTY: 20# CHECK: bss_global 21# CHECK-NEXT: {{[0-9]+}} 4 22# CHECK-NEXT: /tmp/file.cpp:1 23# CHECK-EMPTY: 24 25## Now, the remainder of the symbols. 26# CHECK-NEXT: data_global 27# CHECK-NEXT: {{[0-9]+}} 4 28# CHECK-NEXT: /tmp/file.cpp:2 29# CHECK-EMPTY: 30# CHECK-NEXT: str 31# CHECK-NEXT: {{[0-9]+}} 8 32# CHECK-NEXT: /tmp/file.cpp:4 33# CHECK-EMPTY: 34# CHECK-NEXT: f()::function_global 35# CHECK-NEXT: {{[0-9]+}} 4 36# CHECK-NEXT: /tmp/file.cpp:8 37# CHECK-EMPTY: 38 39## Including the one that includes an addend. 40# CHECK-NEXT: alpha 41# CHECK-NEXT: {{[0-9]+}} 4 42# CHECK-NEXT: /tmp/file.cpp:12 43# CHECK-EMPTY: 44# CHECK-NEXT: beta 45# CHECK-NEXT: {{[0-9]+}} 4 46# CHECK-NEXT: /tmp/file.cpp:13 47# CHECK-EMPTY: 48 49## Ensure there's still a global that's offset-based. 50# RUN: llvm-dwarfdump --debug-info %t.so | FileCheck %s --check-prefix=OFFSET 51 52# OFFSET: DW_AT_location (DW_OP_addrx 0x4, DW_OP_plus_uconst 0x4) 53 54################################################################################ 55## File below was generated using: 56## 57## $ clang++ -g -O3 /tmp/file.cpp -shared -fuse-ld=lld -nostdlib \ 58## -target aarch64-linux-gnuabi -mllvm -global-merge-ignore-single-use \ 59## -o /tmp/file.so 60## 61## With /tmp/file.cpp as: 62## 1: int bss_global; 63## 2: int data_global = 2; 64## 3: 65## 4: const char* str = 66## 5: "12345678"; 67## 6: 68## 7: int* f() { 69## 8: static int function_global; 70## 9: return &function_global; 71## 10: } 72## 11: 73## 12: static int alpha; 74## 13: static int beta; 75## 14: int *f(bool b) { return beta ? &alpha : β } 76## 15: 77## 78## ... then, one can get the offsets using `nm`, like: 79## $ nm out.so | grep bss_global 80## 00000000000038fc B bss_global 81## 82## Note the use of the aarch64 target (with -nostdlib in order to allow linkage 83## without libraries for cross-compilation) as well as -O3 and 84## -global-merge-ignore-single-use. This is a specific combination that makes 85## the compiler emit the `alpha` global variable with a more complex 86## DW_AT_location than just a DW_OP_addr/DW_OP_addrx. In this instance, it 87## outputs a `DW_AT_location (DW_OP_addrx 0x4, DW_OP_plus_uconst 0x4)`. 88## 89## Ideally, this would be tested by invoking clang directly on a C source file, 90## but unfortunately there's no way to do that for LLVM tests. The other option 91## is to compile IR to an objfile, but llvm-symbolizer doesn't understand that 92## two symbols can have the same address in different sections. In the code 93## above, for example, we'd have bss_global at .bss+0x0, and data_global at 94## .data+0x0, and so the symbolizer would only print one of them. Hence, we have 95## the ugly dso-to-yaml blob below. 96## 97## For now, constant strings don't have a debuginfo entry, and so can't be 98## symbolized correctly. In future (if D123534 gets merged), this can be updated 99## to include a check that llvm-symbolizer can also symbolize constant strings, 100## like `str` above (basically that &"12345678" should be symbolizable) 101## to the specific line. Then, you can find the address of the constant string 102## from the relocation: 103## 104## $ nm out.so | grep str 105## 00000000000038c0 D str 106## $ llvm-objdump -R out.so | grep 38c0 107## 00000000000038c0 R_X86_64_RELATIVE *ABS*+0x4f8 # <-- 0x4f8 108################################################################################ 109 110--- !ELF 111FileHeader: 112 Class: ELFCLASS64 113 Data: ELFDATA2LSB 114 Type: ET_DYN 115 Machine: EM_AARCH64 116ProgramHeaders: 117 - Type: PT_PHDR 118 Flags: [ PF_R ] 119 VAddr: 0x40 120 Align: 0x8 121 - Type: PT_LOAD 122 Flags: [ PF_R ] 123 FirstSec: .dynsym 124 LastSec: .eh_frame 125 Align: 0x10000 126 - Type: PT_LOAD 127 Flags: [ PF_X, PF_R ] 128 FirstSec: .text 129 LastSec: .text 130 VAddr: 0x103E4 131 Align: 0x10000 132 - Type: PT_LOAD 133 Flags: [ PF_W, PF_R ] 134 FirstSec: .dynamic 135 LastSec: .dynamic 136 VAddr: 0x20410 137 Align: 0x10000 138 - Type: PT_LOAD 139 Flags: [ PF_W, PF_R ] 140 FirstSec: .data 141 LastSec: .bss 142 VAddr: 0x304C0 143 Align: 0x10000 144 - Type: PT_DYNAMIC 145 Flags: [ PF_W, PF_R ] 146 FirstSec: .dynamic 147 LastSec: .dynamic 148 VAddr: 0x20410 149 Align: 0x8 150 - Type: PT_GNU_RELRO 151 Flags: [ PF_R ] 152 FirstSec: .dynamic 153 LastSec: .dynamic 154 VAddr: 0x20410 155 - Type: PT_GNU_EH_FRAME 156 Flags: [ PF_R ] 157 FirstSec: .eh_frame_hdr 158 LastSec: .eh_frame_hdr 159 VAddr: 0x37C 160 Align: 0x4 161 - Type: PT_GNU_STACK 162 Flags: [ PF_W, PF_R ] 163 Align: 0x0 164Sections: 165 - Name: .dynsym 166 Type: SHT_DYNSYM 167 Flags: [ SHF_ALLOC ] 168 Address: 0x238 169 Link: .dynstr 170 AddressAlign: 0x8 171 - Name: .gnu.hash 172 Type: SHT_GNU_HASH 173 Flags: [ SHF_ALLOC ] 174 Address: 0x2C8 175 Link: .dynsym 176 AddressAlign: 0x8 177 Header: 178 SymNdx: 0x1 179 Shift2: 0x1A 180 BloomFilter: [ 0x400188002180000C ] 181 HashBuckets: [ 0x1 ] 182 HashValues: [ 0xEE8502A, 0xEE85016, 0xC033991C, 0x61F7372E, 0xB88AB7F ] 183 - Name: .hash 184 Type: SHT_HASH 185 Flags: [ SHF_ALLOC ] 186 Address: 0x2F8 187 Link: .dynsym 188 AddressAlign: 0x4 189 Bucket: [ 5, 0, 4, 0, 3, 0 ] 190 Chain: [ 0, 0, 0, 1, 2, 0 ] 191 - Name: .dynstr 192 Type: SHT_STRTAB 193 Flags: [ SHF_ALLOC ] 194 Address: 0x330 195 AddressAlign: 0x1 196 - Name: .rela.dyn 197 Type: SHT_RELA 198 Flags: [ SHF_ALLOC ] 199 Address: 0x358 200 Link: .dynsym 201 AddressAlign: 0x8 202 Relocations: 203 - Offset: 0x304C8 204 Type: R_AARCH64_RELATIVE 205 Addend: 880 206 - Name: .rodata 207 Type: SHT_PROGBITS 208 Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] 209 Address: 0x370 210 AddressAlign: 0x1 211 EntSize: 0x1 212 Content: '313233343536373800' 213 - Name: .eh_frame_hdr 214 Type: SHT_PROGBITS 215 Flags: [ SHF_ALLOC ] 216 Address: 0x37C 217 AddressAlign: 0x4 218 Content: 011B033B18000000020000006800010034000000740001004C000000 219 - Name: .eh_frame 220 Type: SHT_PROGBITS 221 Flags: [ SHF_ALLOC ] 222 Address: 0x398 223 AddressAlign: 0x8 224 Content: 1400000000000000017A5200017C1E011B0C1F0000000000140000001C0000002C0001000C00000000000000000000001400000034000000200001001C000000000000000000000000000000 225 - Name: .text 226 Type: SHT_PROGBITS 227 Flags: [ SHF_ALLOC, SHF_EXECINSTR ] 228 Address: 0x103E4 229 AddressAlign: 0x4 230 Content: 0001009000501391C0035FD60801009008611391E90308AA2A4540B85F0100710001899AC0035FD6 231 - Name: .dynamic 232 Type: SHT_DYNAMIC 233 Flags: [ SHF_WRITE, SHF_ALLOC ] 234 Address: 0x20410 235 Link: .dynstr 236 AddressAlign: 0x8 237 Entries: 238 - Tag: DT_RELA 239 Value: 0x358 240 - Tag: DT_RELASZ 241 Value: 0x18 242 - Tag: DT_RELAENT 243 Value: 0x18 244 - Tag: DT_RELACOUNT 245 Value: 0x1 246 - Tag: DT_SYMTAB 247 Value: 0x238 248 - Tag: DT_SYMENT 249 Value: 0x18 250 - Tag: DT_STRTAB 251 Value: 0x330 252 - Tag: DT_STRSZ 253 Value: 0x28 254 - Tag: DT_GNU_HASH 255 Value: 0x2C8 256 - Tag: DT_HASH 257 Value: 0x2F8 258 - Tag: DT_NULL 259 Value: 0x0 260 - Name: .data 261 Type: SHT_PROGBITS 262 Flags: [ SHF_WRITE, SHF_ALLOC ] 263 Address: 0x304C0 264 AddressAlign: 0x8 265 Content: '02000000000000000000000000000000' 266 - Name: .bss 267 Type: SHT_NOBITS 268 Flags: [ SHF_WRITE, SHF_ALLOC ] 269 Address: 0x304D0 270 AddressAlign: 0x4 271 Size: 0x10 272 - Name: .debug_abbrev 273 Type: SHT_PROGBITS 274 AddressAlign: 0x1 275 Content: 011101252513050325721710171B25111B120673170000023400032549133F193A0B3B0B0218000003240003253E0B0B0B0000040F004913000005260049130000062E01111B120640187A196E2503253A0B3B0B49133F190000073400032549133A0B3B0B02180000083400032549133A0B3B0B02186E25000009050003253A0B3B0B4913000000 276 - Name: .debug_info 277 Type: SHT_PROGBITS 278 AddressAlign: 0x1 279 Content: AB0000000500010800000000010021000108000000000000000205280000000800000002032E000000000102A1000304050402052E000000000202A101020648000000000402A102044D00000005520000000307080106050C000000016F0D0E0007A500000007082E000000000802A1030008092E000000000D02A1040A080B2E000000000C04A10423040C06061C000000016F0F0E000EA50000000910000EAA00000000042E0000000311020100 280 - Name: .debug_str_offsets 281 Type: SHT_PROGBITS 282 AddressAlign: 0x1 283 Content: 4C00000005000000A2000000000000002C00000059000000280000001C00000072000000640000008C0000008700000069000000140000007B0000009C0000001A0000000E0000008500000076000000 284 - Name: .comment 285 Type: SHT_PROGBITS 286 Flags: [ SHF_MERGE, SHF_STRINGS ] 287 AddressAlign: 0x1 288 EntSize: 0x1 289 Content: 4C696E6B65723A204C4C442031352E302E300000636C616E672076657273696F6E2031352E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E67697420306462616566363162353666306566306162306366333865613932666663316633356265653366662900 290 - Name: .debug_line 291 Type: SHT_PROGBITS 292 AddressAlign: 0x1 293 Content: 620000000500080037000000010101FB0E0D00010101010000000100000101011F010E00000003011F020F051E0100000000006C97BBE59F7DC6A9EA956633431DA63E0400000902E4030100000000001805030A140500BF05190A0105120608740204000101 294 - Name: .debug_line_str 295 Type: SHT_PROGBITS 296 Flags: [ SHF_MERGE, SHF_STRINGS ] 297 AddressAlign: 0x1 298 EntSize: 0x1 299 Content: 2F746D702F66696C652E637070002F7573722F6C6F63616C2F676F6F676C652F686F6D652F6D69746368702F6C6C766D2D6275696C642F6F707400 300Symbols: 301 - Name: file.cpp 302 Type: STT_FILE 303 Index: SHN_ABS 304 - Name: '$x.0' 305 Section: .text 306 Value: 0x103E4 307 - Name: _ZZ1fvE15function_global 308 Type: STT_OBJECT 309 Section: .bss 310 Value: 0x304D4 311 Size: 0x4 312 - Name: '$d.1' 313 Section: .bss 314 Value: 0x304D0 315 - Name: '$d.2' 316 Section: .data 317 Value: 0x304C0 318 - Name: '$d.3' 319 Section: .rodata 320 Value: 0x370 321 - Name: '$d.4' 322 Section: .debug_abbrev 323 - Name: '$d.5' 324 Section: .debug_info 325 - Name: '$d.6' 326 Section: .debug_str_offsets 327 - Name: '$d.7' 328 Section: .debug_str 329 Value: 0xA2 330 - Name: '$d.8' 331 Section: .debug_addr 332 - Name: _ZL4beta 333 Type: STT_OBJECT 334 Section: .bss 335 Value: 0x304D8 336 Size: 0x4 337 - Name: _ZL5alpha 338 Type: STT_OBJECT 339 Section: .bss 340 Value: 0x304DC 341 Size: 0x4 342 - Name: '$d.9' 343 Section: .comment 344 Value: 0x13 345 - Name: '$d.10' 346 Section: .eh_frame 347 Value: 0x398 348 - Name: '$d.11' 349 Section: .debug_line 350 - Name: '$d.12' 351 Section: .debug_line_str 352 Value: 0xE 353 - Name: _DYNAMIC 354 Section: .dynamic 355 Value: 0x20410 356 Other: [ STV_HIDDEN ] 357 - Name: _Z1fv 358 Type: STT_FUNC 359 Section: .text 360 Binding: STB_GLOBAL 361 Value: 0x103E4 362 Size: 0xC 363 - Name: _Z1fb 364 Type: STT_FUNC 365 Section: .text 366 Binding: STB_GLOBAL 367 Value: 0x103F0 368 Size: 0x1C 369 - Name: bss_global 370 Type: STT_OBJECT 371 Section: .bss 372 Binding: STB_GLOBAL 373 Value: 0x304D0 374 Size: 0x4 375 - Name: data_global 376 Type: STT_OBJECT 377 Section: .data 378 Binding: STB_GLOBAL 379 Value: 0x304C0 380 Size: 0x4 381 - Name: str 382 Type: STT_OBJECT 383 Section: .data 384 Binding: STB_GLOBAL 385 Value: 0x304C8 386 Size: 0x8 387DynamicSymbols: 388 - Name: _Z1fv 389 Type: STT_FUNC 390 Section: .text 391 Binding: STB_GLOBAL 392 Value: 0x103E4 393 Size: 0xC 394 - Name: _Z1fb 395 Type: STT_FUNC 396 Section: .text 397 Binding: STB_GLOBAL 398 Value: 0x103F0 399 Size: 0x1C 400 - Name: bss_global 401 Type: STT_OBJECT 402 Section: .bss 403 Binding: STB_GLOBAL 404 Value: 0x304D0 405 Size: 0x4 406 - Name: data_global 407 Type: STT_OBJECT 408 Section: .data 409 Binding: STB_GLOBAL 410 Value: 0x304C0 411 Size: 0x4 412 - Name: str 413 Type: STT_OBJECT 414 Section: .data 415 Binding: STB_GLOBAL 416 Value: 0x304C8 417 Size: 0x8 418DWARF: 419 debug_str: 420 - '/tmp/file.cpp' 421 - _Z1fb 422 - alpha 423 - f 424 - data_global 425 - int 426 - '/usr/local/google/home/mitchp/llvm-build/opt' 427 - bss_global 428 - char 429 - _ZL4beta 430 - str 431 - bool 432 - _ZL5alpha 433 - b 434 - beta 435 - function_global 436 - _Z1fv 437 - 'clang version 15.0.0 (https://github.com/llvm/llvm-project.git 0dbaef61b56f0ef0ab0cf38ea92ffc1f35bee3ff)' 438 debug_addr: 439 - Length: 0x3C 440 Version: 0x5 441 AddressSize: 0x8 442 Entries: 443 - Address: 0x304D0 444 - Address: 0x304C0 445 - Address: 0x304C8 446 - Address: 0x304D4 447 - Address: 0x304D8 448 - Address: 0x103E4 449 - Address: 0x103F0 450... 451