xref: /llvm-project/bolt/test/X86/dwarf5-debug-loclists.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1# REQUIRES: system-linux
2
3# RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %s -o %t1.o
4# RUN: %clang %cflags -dwarf-5 %t1.o -o %t.exe -Wl,-q
5# RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections
6# RUN: llvm-dwarfdump --show-form --verbose --debug-info %t.exe | FileCheck --check-prefix=PRECHECK %s
7# RUN: llvm-dwarfdump --show-form --verbose --debug-addr %t.bolt > %t.txt
8# RUN: llvm-dwarfdump --show-form --verbose --debug-info %t.bolt >> %t.txt
9# RUN: cat %t.txt | FileCheck --check-prefix=POSTCHECK %s
10
11## This tests checks that re-writing of .debug_loclists is handled correctly.
12
13# PRECHECK: version = 0x0005
14# PRECHECK: DW_AT_loclists_base [DW_FORM_sec_offset] (0x0000000c)
15# PRECHECK-EMPTY:
16# PRECHECK: DW_TAG_variable
17# PRECHECK: DW_AT_location [DW_FORM_loclistx]
18# PRECHECK-SAME: indexed (0x0)
19# PRECHECK-SAME: loclist = 0x00000010
20
21# POSTCHECK: Addrs: [
22# POSTCHECK-NEXT: 0x
23# POSTCHECK-NEXT: 0x
24# POSTCHECK-NEXT: 0x[[#%.16x,ADDR:]]
25# POSTCHECK: version = 0x0005
26# POSTCHECK: DW_AT_loclists_base [DW_FORM_sec_offset]	(0x0000000c)
27# POSTCHECK: DW_AT_rnglists_base [DW_FORM_sec_offset]	(0x0000000c)
28# POSTCHECK: DW_TAG_variable
29# POSTCHECK: DW_AT_location [DW_FORM_loclistx]
30# POSTCHECK-SAME: indexed (0x0)
31# POSTCHECK-SAME: loclist = 0x00000010
32# POSTCHECK-NEXT: [0x[[#ADDR]]
33# POSTCHECK-SAME: 0x[[#ADDR + 0x3]]
34# POSTCHECK-NEXT: [0x[[#ADDR + 0x3]]
35# POSTCHECK-SAME: 0x[[#ADDR + 0x4]]
36
37# clang++ main.cpp -g -O2 -S
38# void use(int * x) {
39# 	*x += 4;
40# }
41#
42# int  main(int argc, char *argv[]) {
43# 	int x = argc;
44# 	use(&x);
45# 	return x;
46# }
47
48	.text
49	.file	"main.cpp"
50	.globl	_Z3usePi                        # -- Begin function _Z3usePi
51	.p2align	4, 0x90
52	.type	_Z3usePi,@function
53_Z3usePi:                               # @_Z3usePi
54.Lfunc_begin0:
55	.file	0 "testLocList" "main.cpp" md5 0x95a77c95663d823a6228bf928825e8c7
56	.loc	0 1 0                           # main.cpp:1:0
57	.cfi_startproc
58# %bb.0:                                # %entry
59	#DEBUG_VALUE: use:x <- $rdi
60	.loc	0 2 4 prologue_end              # main.cpp:2:4
61	addl	$4, (%rdi)
62	.loc	0 3 1                           # main.cpp:3:1
63	retq
64.Ltmp0:
65.Lfunc_end0:
66	.size	_Z3usePi, .Lfunc_end0-_Z3usePi
67	.cfi_endproc
68                                        # -- End function
69	.globl	main                            # -- Begin function main
70	.p2align	4, 0x90
71	.type	main,@function
72main:                                   # @main
73.Lfunc_begin1:
74	.loc	0 5 0                           # main.cpp:5:0
75	.cfi_startproc
76# %bb.0:                                # %entry
77	#DEBUG_VALUE: main:argc <- $edi
78	#DEBUG_VALUE: main:argv <- $rsi
79	#DEBUG_VALUE: main:x <- $edi
80                                        # kill: def $edi killed $edi def $rdi
81	#DEBUG_VALUE: use:x <- undef
82	.loc	0 2 4 prologue_end              # main.cpp:2:4
83	leal	4(%rdi), %eax
84.Ltmp1:
85	#DEBUG_VALUE: main:x <- $eax
86	.loc	0 8 4                           # main.cpp:8:4
87	retq
88.Ltmp2:
89.Lfunc_end1:
90	.size	main, .Lfunc_end1-main
91	.cfi_endproc
92                                        # -- End function
93	.section	.debug_loclists,"",@progbits
94	.long	.Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length
95.Ldebug_list_header_start0:
96	.short	5                               # Version
97	.byte	8                               # Address size
98	.byte	0                               # Segment selector size
99	.long	1                               # Offset entry count
100.Lloclists_table_base0:
101	.long	.Ldebug_loc0-.Lloclists_table_base0
102.Ldebug_loc0:
103	.byte	4                               # DW_LLE_offset_pair
104	.uleb128 .Lfunc_begin1-.Lfunc_begin0    #   starting offset
105	.uleb128 .Ltmp1-.Lfunc_begin0           #   ending offset
106	.byte	1                               # Loc expr size
107	.byte	85                              # super-register DW_OP_reg5
108	.byte	4                               # DW_LLE_offset_pair
109	.uleb128 .Ltmp1-.Lfunc_begin0           #   starting offset
110	.uleb128 .Lfunc_end1-.Lfunc_begin0      #   ending offset
111	.byte	1                               # Loc expr size
112	.byte	80                              # super-register DW_OP_reg0
113	.byte	0                               # DW_LLE_end_of_list
114.Ldebug_list_header_end0:
115	.section	.debug_abbrev,"",@progbits
116	.byte	1                               # Abbreviation Code
117	.byte	17                              # DW_TAG_compile_unit
118	.byte	1                               # DW_CHILDREN_yes
119	.byte	37                              # DW_AT_producer
120	.byte	37                              # DW_FORM_strx1
121	.byte	19                              # DW_AT_language
122	.byte	5                               # DW_FORM_data2
123	.byte	3                               # DW_AT_name
124	.byte	37                              # DW_FORM_strx1
125	.byte	114                             # DW_AT_str_offsets_base
126	.byte	23                              # DW_FORM_sec_offset
127	.byte	16                              # DW_AT_stmt_list
128	.byte	23                              # DW_FORM_sec_offset
129	.byte	27                              # DW_AT_comp_dir
130	.byte	37                              # DW_FORM_strx1
131	.byte	17                              # DW_AT_low_pc
132	.byte	27                              # DW_FORM_addrx
133	.byte	18                              # DW_AT_high_pc
134	.byte	6                               # DW_FORM_data4
135	.byte	115                             # DW_AT_addr_base
136	.byte	23                              # DW_FORM_sec_offset
137	.ascii	"\214\001"                      # DW_AT_loclists_base
138	.byte	23                              # DW_FORM_sec_offset
139	.byte	0                               # EOM(1)
140	.byte	0                               # EOM(2)
141	.byte	2                               # Abbreviation Code
142	.byte	46                              # DW_TAG_subprogram
143	.byte	1                               # DW_CHILDREN_yes
144	.byte	17                              # DW_AT_low_pc
145	.byte	27                              # DW_FORM_addrx
146	.byte	18                              # DW_AT_high_pc
147	.byte	6                               # DW_FORM_data4
148	.byte	64                              # DW_AT_frame_base
149	.byte	24                              # DW_FORM_exprloc
150	.byte	122                             # DW_AT_call_all_calls
151	.byte	25                              # DW_FORM_flag_present
152	.byte	49                              # DW_AT_abstract_origin
153	.byte	19                              # DW_FORM_ref4
154	.byte	0                               # EOM(1)
155	.byte	0                               # EOM(2)
156	.byte	3                               # Abbreviation Code
157	.byte	5                               # DW_TAG_formal_parameter
158	.byte	0                               # DW_CHILDREN_no
159	.byte	2                               # DW_AT_location
160	.byte	24                              # DW_FORM_exprloc
161	.byte	49                              # DW_AT_abstract_origin
162	.byte	19                              # DW_FORM_ref4
163	.byte	0                               # EOM(1)
164	.byte	0                               # EOM(2)
165	.byte	4                               # Abbreviation Code
166	.byte	46                              # DW_TAG_subprogram
167	.byte	1                               # DW_CHILDREN_yes
168	.byte	110                             # DW_AT_linkage_name
169	.byte	37                              # DW_FORM_strx1
170	.byte	3                               # DW_AT_name
171	.byte	37                              # DW_FORM_strx1
172	.byte	58                              # DW_AT_decl_file
173	.byte	11                              # DW_FORM_data1
174	.byte	59                              # DW_AT_decl_line
175	.byte	11                              # DW_FORM_data1
176	.byte	63                              # DW_AT_external
177	.byte	25                              # DW_FORM_flag_present
178	.byte	32                              # DW_AT_inline
179	.byte	33                              # DW_FORM_implicit_const
180	.byte	1
181	.byte	0                               # EOM(1)
182	.byte	0                               # EOM(2)
183	.byte	5                               # Abbreviation Code
184	.byte	5                               # DW_TAG_formal_parameter
185	.byte	0                               # DW_CHILDREN_no
186	.byte	3                               # DW_AT_name
187	.byte	37                              # DW_FORM_strx1
188	.byte	58                              # DW_AT_decl_file
189	.byte	11                              # DW_FORM_data1
190	.byte	59                              # DW_AT_decl_line
191	.byte	11                              # DW_FORM_data1
192	.byte	73                              # DW_AT_type
193	.byte	19                              # DW_FORM_ref4
194	.byte	0                               # EOM(1)
195	.byte	0                               # EOM(2)
196	.byte	6                               # Abbreviation Code
197	.byte	15                              # DW_TAG_pointer_type
198	.byte	0                               # DW_CHILDREN_no
199	.byte	73                              # DW_AT_type
200	.byte	19                              # DW_FORM_ref4
201	.byte	0                               # EOM(1)
202	.byte	0                               # EOM(2)
203	.byte	7                               # Abbreviation Code
204	.byte	36                              # DW_TAG_base_type
205	.byte	0                               # DW_CHILDREN_no
206	.byte	3                               # DW_AT_name
207	.byte	37                              # DW_FORM_strx1
208	.byte	62                              # DW_AT_encoding
209	.byte	11                              # DW_FORM_data1
210	.byte	11                              # DW_AT_byte_size
211	.byte	11                              # DW_FORM_data1
212	.byte	0                               # EOM(1)
213	.byte	0                               # EOM(2)
214	.byte	8                               # Abbreviation Code
215	.byte	46                              # DW_TAG_subprogram
216	.byte	1                               # DW_CHILDREN_yes
217	.byte	17                              # DW_AT_low_pc
218	.byte	27                              # DW_FORM_addrx
219	.byte	18                              # DW_AT_high_pc
220	.byte	6                               # DW_FORM_data4
221	.byte	64                              # DW_AT_frame_base
222	.byte	24                              # DW_FORM_exprloc
223	.byte	122                             # DW_AT_call_all_calls
224	.byte	25                              # DW_FORM_flag_present
225	.byte	3                               # DW_AT_name
226	.byte	37                              # DW_FORM_strx1
227	.byte	58                              # DW_AT_decl_file
228	.byte	11                              # DW_FORM_data1
229	.byte	59                              # DW_AT_decl_line
230	.byte	11                              # DW_FORM_data1
231	.byte	73                              # DW_AT_type
232	.byte	19                              # DW_FORM_ref4
233	.byte	63                              # DW_AT_external
234	.byte	25                              # DW_FORM_flag_present
235	.byte	0                               # EOM(1)
236	.byte	0                               # EOM(2)
237	.byte	9                               # Abbreviation Code
238	.byte	5                               # DW_TAG_formal_parameter
239	.byte	0                               # DW_CHILDREN_no
240	.byte	2                               # DW_AT_location
241	.byte	24                              # DW_FORM_exprloc
242	.byte	3                               # DW_AT_name
243	.byte	37                              # DW_FORM_strx1
244	.byte	58                              # DW_AT_decl_file
245	.byte	11                              # DW_FORM_data1
246	.byte	59                              # DW_AT_decl_line
247	.byte	11                              # DW_FORM_data1
248	.byte	73                              # DW_AT_type
249	.byte	19                              # DW_FORM_ref4
250	.byte	0                               # EOM(1)
251	.byte	0                               # EOM(2)
252	.byte	10                              # Abbreviation Code
253	.byte	52                              # DW_TAG_variable
254	.byte	0                               # DW_CHILDREN_no
255	.byte	2                               # DW_AT_location
256	.byte	34                              # DW_FORM_loclistx
257	.byte	3                               # DW_AT_name
258	.byte	37                              # DW_FORM_strx1
259	.byte	58                              # DW_AT_decl_file
260	.byte	11                              # DW_FORM_data1
261	.byte	59                              # DW_AT_decl_line
262	.byte	11                              # DW_FORM_data1
263	.byte	73                              # DW_AT_type
264	.byte	19                              # DW_FORM_ref4
265	.byte	0                               # EOM(1)
266	.byte	0                               # EOM(2)
267	.byte	11                              # Abbreviation Code
268	.byte	29                              # DW_TAG_inlined_subroutine
269	.byte	0                               # DW_CHILDREN_no
270	.byte	49                              # DW_AT_abstract_origin
271	.byte	19                              # DW_FORM_ref4
272	.byte	17                              # DW_AT_low_pc
273	.byte	27                              # DW_FORM_addrx
274	.byte	18                              # DW_AT_high_pc
275	.byte	6                               # DW_FORM_data4
276	.byte	88                              # DW_AT_call_file
277	.byte	11                              # DW_FORM_data1
278	.byte	89                              # DW_AT_call_line
279	.byte	11                              # DW_FORM_data1
280	.byte	87                              # DW_AT_call_column
281	.byte	11                              # DW_FORM_data1
282	.byte	0                               # EOM(1)
283	.byte	0                               # EOM(2)
284	.byte	0                               # EOM(3)
285	.section	.debug_info,"",@progbits
286.Lcu_begin0:
287	.long	.Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
288.Ldebug_info_start0:
289	.short	5                               # DWARF version number
290	.byte	1                               # DWARF Unit Type
291	.byte	8                               # Address Size (in bytes)
292	.long	.debug_abbrev                   # Offset Into Abbrev. Section
293	.byte	1                               # Abbrev [1] 0xc:0x8f DW_TAG_compile_unit
294	.byte	0                               # DW_AT_producer
295	.short	33                              # DW_AT_language
296	.byte	1                               # DW_AT_name
297	.long	.Lstr_offsets_base0             # DW_AT_str_offsets_base
298	.long	.Lline_table_start0             # DW_AT_stmt_list
299	.byte	2                               # DW_AT_comp_dir
300	.byte	0                               # DW_AT_low_pc
301	.long	.Lfunc_end1-.Lfunc_begin0       # DW_AT_high_pc
302	.long	.Laddr_table_base0              # DW_AT_addr_base
303	.long	.Lloclists_table_base0          # DW_AT_loclists_base
304	.byte	2                               # Abbrev [2] 0x27:0x14 DW_TAG_subprogram
305	.byte	0                               # DW_AT_low_pc
306	.long	.Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
307	.byte	1                               # DW_AT_frame_base
308	.byte	87
309                                        # DW_AT_call_all_calls
310	.long	59                              # DW_AT_abstract_origin
311	.byte	3                               # Abbrev [3] 0x33:0x7 DW_TAG_formal_parameter
312	.byte	1                               # DW_AT_location
313	.byte	85
314	.long	64                              # DW_AT_abstract_origin
315	.byte	0                               # End Of Children Mark
316	.byte	4                               # Abbrev [4] 0x3b:0xe DW_TAG_subprogram
317	.byte	3                               # DW_AT_linkage_name
318	.byte	4                               # DW_AT_name
319	.byte	0                               # DW_AT_decl_file
320	.byte	1                               # DW_AT_decl_line
321                                        # DW_AT_external
322                                        # DW_AT_inline
323	.byte	5                               # Abbrev [5] 0x40:0x8 DW_TAG_formal_parameter
324	.byte	5                               # DW_AT_name
325	.byte	0                               # DW_AT_decl_file
326	.byte	1                               # DW_AT_decl_line
327	.long	73                              # DW_AT_type
328	.byte	0                               # End Of Children Mark
329	.byte	6                               # Abbrev [6] 0x49:0x5 DW_TAG_pointer_type
330	.long	78                              # DW_AT_type
331	.byte	7                               # Abbrev [7] 0x4e:0x4 DW_TAG_base_type
332	.byte	6                               # DW_AT_name
333	.byte	5                               # DW_AT_encoding
334	.byte	4                               # DW_AT_byte_size
335	.byte	8                               # Abbrev [8] 0x52:0x3a DW_TAG_subprogram
336	.byte	1                               # DW_AT_low_pc
337	.long	.Lfunc_end1-.Lfunc_begin1       # DW_AT_high_pc
338	.byte	1                               # DW_AT_frame_base
339	.byte	87
340                                        # DW_AT_call_all_calls
341	.byte	7                               # DW_AT_name
342	.byte	0                               # DW_AT_decl_file
343	.byte	5                               # DW_AT_decl_line
344	.long	78                              # DW_AT_type
345                                        # DW_AT_external
346	.byte	9                               # Abbrev [9] 0x61:0xa DW_TAG_formal_parameter
347	.byte	1                               # DW_AT_location
348	.byte	85
349	.byte	8                               # DW_AT_name
350	.byte	0                               # DW_AT_decl_file
351	.byte	5                               # DW_AT_decl_line
352	.long	78                              # DW_AT_type
353	.byte	9                               # Abbrev [9] 0x6b:0xa DW_TAG_formal_parameter
354	.byte	1                               # DW_AT_location
355	.byte	84
356	.byte	9                               # DW_AT_name
357	.byte	0                               # DW_AT_decl_file
358	.byte	5                               # DW_AT_decl_line
359	.long	140                             # DW_AT_type
360	.byte	10                              # Abbrev [10] 0x75:0x9 DW_TAG_variable
361	.byte	0                               # DW_AT_location
362	.byte	5                               # DW_AT_name
363	.byte	0                               # DW_AT_decl_file
364	.byte	6                               # DW_AT_decl_line
365	.long	78                              # DW_AT_type
366	.byte	11                              # Abbrev [11] 0x7e:0xd DW_TAG_inlined_subroutine
367	.long	59                              # DW_AT_abstract_origin
368	.byte	1                               # DW_AT_low_pc
369	.long	.Ltmp1-.Lfunc_begin1            # DW_AT_high_pc
370	.byte	0                               # DW_AT_call_file
371	.byte	7                               # DW_AT_call_line
372	.byte	4                               # DW_AT_call_column
373	.byte	0                               # End Of Children Mark
374	.byte	6                               # Abbrev [6] 0x8c:0x5 DW_TAG_pointer_type
375	.long	145                             # DW_AT_type
376	.byte	6                               # Abbrev [6] 0x91:0x5 DW_TAG_pointer_type
377	.long	150                             # DW_AT_type
378	.byte	7                               # Abbrev [7] 0x96:0x4 DW_TAG_base_type
379	.byte	10                              # DW_AT_name
380	.byte	6                               # DW_AT_encoding
381	.byte	1                               # DW_AT_byte_size
382	.byte	0                               # End Of Children Mark
383.Ldebug_info_end0:
384	.section	.debug_str_offsets,"",@progbits
385	.long	48                              # Length of String Offsets Set
386	.short	5
387	.short	0
388.Lstr_offsets_base0:
389	.section	.debug_str,"MS",@progbits,1
390.Linfo_string0:
391	.asciz	"clang version 15.0.0)" # string offset=0
392.Linfo_string1:
393	.asciz	"main.cpp"                      # string offset=134
394.Linfo_string2:
395	.asciz	"/testLocList" # string offset=143
396.Linfo_string3:
397	.asciz	"_Z3usePi"                      # string offset=192
398.Linfo_string4:
399	.asciz	"use"                           # string offset=201
400.Linfo_string5:
401	.asciz	"x"                             # string offset=205
402.Linfo_string6:
403	.asciz	"int"                           # string offset=207
404.Linfo_string7:
405	.asciz	"main"                          # string offset=211
406.Linfo_string8:
407	.asciz	"argc"                          # string offset=216
408.Linfo_string9:
409	.asciz	"argv"                          # string offset=221
410.Linfo_string10:
411	.asciz	"char"                          # string offset=226
412	.section	.debug_str_offsets,"",@progbits
413	.long	.Linfo_string0
414	.long	.Linfo_string1
415	.long	.Linfo_string2
416	.long	.Linfo_string3
417	.long	.Linfo_string4
418	.long	.Linfo_string5
419	.long	.Linfo_string6
420	.long	.Linfo_string7
421	.long	.Linfo_string8
422	.long	.Linfo_string9
423	.long	.Linfo_string10
424	.section	.debug_addr,"",@progbits
425	.long	.Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
426.Ldebug_addr_start0:
427	.short	5                               # DWARF version number
428	.byte	8                               # Address size
429	.byte	0                               # Segment selector size
430.Laddr_table_base0:
431	.quad	.Lfunc_begin0
432	.quad	.Lfunc_begin1
433.Ldebug_addr_end0:
434	.ident	"clang version 15.0.0"
435	.section	".note.GNU-stack","",@progbits
436	.addrsig
437	.section	.debug_line,"",@progbits
438.Lline_table_start0:
439