Skip to content

Commit c2bea66

Browse files
author
George Rimar
committed
[LLD][ELF] - Improve the DWARF v5 suport for building .gdb_index.
Now LLD might build the broken/incomplete .gdb_index when some DWARF v5 sections (like .debug_rnglists and .debug_addr) are used. Particularly, for the case above, we emit an empty address area. A test case is provided and patch fixes the issue. Differential revision: https://reviews.llvm.org/D55109 llvm-svn: 348119
1 parent 7304dd5 commit c2bea66

File tree

3 files changed

+214
-1
lines changed

3 files changed

+214
-1
lines changed

lld/ELF/DWARF.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {
3333

3434
if (LLDDWARFSection *M =
3535
StringSwitch<LLDDWARFSection *>(Sec->Name)
36+
.Case(".debug_addr", &AddrSection)
3637
.Case(".debug_gnu_pubnames", &GnuPubNamesSection)
3738
.Case(".debug_gnu_pubtypes", &GnuPubTypesSection)
3839
.Case(".debug_info", &InfoSection)
3940
.Case(".debug_ranges", &RangeSection)
41+
.Case(".debug_rnglists", &RngListsSection)
4042
.Case(".debug_line", &LineSection)
4143
.Default(nullptr)) {
4244
M->Data = toStringRef(Sec->data());

lld/ELF/DWARF.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
3737
return RangeSection;
3838
}
3939

40+
const llvm::DWARFSection &getRnglistsSection() const override {
41+
return RngListsSection;
42+
}
43+
4044
const llvm::DWARFSection &getLineSection() const override {
4145
return LineSection;
4246
}
4347

48+
const llvm::DWARFSection &getAddrSection() const override {
49+
return AddrSection;
50+
}
51+
4452
const llvm::DWARFSection &getGnuPubNamesSection() const override {
4553
return GnuPubNamesSection;
4654
}
@@ -71,8 +79,9 @@ template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
7179
LLDDWARFSection GnuPubTypesSection;
7280
LLDDWARFSection InfoSection;
7381
LLDDWARFSection RangeSection;
82+
LLDDWARFSection RngListsSection;
7483
LLDDWARFSection LineSection;
75-
84+
LLDDWARFSection AddrSection;
7685
StringRef AbbrevSection;
7786
StringRef StrSection;
7887
StringRef LineStringSection;

lld/test/ELF/gdb-index-rng-lists.s

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
3+
# RUN: ld.lld --gdb-index %t1.o -o %t
4+
# RUN: llvm-dwarfdump -gdb-index %t | FileCheck %s
5+
6+
## The code contains DWARF v5 sections .debug_rnglists and .debug_addr.
7+
## Check we are able to build the correct address
8+
## area using address range lists.
9+
10+
# CHECK: .gdb_index contents:
11+
# CHECK: Address area offset = 0x28, has 2 entries:
12+
# CHECK-NEXT: Low/High address = [0x201000, 0x201001) (Size: 0x1), CU id = 0
13+
# CHECK-NEXT: Low/High address = [0x201001, 0x201003) (Size: 0x2), CU id = 0
14+
15+
.text
16+
.section .text._Z3zedv,"ax",@progbits
17+
.Lfunc_begin0:
18+
retq
19+
.Lfunc_end0:
20+
21+
.section .text.main,"ax",@progbits
22+
.Lfunc_begin1:
23+
retq
24+
retq
25+
.Lfunc_end1:
26+
27+
.section .debug_str_offsets,"",@progbits
28+
.long 32
29+
.short 5
30+
.short 0
31+
.Lstr_offsets_base0:
32+
.long .Linfo_string0
33+
.long .Linfo_string0
34+
.long .Linfo_string0
35+
.long .Linfo_string0
36+
.long .Linfo_string0
37+
.long .Linfo_string0
38+
.long .Linfo_string0
39+
40+
.section .debug_str,"MS",@progbits,1
41+
.Linfo_string0:
42+
.asciz "stub"
43+
44+
.section .debug_abbrev,"",@progbits
45+
.byte 1 # Abbreviation Code
46+
.byte 17 # DW_TAG_compile_unit
47+
.byte 1 # DW_CHILDREN_yes
48+
.byte 37 # DW_AT_producer
49+
.byte 37 # DW_FORM_strx1
50+
.byte 19 # DW_AT_language
51+
.byte 5 # DW_FORM_data2
52+
.byte 3 # DW_AT_name
53+
.byte 37 # DW_FORM_strx1
54+
.byte 114 # DW_AT_str_offsets_base
55+
.byte 23 # DW_FORM_sec_offset
56+
.byte 16 # DW_AT_stmt_list
57+
.byte 23 # DW_FORM_sec_offset
58+
.byte 27 # DW_AT_comp_dir
59+
.byte 37 # DW_FORM_strx1
60+
.byte 115 # DW_AT_addr_base
61+
.byte 23 # DW_FORM_sec_offset
62+
.byte 17 # DW_AT_low_pc
63+
.byte 1 # DW_FORM_addr
64+
.byte 85 # DW_AT_ranges
65+
.byte 35 # DW_FORM_rnglistx
66+
.byte 116 # DW_AT_rnglists_base
67+
.byte 23 # DW_FORM_sec_offset
68+
.byte 0 # EOM(1)
69+
.byte 0 # EOM(2)
70+
.byte 2 # Abbreviation Code
71+
.byte 46 # DW_TAG_subprogram
72+
.byte 0 # DW_CHILDREN_no
73+
.byte 17 # DW_AT_low_pc
74+
.byte 27 # DW_FORM_addrx
75+
.byte 18 # DW_AT_high_pc
76+
.byte 6 # DW_FORM_data4
77+
.byte 64 # DW_AT_frame_base
78+
.byte 24 # DW_FORM_exprloc
79+
.byte 110 # DW_AT_linkage_name
80+
.byte 37 # DW_FORM_strx1
81+
.byte 3 # DW_AT_name
82+
.byte 37 # DW_FORM_strx1
83+
.byte 58 # DW_AT_decl_file
84+
.byte 11 # DW_FORM_data1
85+
.byte 59 # DW_AT_decl_line
86+
.byte 11 # DW_FORM_data1
87+
.byte 73 # DW_AT_type
88+
.byte 19 # DW_FORM_ref4
89+
.byte 63 # DW_AT_external
90+
.byte 25 # DW_FORM_flag_present
91+
.byte 0 # EOM(1)
92+
.byte 0 # EOM(2)
93+
.byte 3 # Abbreviation Code
94+
.byte 46 # DW_TAG_subprogram
95+
.byte 0 # DW_CHILDREN_no
96+
.byte 17 # DW_AT_low_pc
97+
.byte 27 # DW_FORM_addrx
98+
.byte 18 # DW_AT_high_pc
99+
.byte 6 # DW_FORM_data4
100+
.byte 64 # DW_AT_frame_base
101+
.byte 24 # DW_FORM_exprloc
102+
.byte 3 # DW_AT_name
103+
.byte 37 # DW_FORM_strx1
104+
.byte 58 # DW_AT_decl_file
105+
.byte 11 # DW_FORM_data1
106+
.byte 59 # DW_AT_decl_line
107+
.byte 11 # DW_FORM_data1
108+
.byte 73 # DW_AT_type
109+
.byte 19 # DW_FORM_ref4
110+
.byte 63 # DW_AT_external
111+
.byte 25 # DW_FORM_flag_present
112+
.byte 0 # EOM(1)
113+
.byte 0 # EOM(2)
114+
.byte 4 # Abbreviation Code
115+
.byte 36 # DW_TAG_base_type
116+
.byte 0 # DW_CHILDREN_no
117+
.byte 3 # DW_AT_name
118+
.byte 37 # DW_FORM_strx1
119+
.byte 62 # DW_AT_encoding
120+
.byte 11 # DW_FORM_data1
121+
.byte 11 # DW_AT_byte_size
122+
.byte 11 # DW_FORM_data1
123+
.byte 0 # EOM(1)
124+
.byte 0 # EOM(2)
125+
.byte 0 # EOM(3)
126+
127+
.section .debug_info,"",@progbits
128+
.Lcu_begin0:
129+
.long 75 # Length of Unit
130+
.short 5 # DWARF version number
131+
.byte 1 # DWARF Unit Type
132+
.byte 8 # Address Size (in bytes)
133+
.long .debug_abbrev # Offset Into Abbrev. Section
134+
135+
.byte 1 # Abbrev [1] 0xc:0x43 DW_TAG_compile_unit
136+
.byte 0 # DW_AT_producer
137+
.short 4 # DW_AT_language
138+
.byte 1 # DW_AT_name
139+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
140+
.long 0 # DW_AT_stmt_list
141+
.byte 2 # DW_AT_comp_dir
142+
.long .Laddr_table_base0 # DW_AT_addr_base
143+
.quad 0 # DW_AT_low_pc
144+
.byte 0 # DW_AT_ranges
145+
.long .Lrnglists_table_base0 # DW_AT_rnglists_base
146+
147+
.byte 2 # Abbrev [2] 0x2b:0x10 DW_TAG_subprogram
148+
.byte 0 # DW_AT_low_pc
149+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
150+
.byte 1 # DW_AT_frame_base
151+
.byte 86
152+
.byte 3 # DW_AT_linkage_name
153+
.byte 4 # DW_AT_name
154+
.byte 1 # DW_AT_decl_file
155+
.byte 1 # DW_AT_decl_line
156+
.long 74 # DW_AT_type
157+
# DW_AT_external
158+
159+
.byte 3 # Abbrev [3] 0x3b:0xf DW_TAG_subprogram
160+
.byte 1 # DW_AT_low_pc
161+
.long .Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
162+
.byte 1 # DW_AT_frame_base
163+
.byte 86
164+
.byte 6 # DW_AT_name
165+
.byte 1 # DW_AT_decl_file
166+
.byte 5 # DW_AT_decl_line
167+
.long 74 # DW_AT_type
168+
# DW_AT_external
169+
170+
.byte 4 # Abbrev [4] 0x4a:0x4 DW_TAG_base_type
171+
.byte 5 # DW_AT_name
172+
.byte 5 # DW_AT_encoding
173+
.byte 4 # DW_AT_byte_size
174+
.byte 0 # End Of Children Mark
175+
176+
.section .debug_rnglists,"",@progbits
177+
.long .Ldebug_rnglist_table_end0-.Ldebug_rnglist_table_start0 # Length
178+
.Ldebug_rnglist_table_start0:
179+
.short 5 # Version
180+
.byte 8 # Address size
181+
.byte 0 # Segment selector size
182+
.long 1 # Offset entry count
183+
.Lrnglists_table_base0:
184+
.long .Ldebug_ranges0-.Lrnglists_table_base0
185+
.Ldebug_ranges0:
186+
.byte 3 # DW_RLE_startx_length
187+
.byte 0 # start index
188+
.uleb128 .Lfunc_end0-.Lfunc_begin0 # length
189+
.byte 3 # DW_RLE_startx_length
190+
.byte 1 # start index
191+
.uleb128 .Lfunc_end1-.Lfunc_begin1 # length
192+
.byte 0 # DW_RLE_end_of_list
193+
.Ldebug_rnglist_table_end0:
194+
195+
.section .debug_addr,"",@progbits
196+
.long 20
197+
.short 5
198+
.byte 8
199+
.byte 0
200+
.Laddr_table_base0:
201+
.quad .Lfunc_begin0
202+
.quad .Lfunc_begin1

0 commit comments

Comments
 (0)