xref: /llvm-project/bolt/test/X86/dwarf5-lowpc-highpc-convert.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 --always-convert-to-ranges
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 DW_AT_low_pc/DW_AT_high_pc is converted to DW_AT_low_pc/DW_AT_ranges.
12## Checks that DW_AT_rnglists_base is inserted, and that correct address is used.
13
14# PRECHECK: version = 0x0005
15# PRECHECK: DW_AT_low_pc
16# PRECHECK-SAME: DW_FORM_addrx
17# PRECHECK-SAME: (00000000)
18# PRECHECK-NEXT: DW_AT_high_pc [DW_FORM_data4]	(0x0000000f)
19# PRECHECK-NEXT: DW_AT_addr_base [DW_FORM_sec_offset]	(0x00000008)
20
21# POSTCHECK: Addrs: [
22# POSTCHECK-NEXT: 0x[[#%.16x,ADDR:]]
23# POSTCHECK: version = 0x0005
24# POSTCHECK: DW_AT_low_pc
25# POSTCHECK-SAME: DW_FORM_addrx
26# POSTCHECK-SAME: (00000001)
27# POSTCHECK-SAME: address = 0x0000000000000000
28# POSTCHECK-NEXT: DW_AT_ranges
29# POSTCHECK-SAME: DW_FORM_rnglistx
30# POSTCHECK-SAME: (0x0)
31# POSTCHECK-SAME: rangelist = 0x00000014
32# POSTCHECK-NEXT: [
33# POSTCHECK-SAME: 0x[[#ADDR]]
34# POSTCHECK-SAME: 0x[[#ADDR + 15]]
35# POSTCHECK-NEXT: DW_AT_addr_base [DW_FORM_sec_offset]  (0x00000008)
36# POSTCHECK-NEXT: DW_AT_rnglists_base [DW_FORM_sec_offset]  (0x0000000c)
37
38# int main() {
39#    return 0;
40# }
41
42	.text
43	.file	"main.cpp"
44	.globl	main                            # -- Begin function main
45	.p2align	4, 0x90
46	.type	main,@function
47main:                                   # @main
48.Lfunc_begin0:
49	.file	0 "." "main.cpp" md5 0xbb12fec8d002b1f0e06f7dee4604c6cc
50	.loc	0 1 0                           # main.cpp:1:0
51	.cfi_startproc
52# %bb.0:                                # %entry
53	pushq	%rbp
54	.cfi_def_cfa_offset 16
55	.cfi_offset %rbp, -16
56	movq	%rsp, %rbp
57	.cfi_def_cfa_register %rbp
58	movl	$0, -4(%rbp)
59.Ltmp0:
60	.loc	0 2 3 prologue_end              # main.cpp:2:3
61	xorl	%eax, %eax
62	popq	%rbp
63	.cfi_def_cfa %rsp, 8
64	retq
65.Ltmp1:
66.Lfunc_end0:
67	.size	main, .Lfunc_end0-main
68	.cfi_endproc
69                                        # -- End function
70	.section	.debug_abbrev,"",@progbits
71	.byte	1                               # Abbreviation Code
72	.byte	17                              # DW_TAG_compile_unit
73	.byte	1                               # DW_CHILDREN_yes
74	.byte	37                              # DW_AT_producer
75	.byte	37                              # DW_FORM_strx1
76	.byte	19                              # DW_AT_language
77	.byte	5                               # DW_FORM_data2
78	.byte	3                               # DW_AT_name
79	.byte	37                              # DW_FORM_strx1
80	.byte	114                             # DW_AT_str_offsets_base
81	.byte	23                              # DW_FORM_sec_offset
82	.byte	16                              # DW_AT_stmt_list
83	.byte	23                              # DW_FORM_sec_offset
84	.byte	27                              # DW_AT_comp_dir
85	.byte	37                              # DW_FORM_strx1
86	.byte	17                              # DW_AT_low_pc
87	.byte	27                              # DW_FORM_addrx
88	.byte	18                              # DW_AT_high_pc
89	.byte	6                               # DW_FORM_data4
90	.byte	115                             # DW_AT_addr_base
91	.byte	23                              # DW_FORM_sec_offset
92	.byte	0                               # EOM(1)
93	.byte	0                               # EOM(2)
94	.byte	2                               # Abbreviation Code
95	.byte	46                              # DW_TAG_subprogram
96	.byte	0                               # DW_CHILDREN_no
97	.byte	17                              # DW_AT_low_pc
98	.byte	27                              # DW_FORM_addrx
99	.byte	18                              # DW_AT_high_pc
100	.byte	6                               # DW_FORM_data4
101	.byte	64                              # DW_AT_frame_base
102	.byte	24                              # DW_FORM_exprloc
103	.byte	3                               # DW_AT_name
104	.byte	37                              # DW_FORM_strx1
105	.byte	58                              # DW_AT_decl_file
106	.byte	11                              # DW_FORM_data1
107	.byte	59                              # DW_AT_decl_line
108	.byte	11                              # DW_FORM_data1
109	.byte	73                              # DW_AT_type
110	.byte	19                              # DW_FORM_ref4
111	.byte	63                              # DW_AT_external
112	.byte	25                              # DW_FORM_flag_present
113	.byte	0                               # EOM(1)
114	.byte	0                               # EOM(2)
115	.byte	3                               # Abbreviation Code
116	.byte	36                              # DW_TAG_base_type
117	.byte	0                               # DW_CHILDREN_no
118	.byte	3                               # DW_AT_name
119	.byte	37                              # DW_FORM_strx1
120	.byte	62                              # DW_AT_encoding
121	.byte	11                              # DW_FORM_data1
122	.byte	11                              # DW_AT_byte_size
123	.byte	11                              # DW_FORM_data1
124	.byte	0                               # EOM(1)
125	.byte	0                               # EOM(2)
126	.byte	0                               # EOM(3)
127	.section	.debug_info,"",@progbits
128.Lcu_begin0:
129	.long	.Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
130.Ldebug_info_start0:
131	.short	5                               # DWARF version number
132	.byte	1                               # DWARF Unit Type
133	.byte	8                               # Address Size (in bytes)
134	.long	.debug_abbrev                   # Offset Into Abbrev. Section
135	.byte	1                               # Abbrev [1] 0xc:0x2b DW_TAG_compile_unit
136	.byte	0                               # DW_AT_producer
137	.short	33                              # DW_AT_language
138	.byte	1                               # DW_AT_name
139	.long	.Lstr_offsets_base0             # DW_AT_str_offsets_base
140	.long	.Lline_table_start0             # DW_AT_stmt_list
141	.byte	2                               # DW_AT_comp_dir
142	.byte	0                               # DW_AT_low_pc
143	.long	.Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
144	.long	.Laddr_table_base0              # DW_AT_addr_base
145	.byte	2                               # Abbrev [2] 0x23:0xf DW_TAG_subprogram
146	.byte	0                               # DW_AT_low_pc
147	.long	.Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
148	.byte	1                               # DW_AT_frame_base
149	.byte	86
150	.byte	3                               # DW_AT_name
151	.byte	0                               # DW_AT_decl_file
152	.byte	1                               # DW_AT_decl_line
153	.long	50                              # DW_AT_type
154                                        # DW_AT_external
155	.byte	3                               # Abbrev [3] 0x32:0x4 DW_TAG_base_type
156	.byte	4                               # DW_AT_name
157	.byte	5                               # DW_AT_encoding
158	.byte	4                               # DW_AT_byte_size
159	.byte	0                               # End Of Children Mark
160.Ldebug_info_end0:
161	.section	.debug_str_offsets,"",@progbits
162	.long	24                              # Length of String Offsets Set
163	.short	5
164	.short	0
165.Lstr_offsets_base0:
166	.section	.debug_str,"MS",@progbits,1
167.Linfo_string0:
168	.asciz	"clang version 15.0.0" # string offset=0
169.Linfo_string1:
170	.asciz	"main.cpp"                      # string offset=134
171.Linfo_string2:
172	.asciz	"." # string offset=143
173.Linfo_string3:
174	.asciz	"main"                          # string offset=180
175.Linfo_string4:
176	.asciz	"int"                           # string offset=185
177	.section	.debug_str_offsets,"",@progbits
178	.long	.Linfo_string0
179	.long	.Linfo_string1
180	.long	.Linfo_string2
181	.long	.Linfo_string3
182	.long	.Linfo_string4
183	.section	.debug_addr,"",@progbits
184	.long	.Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
185.Ldebug_addr_start0:
186	.short	5                               # DWARF version number
187	.byte	8                               # Address size
188	.byte	0                               # Segment selector size
189.Laddr_table_base0:
190	.quad	.Lfunc_begin0
191.Ldebug_addr_end0:
192	.ident	"clang version 15.0.0"
193	.section	".note.GNU-stack","",@progbits
194	.addrsig
195	.section	.debug_line,"",@progbits
196.Lline_table_start0:
197