Skip to content

Commit 5ff8b30

Browse files
authored
[BOLT][DWARF] Do not emit zero low_pc address arange (#81955)
According to DWARF spec zero entires indicate end of arange. Changed so that BOLT does not emit zero low_pc arange.
1 parent dc85719 commit 5ff8b30

File tree

4 files changed

+568
-1
lines changed

4 files changed

+568
-1
lines changed

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ void DWARFRewriter::updateUnitDebugInfo(
873873
OutputRanges.push_back({0, 0});
874874
const uint64_t RangesSectionOffset =
875875
RangesSectionWriter.addRanges(OutputRanges);
876-
if (!Unit.isDWOUnit())
876+
// Don't emit the zero low_pc arange.
877+
if (!Unit.isDWOUnit() && !OutputRanges.empty() &&
878+
OutputRanges.back().LowPC)
877879
ARangesSectionWriter->addCURanges(Unit.getOffset(),
878880
std::move(OutputRanges));
879881
updateDWARFObjectAddressRanges(Unit, DIEBldr, *Die, RangesSectionOffset,
Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
# clang++ -O0 -g2 -S -ffunction-sections -o
2+
# int Foo;
3+
# int helper() {
4+
# return 0;
5+
# }
6+
#
7+
# int helperhelper() {
8+
# return 0;
9+
# }
10+
# int helperhelper2() {
11+
# return 1;
12+
# }
13+
14+
.text
15+
.file "helper.cpp"
16+
.file 0 "/repro2" "helper.cpp" md5 0xef451fc8d099ed067c9f2ff97d8aacf6
17+
.section .text._Z6helperv,"ax",@progbits
18+
.globl _Z6helperv # -- Begin function _Z6helperv
19+
.p2align 4, 0x90
20+
.type _Z6helperv,@function
21+
_Z6helperv: # @_Z6helperv
22+
.Lfunc_begin0:
23+
.loc 0 2 0 # helper.cpp:2:0
24+
.cfi_startproc
25+
# %bb.0: # %entry
26+
pushq %rbp
27+
.cfi_def_cfa_offset 16
28+
.cfi_offset %rbp, -16
29+
movq %rsp, %rbp
30+
.cfi_def_cfa_register %rbp
31+
.Ltmp0:
32+
.loc 0 3 3 prologue_end # helper.cpp:3:3
33+
xorl %eax, %eax
34+
.loc 0 3 3 epilogue_begin is_stmt 0 # helper.cpp:3:3
35+
popq %rbp
36+
.cfi_def_cfa %rsp, 8
37+
retq
38+
.Ltmp1:
39+
.Lfunc_end0:
40+
.size _Z6helperv, .Lfunc_end0-_Z6helperv
41+
.cfi_endproc
42+
# -- End function
43+
.section .text._Z12helperhelperv,"ax",@progbits
44+
.globl _Z12helperhelperv # -- Begin function _Z12helperhelperv
45+
.p2align 4, 0x90
46+
.type _Z12helperhelperv,@function
47+
_Z12helperhelperv: # @_Z12helperhelperv
48+
.Lfunc_begin1:
49+
.loc 0 5 0 is_stmt 1 # helper.cpp:5:0
50+
.cfi_startproc
51+
# %bb.0: # %entry
52+
pushq %rbp
53+
.cfi_def_cfa_offset 16
54+
.cfi_offset %rbp, -16
55+
movq %rsp, %rbp
56+
.cfi_def_cfa_register %rbp
57+
.Ltmp2:
58+
.loc 0 6 3 prologue_end # helper.cpp:6:3
59+
xorl %eax, %eax
60+
.loc 0 6 3 epilogue_begin is_stmt 0 # helper.cpp:6:3
61+
popq %rbp
62+
.cfi_def_cfa %rsp, 8
63+
retq
64+
.Ltmp3:
65+
.Lfunc_end1:
66+
.size _Z12helperhelperv, .Lfunc_end1-_Z12helperhelperv
67+
.cfi_endproc
68+
# -- End function
69+
.section .text._Z13helperhelper2v,"ax",@progbits
70+
.globl _Z13helperhelper2v # -- Begin function _Z13helperhelper2v
71+
.p2align 4, 0x90
72+
.type _Z13helperhelper2v,@function
73+
_Z13helperhelper2v: # @_Z13helperhelper2v
74+
.Lfunc_begin2:
75+
.loc 0 8 0 is_stmt 1 # helper.cpp:8:0
76+
.cfi_startproc
77+
# %bb.0: # %entry
78+
pushq %rbp
79+
.cfi_def_cfa_offset 16
80+
.cfi_offset %rbp, -16
81+
movq %rsp, %rbp
82+
.cfi_def_cfa_register %rbp
83+
.Ltmp4:
84+
.loc 0 9 3 prologue_end # helper.cpp:9:3
85+
movl $1, %eax
86+
.loc 0 9 3 epilogue_begin is_stmt 0 # helper.cpp:9:3
87+
popq %rbp
88+
.cfi_def_cfa %rsp, 8
89+
retq
90+
.Ltmp5:
91+
.Lfunc_end2:
92+
.size _Z13helperhelper2v, .Lfunc_end2-_Z13helperhelper2v
93+
.cfi_endproc
94+
# -- End function
95+
.type Foo,@object # @Foo
96+
.bss
97+
.globl Foo
98+
.p2align 2, 0x0
99+
Foo:
100+
.long 0 # 0x0
101+
.size Foo, 4
102+
103+
.section .debug_abbrev,"",@progbits
104+
.byte 1 # Abbreviation Code
105+
.byte 17 # DW_TAG_compile_unit
106+
.byte 1 # DW_CHILDREN_yes
107+
.byte 37 # DW_AT_producer
108+
.byte 37 # DW_FORM_strx1
109+
.byte 19 # DW_AT_language
110+
.byte 5 # DW_FORM_data2
111+
.byte 3 # DW_AT_name
112+
.byte 37 # DW_FORM_strx1
113+
.byte 114 # DW_AT_str_offsets_base
114+
.byte 23 # DW_FORM_sec_offset
115+
.byte 16 # DW_AT_stmt_list
116+
.byte 23 # DW_FORM_sec_offset
117+
.byte 27 # DW_AT_comp_dir
118+
.byte 37 # DW_FORM_strx1
119+
.byte 17 # DW_AT_low_pc
120+
.byte 1 # DW_FORM_addr
121+
.byte 85 # DW_AT_ranges
122+
.byte 35 # DW_FORM_rnglistx
123+
.byte 115 # DW_AT_addr_base
124+
.byte 23 # DW_FORM_sec_offset
125+
.byte 116 # DW_AT_rnglists_base
126+
.byte 23 # DW_FORM_sec_offset
127+
.byte 0 # EOM(1)
128+
.byte 0 # EOM(2)
129+
.byte 2 # Abbreviation Code
130+
.byte 52 # DW_TAG_variable
131+
.byte 0 # DW_CHILDREN_no
132+
.byte 3 # DW_AT_name
133+
.byte 37 # DW_FORM_strx1
134+
.byte 73 # DW_AT_type
135+
.byte 19 # DW_FORM_ref4
136+
.byte 63 # DW_AT_external
137+
.byte 25 # DW_FORM_flag_present
138+
.byte 58 # DW_AT_decl_file
139+
.byte 11 # DW_FORM_data1
140+
.byte 59 # DW_AT_decl_line
141+
.byte 11 # DW_FORM_data1
142+
.byte 2 # DW_AT_location
143+
.byte 24 # DW_FORM_exprloc
144+
.byte 0 # EOM(1)
145+
.byte 0 # EOM(2)
146+
.byte 3 # Abbreviation Code
147+
.byte 36 # DW_TAG_base_type
148+
.byte 0 # DW_CHILDREN_no
149+
.byte 3 # DW_AT_name
150+
.byte 37 # DW_FORM_strx1
151+
.byte 62 # DW_AT_encoding
152+
.byte 11 # DW_FORM_data1
153+
.byte 11 # DW_AT_byte_size
154+
.byte 11 # DW_FORM_data1
155+
.byte 0 # EOM(1)
156+
.byte 0 # EOM(2)
157+
.byte 4 # Abbreviation Code
158+
.byte 46 # DW_TAG_subprogram
159+
.byte 0 # DW_CHILDREN_no
160+
.byte 17 # DW_AT_low_pc
161+
.byte 27 # DW_FORM_addrx
162+
.byte 18 # DW_AT_high_pc
163+
.byte 6 # DW_FORM_data4
164+
.byte 64 # DW_AT_frame_base
165+
.byte 24 # DW_FORM_exprloc
166+
.byte 110 # DW_AT_linkage_name
167+
.byte 37 # DW_FORM_strx1
168+
.byte 3 # DW_AT_name
169+
.byte 37 # DW_FORM_strx1
170+
.byte 58 # DW_AT_decl_file
171+
.byte 11 # DW_FORM_data1
172+
.byte 59 # DW_AT_decl_line
173+
.byte 11 # DW_FORM_data1
174+
.byte 73 # DW_AT_type
175+
.byte 19 # DW_FORM_ref4
176+
.byte 63 # DW_AT_external
177+
.byte 25 # DW_FORM_flag_present
178+
.byte 0 # EOM(1)
179+
.byte 0 # EOM(2)
180+
.byte 0 # EOM(3)
181+
.section .debug_info,"",@progbits
182+
.Lcu_begin0:
183+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
184+
.Ldebug_info_start0:
185+
.short 5 # DWARF version number
186+
.byte 1 # DWARF Unit Type
187+
.byte 8 # Address Size (in bytes)
188+
.long .debug_abbrev # Offset Into Abbrev. Section
189+
.byte 1 # Abbrev [1] 0xc:0x5f DW_TAG_compile_unit
190+
.byte 0 # DW_AT_producer
191+
.short 33 # DW_AT_language
192+
.byte 1 # DW_AT_name
193+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
194+
.long .Lline_table_start0 # DW_AT_stmt_list
195+
.byte 2 # DW_AT_comp_dir
196+
.quad 0 # DW_AT_low_pc
197+
.byte 0 # DW_AT_ranges
198+
.long .Laddr_table_base0 # DW_AT_addr_base
199+
.long .Lrnglists_table_base0 # DW_AT_rnglists_base
200+
.byte 2 # Abbrev [2] 0x2b:0xb DW_TAG_variable
201+
.byte 3 # DW_AT_name
202+
.long 54 # DW_AT_type
203+
# DW_AT_external
204+
.byte 0 # DW_AT_decl_file
205+
.byte 1 # DW_AT_decl_line
206+
.byte 2 # DW_AT_location
207+
.byte 161
208+
.byte 0
209+
.byte 3 # Abbrev [3] 0x36:0x4 DW_TAG_base_type
210+
.byte 4 # DW_AT_name
211+
.byte 5 # DW_AT_encoding
212+
.byte 4 # DW_AT_byte_size
213+
.byte 4 # Abbrev [4] 0x3a:0x10 DW_TAG_subprogram
214+
.byte 1 # DW_AT_low_pc
215+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
216+
.byte 1 # DW_AT_frame_base
217+
.byte 86
218+
.byte 5 # DW_AT_linkage_name
219+
.byte 6 # DW_AT_name
220+
.byte 0 # DW_AT_decl_file
221+
.byte 2 # DW_AT_decl_line
222+
.long 54 # DW_AT_type
223+
# DW_AT_external
224+
.byte 4 # Abbrev [4] 0x4a:0x10 DW_TAG_subprogram
225+
.byte 2 # DW_AT_low_pc
226+
.long .Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
227+
.byte 1 # DW_AT_frame_base
228+
.byte 86
229+
.byte 7 # DW_AT_linkage_name
230+
.byte 8 # DW_AT_name
231+
.byte 0 # DW_AT_decl_file
232+
.byte 5 # DW_AT_decl_line
233+
.long 54 # DW_AT_type
234+
# DW_AT_external
235+
.byte 4 # Abbrev [4] 0x5a:0x10 DW_TAG_subprogram
236+
.byte 3 # DW_AT_low_pc
237+
.long .Lfunc_end2-.Lfunc_begin2 # DW_AT_high_pc
238+
.byte 1 # DW_AT_frame_base
239+
.byte 86
240+
.byte 9 # DW_AT_linkage_name
241+
.byte 10 # DW_AT_name
242+
.byte 0 # DW_AT_decl_file
243+
.byte 8 # DW_AT_decl_line
244+
.long 54 # DW_AT_type
245+
# DW_AT_external
246+
.byte 0 # End Of Children Mark
247+
.Ldebug_info_end0:
248+
.section .debug_rnglists,"",@progbits
249+
.long .Ldebug_list_header_end0-.Ldebug_list_header_start0 # Length
250+
.Ldebug_list_header_start0:
251+
.short 5 # Version
252+
.byte 8 # Address size
253+
.byte 0 # Segment selector size
254+
.long 1 # Offset entry count
255+
.Lrnglists_table_base0:
256+
.long .Ldebug_ranges0-.Lrnglists_table_base0
257+
.Ldebug_ranges0:
258+
.byte 3 # DW_RLE_startx_length
259+
.byte 1 # start index
260+
.uleb128 .Lfunc_end0-.Lfunc_begin0 # length
261+
.byte 3 # DW_RLE_startx_length
262+
.byte 2 # start index
263+
.uleb128 .Lfunc_end1-.Lfunc_begin1 # length
264+
.byte 3 # DW_RLE_startx_length
265+
.byte 3 # start index
266+
.uleb128 .Lfunc_end2-.Lfunc_begin2 # length
267+
.byte 0 # DW_RLE_end_of_list
268+
.Ldebug_list_header_end0:
269+
.section .debug_str_offsets,"",@progbits
270+
.long 48 # Length of String Offsets Set
271+
.short 5
272+
.short 0
273+
.Lstr_offsets_base0:
274+
.section .debug_str,"MS",@progbits,1
275+
.Linfo_string0:
276+
.asciz "clang version 19.0.0git ([email protected]:ayermolo/llvm-project.git 6c884ef47e88e5ff18353819e806fe1b84e3c5b5)" # string offset=0
277+
.Linfo_string1:
278+
.asciz "helper.cpp" # string offset=108
279+
.Linfo_string2:
280+
.asciz "/repro2" # string offset=119
281+
.Linfo_string3:
282+
.asciz "Foo" # string offset=164
283+
.Linfo_string4:
284+
.asciz "int" # string offset=168
285+
.Linfo_string5:
286+
.asciz "_Z6helperv" # string offset=172
287+
.Linfo_string6:
288+
.asciz "helper" # string offset=183
289+
.Linfo_string7:
290+
.asciz "_Z12helperhelperv" # string offset=190
291+
.Linfo_string8:
292+
.asciz "helperhelper" # string offset=208
293+
.Linfo_string9:
294+
.asciz "_Z13helperhelper2v" # string offset=221
295+
.Linfo_string10:
296+
.asciz "helperhelper2" # string offset=240
297+
.section .debug_str_offsets,"",@progbits
298+
.long .Linfo_string0
299+
.long .Linfo_string1
300+
.long .Linfo_string2
301+
.long .Linfo_string3
302+
.long .Linfo_string4
303+
.long .Linfo_string5
304+
.long .Linfo_string6
305+
.long .Linfo_string7
306+
.long .Linfo_string8
307+
.long .Linfo_string9
308+
.long .Linfo_string10
309+
.section .debug_addr,"",@progbits
310+
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
311+
.Ldebug_addr_start0:
312+
.short 5 # DWARF version number
313+
.byte 8 # Address size
314+
.byte 0 # Segment selector size
315+
.Laddr_table_base0:
316+
.quad Foo
317+
.quad .Lfunc_begin0
318+
.quad .Lfunc_begin1
319+
.quad .Lfunc_begin2
320+
.Ldebug_addr_end0:
321+
.ident "clang version 19.0.0git ([email protected]:ayermolo/llvm-project.git 6c884ef47e88e5ff18353819e806fe1b84e3c5b5)"
322+
.section ".note.GNU-stack","",@progbits
323+
.addrsig
324+
.section .debug_line,"",@progbits
325+
.Lline_table_start0:

0 commit comments

Comments
 (0)