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.
4 # RUN: yaml2obj %s -o %t.so
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
11 # CHECK-NEXT: {{[0-9]+}} 4
12 # CHECK-NEXT: /tmp/file.cpp:1
15 ## Check that lookups in the middle of the symbol are also resolved correctly.
17 # CHECK-NEXT: {{[0-9]+}} 4
18 # CHECK-NEXT: /tmp/file.cpp:1
21 # CHECK-NEXT: {{[0-9]+}} 4
22 # CHECK-NEXT: /tmp/file.cpp:1
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
31 # CHECK-NEXT: {{[0-9]+}} 8
32 # CHECK-NEXT: /tmp/file.cpp:4
34 # CHECK-NEXT: f()::function_global
35 # CHECK-NEXT: {{[0-9]+}} 4
36 # CHECK-NEXT: /tmp/file.cpp:8
39 ## Including the one that includes an addend.
41 # CHECK-NEXT: {{[0-9]+}} 4
42 # CHECK-NEXT: /tmp/file.cpp:12
45 # CHECK-NEXT: {{[0-9]+}} 4
46 # CHECK-NEXT: /tmp/file.cpp:13
49 ## Ensure there's still a global that's offset-based.
50 # RUN: llvm-dwarfdump --debug-info %t.so | FileCheck %s --check-prefix=OFFSET
52 # OFFSET: DW_AT_location (DW_OP_addrx 0x4, DW_OP_plus_uconst 0x4)
54 ################################################################################
55 ## File below was generated using:
57 ## $ clang++ -g -O3 /tmp/file.cpp -shared -fuse-ld=lld -nostdlib \
58 ## -target aarch64-linux-gnuabi -mllvm -global-merge-ignore-single-use \
61 ## With /tmp/file.cpp as:
63 ## 2: int data_global = 2;
65 ## 4: const char* str =
69 ## 8: static int function_global;
70 ## 9: return &function_global;
73 ## 12: static int alpha;
74 ## 13: static int beta;
75 ## 14: int *f(bool b) { return beta ? &alpha : β }
78 ## ... then, one can get the offsets using `nm`, like:
79 ## $ nm out.so | grep bss_global
80 ## 00000000000038fc B bss_global
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)`.
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.
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:
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 ################################################################################
127 Flags: [ PF_X, PF_R ]
133 Flags: [ PF_W, PF_R ]
139 Flags: [ PF_W, PF_R ]
145 Flags: [ PF_W, PF_R ]
155 - Type: PT_GNU_EH_FRAME
157 FirstSec: .eh_frame_hdr
158 LastSec: .eh_frame_hdr
162 Flags: [ PF_W, PF_R ]
180 BloomFilter: [ 0x400188002180000C ]
182 HashValues: [ 0xEE8502A, 0xEE85016, 0xC033991C, 0x61F7372E, 0xB88AB7F ]
189 Bucket: [ 5, 0, 4, 0, 3, 0 ]
190 Chain: [ 0, 0, 0, 1, 2, 0 ]
204 Type: R_AARCH64_RELATIVE
208 Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
212 Content: '313233343536373800'
213 - Name: .eh_frame_hdr
218 Content: 011B033B18000000020000006800010034000000740001004C000000
224 Content: 1400000000000000017A5200017C1E011B0C1F0000000000140000001C0000002C0001000C00000000000000000000001400000034000000200001001C000000000000000000000000000000
227 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
230 Content: 0001009000501391C0035FD60801009008611391E90308AA2A4540B85F0100710001899AC0035FD6
233 Flags: [ SHF_WRITE, SHF_ALLOC ]
262 Flags: [ SHF_WRITE, SHF_ALLOC ]
265 Content: '02000000000000000000000000000000'
268 Flags: [ SHF_WRITE, SHF_ALLOC ]
272 - Name: .debug_abbrev
275 Content: 011101252513050325721710171B25111B120673170000023400032549133F193A0B3B0B0218000003240003253E0B0B0B0000040F004913000005260049130000062E01111B120640187A196E2503253A0B3B0B49133F190000073400032549133A0B3B0B02180000083400032549133A0B3B0B02186E25000009050003253A0B3B0B4913000000
279 Content: AB0000000500010800000000010021000108000000000000000205280000000800000002032E000000000102A1000304050402052E000000000202A101020648000000000402A102044D00000005520000000307080106050C000000016F0D0E0007A500000007082E000000000802A1030008092E000000000D02A1040A080B2E000000000C04A10423040C06061C000000016F0F0E000EA50000000910000EAA00000000042E0000000311020100
280 - Name: .debug_str_offsets
283 Content: 4C00000005000000A2000000000000002C00000059000000280000001C00000072000000640000008C0000008700000069000000140000007B0000009C0000001A0000000E0000008500000076000000
286 Flags: [ SHF_MERGE, SHF_STRINGS ]
289 Content: 4C696E6B65723A204C4C442031352E302E300000636C616E672076657273696F6E2031352E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E67697420306462616566363162353666306566306162306366333865613932666663316633356265653366662900
293 Content: 620000000500080037000000010101FB0E0D00010101010000000100000101011F010E00000003011F020F051E0100000000006C97BBE59F7DC6A9EA956633431DA63E0400000902E4030100000000001805030A140500BF05190A0105120608740204000101
294 - Name: .debug_line_str
296 Flags: [ SHF_MERGE, SHF_STRINGS ]
299 Content: 2F746D702F66696C652E637070002F7573722F6C6F63616C2F676F6F676C652F686F6D652F6D69746368702F6C6C766D2D6275696C642F6F707400
307 - Name: _ZZ1fvE15function_global
322 Section: .debug_abbrev
326 Section: .debug_str_offsets
351 Section: .debug_line_str
356 Other: [ STV_HIDDEN ]
426 - '/usr/local/google/home/mitchp/llvm-build/opt'
437 - 'clang version 15.0.0 (https://github.com/llvm/llvm-project.git 0dbaef61b56f0ef0ab0cf38ea92ffc1f35bee3ff)'