Skip to content

Commit 6d85c58

Browse files
author
George Rimar
committed
[llvm-dwarfdump] - Stop printing the bogus empty section name on invalid dwarf.
When there is no .debug_addr section for some reason, llvm-dwarfdump would print the bogus empty section name when dumping ranges in .debug_info: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000004 [0x0000000000000000, 0x0000000000000001) "" [0x0000000000000000, 0x0000000000000002) "") That happens because of the code which uses 0 (zero) as a section index as a default value. The code should use -1ULL instead because technically 0 is a valid zero section index in ELF and -1ULL is a special constant used that means "no section available". This is mostly a fix for the overall correctness/safety of the code, but a test case is provided too. Differential revision: https://reviews.llvm.org/D55113 llvm-svn: 348115
1 parent 4cf35b4 commit 6d85c58

File tree

2 files changed

+199
-2
lines changed

2 files changed

+199
-2
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDebugRnglists.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ DWARFDebugRnglist::getAbsoluteRanges(llvm::Optional<SectionedAddress> BaseAddr,
123123
if (RLE.EntryKind == dwarf::DW_RLE_base_addressx) {
124124
BaseAddr = U.getAddrOffsetSectionItem(RLE.Value0);
125125
if (!BaseAddr)
126-
BaseAddr = {RLE.Value0, 0};
126+
BaseAddr = {RLE.Value0, -1ULL};
127127
continue;
128128
}
129129
if (RLE.EntryKind == dwarf::DW_RLE_base_address) {
@@ -156,7 +156,7 @@ DWARFDebugRnglist::getAbsoluteRanges(llvm::Optional<SectionedAddress> BaseAddr,
156156
case dwarf::DW_RLE_startx_length: {
157157
auto Start = U.getAddrOffsetSectionItem(RLE.Value0);
158158
if (!Start)
159-
Start = {0, 0};
159+
Start = {0, -1ULL};
160160
E.SectionIndex = Start->SectionIndex;
161161
E.LowPC = Start->Address;
162162
E.HighPC = E.LowPC + RLE.Value1;
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# RUN: llvm-mc %s -filetype obj -triple=x86_64-pc-linux -o %t.o
2+
# RUN: llvm-dwarfdump -v %t.o | FileCheck %s
3+
4+
## When .debug_addr is absent for some reason,
5+
## check we do not print a bogus section name.
6+
7+
# CHECK: DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000004
8+
# CHECK-NEXT: [0x0000000000000000, 0x0000000000000001)
9+
# CHECK-NEXT: [0x0000000000000000, 0x0000000000000002)
10+
# CHECK-NEXT: [0x0000000000000003, 0x0000000000000004))
11+
12+
.text
13+
.section .text._Z3zedv,"ax",@progbits
14+
.Lfunc_begin0:
15+
retq
16+
.Lfunc_end0:
17+
18+
.section .text.main,"ax",@progbits
19+
.Lfunc_begin1:
20+
retq
21+
retq
22+
.Lfunc_end1:
23+
24+
.section .debug_str_offsets,"",@progbits
25+
.long 32
26+
.short 5
27+
.short 0
28+
.Lstr_offsets_base0:
29+
.long .Linfo_string0
30+
.long .Linfo_string0
31+
.long .Linfo_string0
32+
.long .Linfo_string0
33+
.long .Linfo_string0
34+
.long .Linfo_string0
35+
.long .Linfo_string0
36+
37+
.section .debug_str,"MS",@progbits,1
38+
.Linfo_string0:
39+
.asciz "stub"
40+
41+
.section .debug_abbrev,"",@progbits
42+
.byte 1 # Abbreviation Code
43+
.byte 17 # DW_TAG_compile_unit
44+
.byte 1 # DW_CHILDREN_yes
45+
.byte 37 # DW_AT_producer
46+
.byte 37 # DW_FORM_strx1
47+
.byte 19 # DW_AT_language
48+
.byte 5 # DW_FORM_data2
49+
.byte 3 # DW_AT_name
50+
.byte 37 # DW_FORM_strx1
51+
.byte 114 # DW_AT_str_offsets_base
52+
.byte 23 # DW_FORM_sec_offset
53+
.byte 16 # DW_AT_stmt_list
54+
.byte 23 # DW_FORM_sec_offset
55+
.byte 27 # DW_AT_comp_dir
56+
.byte 37 # DW_FORM_strx1
57+
.byte 115 # DW_AT_addr_base
58+
.byte 23 # DW_FORM_sec_offset
59+
.byte 17 # DW_AT_low_pc
60+
.byte 1 # DW_FORM_addr
61+
.byte 85 # DW_AT_ranges
62+
.byte 35 # DW_FORM_rnglistx
63+
.byte 116 # DW_AT_rnglists_base
64+
.byte 23 # DW_FORM_sec_offset
65+
.byte 0 # EOM(1)
66+
.byte 0 # EOM(2)
67+
.byte 2 # Abbreviation Code
68+
.byte 46 # DW_TAG_subprogram
69+
.byte 0 # DW_CHILDREN_no
70+
.byte 17 # DW_AT_low_pc
71+
.byte 27 # DW_FORM_addrx
72+
.byte 18 # DW_AT_high_pc
73+
.byte 6 # DW_FORM_data4
74+
.byte 64 # DW_AT_frame_base
75+
.byte 24 # DW_FORM_exprloc
76+
.byte 110 # DW_AT_linkage_name
77+
.byte 37 # DW_FORM_strx1
78+
.byte 3 # DW_AT_name
79+
.byte 37 # DW_FORM_strx1
80+
.byte 58 # DW_AT_decl_file
81+
.byte 11 # DW_FORM_data1
82+
.byte 59 # DW_AT_decl_line
83+
.byte 11 # DW_FORM_data1
84+
.byte 73 # DW_AT_type
85+
.byte 19 # DW_FORM_ref4
86+
.byte 63 # DW_AT_external
87+
.byte 25 # DW_FORM_flag_present
88+
.byte 0 # EOM(1)
89+
.byte 0 # EOM(2)
90+
.byte 3 # Abbreviation Code
91+
.byte 46 # DW_TAG_subprogram
92+
.byte 0 # DW_CHILDREN_no
93+
.byte 17 # DW_AT_low_pc
94+
.byte 27 # DW_FORM_addrx
95+
.byte 18 # DW_AT_high_pc
96+
.byte 6 # DW_FORM_data4
97+
.byte 64 # DW_AT_frame_base
98+
.byte 24 # DW_FORM_exprloc
99+
.byte 3 # DW_AT_name
100+
.byte 37 # DW_FORM_strx1
101+
.byte 58 # DW_AT_decl_file
102+
.byte 11 # DW_FORM_data1
103+
.byte 59 # DW_AT_decl_line
104+
.byte 11 # DW_FORM_data1
105+
.byte 73 # DW_AT_type
106+
.byte 19 # DW_FORM_ref4
107+
.byte 63 # DW_AT_external
108+
.byte 25 # DW_FORM_flag_present
109+
.byte 0 # EOM(1)
110+
.byte 0 # EOM(2)
111+
.byte 4 # Abbreviation Code
112+
.byte 36 # DW_TAG_base_type
113+
.byte 0 # DW_CHILDREN_no
114+
.byte 3 # DW_AT_name
115+
.byte 37 # DW_FORM_strx1
116+
.byte 62 # DW_AT_encoding
117+
.byte 11 # DW_FORM_data1
118+
.byte 11 # DW_AT_byte_size
119+
.byte 11 # DW_FORM_data1
120+
.byte 0 # EOM(1)
121+
.byte 0 # EOM(2)
122+
.byte 0 # EOM(3)
123+
124+
.section .debug_info,"",@progbits
125+
.Lcu_begin0:
126+
.long 75 # Length of Unit
127+
.short 5 # DWARF version number
128+
.byte 1 # DWARF Unit Type
129+
.byte 8 # Address Size (in bytes)
130+
.long .debug_abbrev # Offset Into Abbrev. Section
131+
132+
.byte 1 # Abbrev [1] 0xc:0x43 DW_TAG_compile_unit
133+
.byte 0 # DW_AT_producer
134+
.short 4 # DW_AT_language
135+
.byte 1 # DW_AT_name
136+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
137+
.long 0 # DW_AT_stmt_list
138+
.byte 2 # DW_AT_comp_dir
139+
.long 0 # DW_AT_addr_base
140+
.quad 0 # DW_AT_low_pc
141+
.byte 0 # DW_AT_ranges
142+
.long .Lrnglists_table_base0 # DW_AT_rnglists_base
143+
144+
.byte 2 # Abbrev [2] 0x2b:0x10 DW_TAG_subprogram
145+
.byte 0 # DW_AT_low_pc
146+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
147+
.byte 1 # DW_AT_frame_base
148+
.byte 86
149+
.byte 3 # DW_AT_linkage_name
150+
.byte 4 # DW_AT_name
151+
.byte 1 # DW_AT_decl_file
152+
.byte 1 # DW_AT_decl_line
153+
.long 74 # DW_AT_type
154+
# DW_AT_external
155+
156+
.byte 3 # Abbrev [3] 0x3b:0xf DW_TAG_subprogram
157+
.byte 1 # DW_AT_low_pc
158+
.long .Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
159+
.byte 1 # DW_AT_frame_base
160+
.byte 86
161+
.byte 6 # DW_AT_name
162+
.byte 1 # DW_AT_decl_file
163+
.byte 5 # DW_AT_decl_line
164+
.long 74 # DW_AT_type
165+
# DW_AT_external
166+
167+
.byte 4 # Abbrev [4] 0x4a:0x4 DW_TAG_base_type
168+
.byte 5 # DW_AT_name
169+
.byte 5 # DW_AT_encoding
170+
.byte 4 # DW_AT_byte_size
171+
.byte 0 # End Of Children Mark
172+
173+
.section .debug_rnglists,"",@progbits
174+
.long .Ldebug_rnglist_table_end0-.Ldebug_rnglist_table_start0 # Length
175+
.Ldebug_rnglist_table_start0:
176+
.short 5 # Version
177+
.byte 8 # Address size
178+
.byte 0 # Segment selector size
179+
.long 1 # Offset entry count
180+
.Lrnglists_table_base0:
181+
.long .Ldebug_ranges0-.Lrnglists_table_base0
182+
.Ldebug_ranges0:
183+
.byte 3 # DW_RLE_startx_length
184+
.byte 0 # start index
185+
.uleb128 .Lfunc_end0-.Lfunc_begin0 # length
186+
.byte 3 # DW_RLE_startx_length
187+
.byte 1 # start index
188+
.uleb128 .Lfunc_end1-.Lfunc_begin1 # length
189+
190+
.byte 1 # DW_RLE_base_addressx
191+
.byte 0 # Base address (index 0 in .debug_addr)
192+
.byte 4 # DW_RLE_offset_pair
193+
.byte 0x3 # Start offset
194+
.byte 0x4 # End offset
195+
196+
.byte 0 # DW_RLE_end_of_list
197+
.Ldebug_rnglist_table_end0:

0 commit comments

Comments
 (0)