Skip to content

Commit 6d4aa9d

Browse files
authored
[BOLT][DWWARF] Fix foreign TU index with local TUs (llvm#84594)
The foreign TU list immediately follows the local TU list and they both use the same index, so that if there are N local TU entries, the index for the first foreign TU is N. Changed so that the size of local TU is accounted for when setting foreign TU index.
1 parent d1d80cc commit 6d4aa9d

5 files changed

+1196
-1
lines changed

bolt/lib/Core/DebugNames.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ void DWARF5AcceleratorTable::finalize() {
345345
std::optional<DWARF5AccelTable::UnitIndexAndEncoding>
346346
DWARF5AcceleratorTable::getIndexForEntry(
347347
const BOLTDWARF5AccelTableData &Value) const {
348+
// The foreign TU list immediately follows the local TU list and they both
349+
// use the same index, so that if there are N local TU entries, the index for
350+
// the first foreign TU is N.
348351
if (Value.isTU())
349-
return {{Value.getUnitID(), {dwarf::DW_IDX_type_unit, TUIndexForm}}};
352+
return {{(Value.getSecondUnitID() ? (unsigned)LocalTUList.size() : 0) +
353+
Value.getUnitID(),
354+
{dwarf::DW_IDX_type_unit, TUIndexForm}}};
350355
if (CUList.size() > 1)
351356
return {{Value.getUnitID(), {dwarf::DW_IDX_compile_unit, CUIndexForm}}};
352357
return std::nullopt;
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
# struct AMono {
2+
# int x;
3+
# };
4+
#
5+
# AMono globalMono;
6+
# # clang++ -g2 -gdwarf-5 -gpubnames -S -fdebug-types-section -o
7+
8+
.text
9+
.file "helper.cpp"
10+
.file 0 "/home" "helper.cpp" md5 0x3c0ac73d7b074961c6e8202230a76228
11+
.section .debug_info,"G",@progbits,6412503741467814911,comdat
12+
.Ltu_begin0:
13+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
14+
.Ldebug_info_start0:
15+
.short 5 # DWARF version number
16+
.byte 2 # DWARF Unit Type
17+
.byte 8 # Address Size (in bytes)
18+
.long .debug_abbrev # Offset Into Abbrev. Section
19+
.quad 6412503741467814911 # Type Signature
20+
.long 35 # Type DIE Offset
21+
.byte 1 # Abbrev [1] 0x18:0x20 DW_TAG_type_unit
22+
.short 33 # DW_AT_language
23+
.long .Lline_table_start0 # DW_AT_stmt_list
24+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
25+
.byte 2 # Abbrev [2] 0x23:0x10 DW_TAG_structure_type
26+
.byte 5 # DW_AT_calling_convention
27+
.byte 6 # DW_AT_name
28+
.byte 4 # DW_AT_byte_size
29+
.byte 0 # DW_AT_decl_file
30+
.byte 1 # DW_AT_decl_line
31+
.byte 3 # Abbrev [3] 0x29:0x9 DW_TAG_member
32+
.byte 4 # DW_AT_name
33+
.long 51 # DW_AT_type
34+
.byte 0 # DW_AT_decl_file
35+
.byte 2 # DW_AT_decl_line
36+
.byte 0 # DW_AT_data_member_location
37+
.byte 0 # End Of Children Mark
38+
.byte 4 # Abbrev [4] 0x33:0x4 DW_TAG_base_type
39+
.byte 5 # DW_AT_name
40+
.byte 5 # DW_AT_encoding
41+
.byte 4 # DW_AT_byte_size
42+
.byte 0 # End Of Children Mark
43+
.Ldebug_info_end0:
44+
.type globalMono,@object # @globalMono
45+
.bss
46+
.globl globalMono
47+
.p2align 2, 0x0
48+
globalMono:
49+
.zero 4
50+
.size globalMono, 4
51+
52+
.section .debug_abbrev,"",@progbits
53+
.byte 1 # Abbreviation Code
54+
.byte 65 # DW_TAG_type_unit
55+
.byte 1 # DW_CHILDREN_yes
56+
.byte 19 # DW_AT_language
57+
.byte 5 # DW_FORM_data2
58+
.byte 16 # DW_AT_stmt_list
59+
.byte 23 # DW_FORM_sec_offset
60+
.byte 114 # DW_AT_str_offsets_base
61+
.byte 23 # DW_FORM_sec_offset
62+
.byte 0 # EOM(1)
63+
.byte 0 # EOM(2)
64+
.byte 2 # Abbreviation Code
65+
.byte 19 # DW_TAG_structure_type
66+
.byte 1 # DW_CHILDREN_yes
67+
.byte 54 # DW_AT_calling_convention
68+
.byte 11 # DW_FORM_data1
69+
.byte 3 # DW_AT_name
70+
.byte 37 # DW_FORM_strx1
71+
.byte 11 # DW_AT_byte_size
72+
.byte 11 # DW_FORM_data1
73+
.byte 58 # DW_AT_decl_file
74+
.byte 11 # DW_FORM_data1
75+
.byte 59 # DW_AT_decl_line
76+
.byte 11 # DW_FORM_data1
77+
.byte 0 # EOM(1)
78+
.byte 0 # EOM(2)
79+
.byte 3 # Abbreviation Code
80+
.byte 13 # DW_TAG_member
81+
.byte 0 # DW_CHILDREN_no
82+
.byte 3 # DW_AT_name
83+
.byte 37 # DW_FORM_strx1
84+
.byte 73 # DW_AT_type
85+
.byte 19 # DW_FORM_ref4
86+
.byte 58 # DW_AT_decl_file
87+
.byte 11 # DW_FORM_data1
88+
.byte 59 # DW_AT_decl_line
89+
.byte 11 # DW_FORM_data1
90+
.byte 56 # DW_AT_data_member_location
91+
.byte 11 # DW_FORM_data1
92+
.byte 0 # EOM(1)
93+
.byte 0 # EOM(2)
94+
.byte 4 # Abbreviation Code
95+
.byte 36 # DW_TAG_base_type
96+
.byte 0 # DW_CHILDREN_no
97+
.byte 3 # DW_AT_name
98+
.byte 37 # DW_FORM_strx1
99+
.byte 62 # DW_AT_encoding
100+
.byte 11 # DW_FORM_data1
101+
.byte 11 # DW_AT_byte_size
102+
.byte 11 # DW_FORM_data1
103+
.byte 0 # EOM(1)
104+
.byte 0 # EOM(2)
105+
.byte 5 # Abbreviation Code
106+
.byte 17 # DW_TAG_compile_unit
107+
.byte 1 # DW_CHILDREN_yes
108+
.byte 37 # DW_AT_producer
109+
.byte 37 # DW_FORM_strx1
110+
.byte 19 # DW_AT_language
111+
.byte 5 # DW_FORM_data2
112+
.byte 3 # DW_AT_name
113+
.byte 37 # DW_FORM_strx1
114+
.byte 114 # DW_AT_str_offsets_base
115+
.byte 23 # DW_FORM_sec_offset
116+
.byte 16 # DW_AT_stmt_list
117+
.byte 23 # DW_FORM_sec_offset
118+
.byte 27 # DW_AT_comp_dir
119+
.byte 37 # DW_FORM_strx1
120+
.byte 115 # DW_AT_addr_base
121+
.byte 23 # DW_FORM_sec_offset
122+
.byte 0 # EOM(1)
123+
.byte 0 # EOM(2)
124+
.byte 6 # Abbreviation Code
125+
.byte 52 # DW_TAG_variable
126+
.byte 0 # DW_CHILDREN_no
127+
.byte 3 # DW_AT_name
128+
.byte 37 # DW_FORM_strx1
129+
.byte 73 # DW_AT_type
130+
.byte 19 # DW_FORM_ref4
131+
.byte 63 # DW_AT_external
132+
.byte 25 # DW_FORM_flag_present
133+
.byte 58 # DW_AT_decl_file
134+
.byte 11 # DW_FORM_data1
135+
.byte 59 # DW_AT_decl_line
136+
.byte 11 # DW_FORM_data1
137+
.byte 2 # DW_AT_location
138+
.byte 24 # DW_FORM_exprloc
139+
.byte 0 # EOM(1)
140+
.byte 0 # EOM(2)
141+
.byte 7 # Abbreviation Code
142+
.byte 19 # DW_TAG_structure_type
143+
.byte 0 # DW_CHILDREN_no
144+
.byte 60 # DW_AT_declaration
145+
.byte 25 # DW_FORM_flag_present
146+
.byte 105 # DW_AT_signature
147+
.byte 32 # DW_FORM_ref_sig8
148+
.byte 0 # EOM(1)
149+
.byte 0 # EOM(2)
150+
.byte 0 # EOM(3)
151+
.section .debug_info,"",@progbits
152+
.Lcu_begin0:
153+
.long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit
154+
.Ldebug_info_start1:
155+
.short 5 # DWARF version number
156+
.byte 1 # DWARF Unit Type
157+
.byte 8 # Address Size (in bytes)
158+
.long .debug_abbrev # Offset Into Abbrev. Section
159+
.byte 5 # Abbrev [5] 0xc:0x27 DW_TAG_compile_unit
160+
.byte 0 # DW_AT_producer
161+
.short 33 # DW_AT_language
162+
.byte 1 # DW_AT_name
163+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
164+
.long .Lline_table_start0 # DW_AT_stmt_list
165+
.byte 2 # DW_AT_comp_dir
166+
.long .Laddr_table_base0 # DW_AT_addr_base
167+
.byte 6 # Abbrev [6] 0x1e:0xb DW_TAG_variable
168+
.byte 3 # DW_AT_name
169+
.long 41 # DW_AT_type
170+
# DW_AT_external
171+
.byte 0 # DW_AT_decl_file
172+
.byte 5 # DW_AT_decl_line
173+
.byte 2 # DW_AT_location
174+
.byte 161
175+
.byte 0
176+
.byte 7 # Abbrev [7] 0x29:0x9 DW_TAG_structure_type
177+
# DW_AT_declaration
178+
.quad 6412503741467814911 # DW_AT_signature
179+
.byte 0 # End Of Children Mark
180+
.Ldebug_info_end1:
181+
.section .debug_str_offsets,"",@progbits
182+
.long 32 # Length of String Offsets Set
183+
.short 5
184+
.short 0
185+
.Lstr_offsets_base0:
186+
.section .debug_str,"MS",@progbits,1
187+
.Linfo_string0:
188+
.asciz "clang version 19.0.0git (git@github.com:llvm/llvm-project.git ced1fac8a32e35b63733bda27c7f5b9a2b635403)" # string offset=0
189+
.Linfo_string1:
190+
.asciz "helper.cpp" # string offset=104
191+
.Linfo_string2:
192+
.asciz "/home" # string offset=115
193+
.Linfo_string3:
194+
.asciz "globalMono" # string offset=153
195+
.Linfo_string4:
196+
.asciz "AMono" # string offset=164
197+
.Linfo_string5:
198+
.asciz "x" # string offset=170
199+
.Linfo_string6:
200+
.asciz "int" # string offset=172
201+
.section .debug_str_offsets,"",@progbits
202+
.long .Linfo_string0
203+
.long .Linfo_string1
204+
.long .Linfo_string2
205+
.long .Linfo_string3
206+
.long .Linfo_string5
207+
.long .Linfo_string6
208+
.long .Linfo_string4
209+
.section .debug_addr,"",@progbits
210+
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
211+
.Ldebug_addr_start0:
212+
.short 5 # DWARF version number
213+
.byte 8 # Address size
214+
.byte 0 # Segment selector size
215+
.Laddr_table_base0:
216+
.quad globalMono
217+
.Ldebug_addr_end0:
218+
.section .debug_names,"",@progbits
219+
.long .Lnames_end0-.Lnames_start0 # Header: unit length
220+
.Lnames_start0:
221+
.short 5 # Header: version
222+
.short 0 # Header: padding
223+
.long 1 # Header: compilation unit count
224+
.long 1 # Header: local type unit count
225+
.long 0 # Header: foreign type unit count
226+
.long 3 # Header: bucket count
227+
.long 3 # Header: name count
228+
.long .Lnames_abbrev_end0-.Lnames_abbrev_start0 # Header: abbreviation table size
229+
.long 8 # Header: augmentation string size
230+
.ascii "LLVM0700" # Header: augmentation string
231+
.long .Lcu_begin0 # Compilation unit 0
232+
.long .Ltu_begin0 # Type unit 0
233+
.long 0 # Bucket 0
234+
.long 0 # Bucket 1
235+
.long 1 # Bucket 2
236+
.long 193495088 # Hash in Bucket 2
237+
.long 253228319 # Hash in Bucket 2
238+
.long -857151761 # Hash in Bucket 2
239+
.long .Linfo_string6 # String in Bucket 2: int
240+
.long .Linfo_string4 # String in Bucket 2: AMono
241+
.long .Linfo_string3 # String in Bucket 2: globalMono
242+
.long .Lnames1-.Lnames_entries0 # Offset in Bucket 2
243+
.long .Lnames0-.Lnames_entries0 # Offset in Bucket 2
244+
.long .Lnames2-.Lnames_entries0 # Offset in Bucket 2
245+
.Lnames_abbrev_start0:
246+
.byte 1 # Abbrev code
247+
.byte 36 # DW_TAG_base_type
248+
.byte 2 # DW_IDX_type_unit
249+
.byte 11 # DW_FORM_data1
250+
.byte 3 # DW_IDX_die_offset
251+
.byte 19 # DW_FORM_ref4
252+
.byte 4 # DW_IDX_parent
253+
.byte 25 # DW_FORM_flag_present
254+
.byte 0 # End of abbrev
255+
.byte 0 # End of abbrev
256+
.byte 2 # Abbrev code
257+
.byte 19 # DW_TAG_structure_type
258+
.byte 2 # DW_IDX_type_unit
259+
.byte 11 # DW_FORM_data1
260+
.byte 3 # DW_IDX_die_offset
261+
.byte 19 # DW_FORM_ref4
262+
.byte 4 # DW_IDX_parent
263+
.byte 25 # DW_FORM_flag_present
264+
.byte 0 # End of abbrev
265+
.byte 0 # End of abbrev
266+
.byte 3 # Abbrev code
267+
.byte 19 # DW_TAG_structure_type
268+
.byte 3 # DW_IDX_die_offset
269+
.byte 19 # DW_FORM_ref4
270+
.byte 4 # DW_IDX_parent
271+
.byte 25 # DW_FORM_flag_present
272+
.byte 0 # End of abbrev
273+
.byte 0 # End of abbrev
274+
.byte 4 # Abbrev code
275+
.byte 52 # DW_TAG_variable
276+
.byte 3 # DW_IDX_die_offset
277+
.byte 19 # DW_FORM_ref4
278+
.byte 4 # DW_IDX_parent
279+
.byte 25 # DW_FORM_flag_present
280+
.byte 0 # End of abbrev
281+
.byte 0 # End of abbrev
282+
.byte 0 # End of abbrev list
283+
.Lnames_abbrev_end0:
284+
.Lnames_entries0:
285+
.Lnames1:
286+
.L1:
287+
.byte 1 # Abbreviation code
288+
.byte 0 # DW_IDX_type_unit
289+
.long 51 # DW_IDX_die_offset
290+
.byte 0 # DW_IDX_parent
291+
# End of list: int
292+
.Lnames0:
293+
.L2:
294+
.byte 2 # Abbreviation code
295+
.byte 0 # DW_IDX_type_unit
296+
.long 35 # DW_IDX_die_offset
297+
.L3: # DW_IDX_parent
298+
.byte 3 # Abbreviation code
299+
.long 41 # DW_IDX_die_offset
300+
.byte 0 # DW_IDX_parent
301+
# End of list: AMono
302+
.Lnames2:
303+
.L0:
304+
.byte 4 # Abbreviation code
305+
.long 30 # DW_IDX_die_offset
306+
.byte 0 # DW_IDX_parent
307+
# End of list: globalMono
308+
.p2align 2, 0x0
309+
.Lnames_end0:
310+
.ident "clang version 19.0.0git (git@github.com:llvm/llvm-project.git ced1fac8a32e35b63733bda27c7f5b9a2b635403)"
311+
.section ".note.GNU-stack","",@progbits
312+
.addrsig
313+
.section .debug_line,"",@progbits
314+
.Lline_table_start0:

0 commit comments

Comments
 (0)