Skip to content

Commit 57aeb30

Browse files
committed
[JITLink][ELF] Don't skip debug info sections by default.
By default ELFLinkGraphBuilder will now create LinkGraph sections with NoAlloc lifetime for debug info sections in the original object. Debug sections are not kept alive by default, and will be dead-stripped unless some plugin marks them as live in the pre-prune phase.
1 parent ede78c1 commit 57aeb30

File tree

3 files changed

+213
-258
lines changed

3 files changed

+213
-258
lines changed

llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ class ELFLinkGraphBuilder : public ELFLinkGraphBuilderBase {
6262
StringRef FileName,
6363
LinkGraph::GetEdgeKindNameFunction GetEdgeKindName);
6464

65+
/// Debug sections are included in the graph by default. Use
66+
/// setProcessDebugSections(false) to ignore them if debug info is not
67+
/// needed.
68+
ELFLinkGraphBuilder &setProcessDebugSections(bool ProcessDebugSections) {
69+
this->ProcessDebugSections = ProcessDebugSections;
70+
return *this;
71+
}
72+
6573
/// Attempt to construct and return the LinkGraph.
6674
Expected<std::unique_ptr<LinkGraph>> buildGraph();
6775

@@ -115,8 +123,7 @@ class ELFLinkGraphBuilder : public ELFLinkGraphBuilderBase {
115123
///
116124
template <typename RelocHandlerMethod>
117125
Error forEachRelaRelocation(const typename ELFT::Shdr &RelSect,
118-
RelocHandlerMethod &&Func,
119-
bool ProcessDebugSections = false);
126+
RelocHandlerMethod &&Func);
120127

121128
/// Traverse all matching ELFT::Rel relocation records in the given section.
122129
/// The handler function Func should be callable with this signature:
@@ -125,44 +132,40 @@ class ELFLinkGraphBuilder : public ELFLinkGraphBuilderBase {
125132
///
126133
template <typename RelocHandlerMethod>
127134
Error forEachRelRelocation(const typename ELFT::Shdr &RelSect,
128-
RelocHandlerMethod &&Func,
129-
bool ProcessDebugSections = false);
135+
RelocHandlerMethod &&Func);
130136

131137
/// Traverse all matching rela relocation records in the given section.
132138
/// Convenience wrapper to allow passing a member function for the handler.
133139
///
134140
template <typename ClassT, typename RelocHandlerMethod>
135141
Error forEachRelaRelocation(const typename ELFT::Shdr &RelSect,
136-
ClassT *Instance, RelocHandlerMethod &&Method,
137-
bool ProcessDebugSections = false) {
142+
ClassT *Instance, RelocHandlerMethod &&Method) {
138143
return forEachRelaRelocation(
139144
RelSect,
140145
[Instance, Method](const auto &Rel, const auto &Target, auto &GS) {
141146
return (Instance->*Method)(Rel, Target, GS);
142-
},
143-
ProcessDebugSections);
147+
});
144148
}
145149

146150
/// Traverse all matching rel relocation records in the given section.
147151
/// Convenience wrapper to allow passing a member function for the handler.
148152
///
149153
template <typename ClassT, typename RelocHandlerMethod>
150154
Error forEachRelRelocation(const typename ELFT::Shdr &RelSect,
151-
ClassT *Instance, RelocHandlerMethod &&Method,
152-
bool ProcessDebugSections = false) {
155+
ClassT *Instance, RelocHandlerMethod &&Method) {
153156
return forEachRelRelocation(
154157
RelSect,
155158
[Instance, Method](const auto &Rel, const auto &Target, auto &GS) {
156159
return (Instance->*Method)(Rel, Target, GS);
157-
},
158-
ProcessDebugSections);
160+
});
159161
}
160162

161163
const ELFFile &Obj;
162164

163165
typename ELFFile::Elf_Shdr_Range Sections;
164166
const typename ELFFile::Elf_Shdr *SymTabSec = nullptr;
165167
StringRef SectionStringTab;
168+
bool ProcessDebugSections = true;
166169

167170
// Maps ELF section indexes to LinkGraph Blocks.
168171
// Only SHF_ALLOC sections will have graph blocks.
@@ -318,7 +321,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
318321

319322
// If the name indicates that it's a debug section then skip it: We don't
320323
// support those yet.
321-
if (isDwarfSection(*Name)) {
324+
if (!ProcessDebugSections && isDwarfSection(*Name)) {
322325
LLVM_DEBUG({
323326
dbgs() << " " << SecIndex << ": \"" << *Name
324327
<< "\" is a debug section: "
@@ -522,8 +525,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
522525
template <typename ELFT>
523526
template <typename RelocHandlerFunction>
524527
Error ELFLinkGraphBuilder<ELFT>::forEachRelaRelocation(
525-
const typename ELFT::Shdr &RelSect, RelocHandlerFunction &&Func,
526-
bool ProcessDebugSections) {
528+
const typename ELFT::Shdr &RelSect, RelocHandlerFunction &&Func) {
527529
// Only look into sections that store relocation entries.
528530
if (RelSect.sh_type != ELF::SHT_RELA)
529531
return Error::success();
@@ -569,8 +571,7 @@ Error ELFLinkGraphBuilder<ELFT>::forEachRelaRelocation(
569571
template <typename ELFT>
570572
template <typename RelocHandlerFunction>
571573
Error ELFLinkGraphBuilder<ELFT>::forEachRelRelocation(
572-
const typename ELFT::Shdr &RelSect, RelocHandlerFunction &&Func,
573-
bool ProcessDebugSections) {
574+
const typename ELFT::Shdr &RelSect, RelocHandlerFunction &&Func) {
574575
// Only look into sections that store relocation entries.
575576
if (RelSect.sh_type != ELF::SHT_REL)
576577
return Error::success();
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# REQUIRES: asserts
2+
# RUN: yaml2obj -o %t.o %s
3+
# RUN: llvm-jitlink -debug-only=jitlink -noexec %t.o 2>&1 | FileCheck %s
4+
#
5+
# Check that debug sections get NoAlloc lifetimes.
6+
#
7+
# CHECK: ".debug_str" is not a SHF_ALLOC section. Using NoAlloc lifetime.
8+
# CHECK: ".debug_abbrev" is not a SHF_ALLOC section. Using NoAlloc lifetime.
9+
# CHECK: ".debug_info" is not a SHF_ALLOC section. Using NoAlloc lifetime.
10+
# CHECK: ".debug_line" is not a SHF_ALLOC section. Using NoAlloc lifetime.
11+
12+
13+
--- !ELF
14+
FileHeader:
15+
Class: ELFCLASS64
16+
Data: ELFDATA2LSB
17+
Type: ET_REL
18+
Machine: EM_X86_64
19+
SectionHeaderStringTable: .strtab
20+
Sections:
21+
- Name: .text
22+
Type: SHT_PROGBITS
23+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
24+
AddressAlign: 0x10
25+
Content: B82A000000C3662E0F1F840000000000B82A000000C3
26+
- Name: .debug_abbrev
27+
Type: SHT_PROGBITS
28+
AddressAlign: 0x1
29+
Content: 011101250E1305030E10171B0E110112060000022E00110112064018974219030E3A0B3B0B271949133F190000032E01110112064018974219030E3A0B3B0B271949133F1900000405000218030E3A0B3B0B49130000052400030E3E0B0B0B0000060F004913000000
30+
- Name: .debug_info
31+
Type: SHT_PROGBITS
32+
AddressAlign: 0x1
33+
Content: 8C0000000400000000000801000000000C000000000000000000000000000000000000000000160000000200000000000000000600000001570000000001017700000003000000000000000006000000015700000000010577000000040155000000000105770000000401540000000001057E0000000005000000000504068300000006880000000500000000060100
34+
- Name: .comment
35+
Type: SHT_PROGBITS
36+
Flags: [ SHF_MERGE, SHF_STRINGS ]
37+
AddressAlign: 0x1
38+
EntSize: 0x1
39+
Content: 00636C616E672076657273696F6E2031302E302E302D347562756E7475312000
40+
- Name: .note.GNU-stack
41+
Type: SHT_PROGBITS
42+
AddressAlign: 0x1
43+
- Name: .debug_line
44+
Type: SHT_PROGBITS
45+
AddressAlign: 0x1
46+
Content: 58000000040036000000010101FB0E0D0001010101000000010000012F746D700000454C465F736B69705F64656275675F73656374696F6E732E63000100000000090200000000000000000105030A130500F505030A130206000101
47+
- Name: .eh_frame
48+
Type: SHT_X86_64_UNWIND
49+
Flags: [ SHF_ALLOC ]
50+
AddressAlign: 0x8
51+
Content: 1400000000000000017A5200017810011B0C070890010000100000001C0000000000000006000000000000001000000030000000000000000600000000000000
52+
- Name: .rela.debug_info
53+
Type: SHT_RELA
54+
Flags: [ SHF_INFO_LINK ]
55+
Link: .symtab
56+
AddressAlign: 0x8
57+
Info: .debug_info
58+
Relocations:
59+
- Offset: 0x6
60+
Symbol: .debug_abbrev
61+
Type: R_X86_64_32
62+
- Offset: 0xC
63+
Symbol: .debug_str
64+
Type: R_X86_64_32
65+
- Offset: 0x12
66+
Symbol: .debug_str
67+
Type: R_X86_64_32
68+
Addend: 31
69+
- Offset: 0x16
70+
Symbol: .debug_line
71+
Type: R_X86_64_32
72+
- Offset: 0x1A
73+
Symbol: .debug_str
74+
Type: R_X86_64_32
75+
Addend: 57
76+
- Offset: 0x1E
77+
Symbol: .text
78+
Type: R_X86_64_64
79+
- Offset: 0x2B
80+
Symbol: .text
81+
Type: R_X86_64_64
82+
- Offset: 0x39
83+
Symbol: .debug_str
84+
Type: R_X86_64_32
85+
Addend: 62
86+
- Offset: 0x44
87+
Symbol: .text
88+
Type: R_X86_64_64
89+
Addend: 16
90+
- Offset: 0x52
91+
Symbol: .debug_str
92+
Type: R_X86_64_32
93+
Addend: 70
94+
- Offset: 0x5F
95+
Symbol: .debug_str
96+
Type: R_X86_64_32
97+
Addend: 75
98+
- Offset: 0x6C
99+
Symbol: .debug_str
100+
Type: R_X86_64_32
101+
Addend: 80
102+
- Offset: 0x78
103+
Symbol: .debug_str
104+
Type: R_X86_64_32
105+
Addend: 66
106+
- Offset: 0x89
107+
Symbol: .debug_str
108+
Type: R_X86_64_32
109+
Addend: 85
110+
- Name: .rela.debug_line
111+
Type: SHT_RELA
112+
Flags: [ SHF_INFO_LINK ]
113+
Link: .symtab
114+
AddressAlign: 0x8
115+
Info: .debug_line
116+
Relocations:
117+
- Offset: 0x43
118+
Symbol: .text
119+
Type: R_X86_64_64
120+
- Name: .rela.eh_frame
121+
Type: SHT_RELA
122+
Flags: [ SHF_INFO_LINK ]
123+
Link: .symtab
124+
AddressAlign: 0x8
125+
Info: .eh_frame
126+
Relocations:
127+
- Offset: 0x20
128+
Symbol: .text
129+
Type: R_X86_64_PC32
130+
- Offset: 0x34
131+
Symbol: .text
132+
Type: R_X86_64_PC32
133+
Addend: 16
134+
- Name: .llvm_addrsig
135+
Type: SHT_LLVM_ADDRSIG
136+
Flags: [ SHF_EXCLUDE ]
137+
Link: .symtab
138+
AddressAlign: 0x1
139+
Offset: 0x4C0
140+
Symbols: [ ]
141+
- Type: SectionHeaderTable
142+
Sections:
143+
- Name: .strtab
144+
- Name: .text
145+
- Name: .debug_str
146+
- Name: .debug_abbrev
147+
- Name: .debug_info
148+
- Name: .rela.debug_info
149+
- Name: .comment
150+
- Name: .note.GNU-stack
151+
- Name: .debug_line
152+
- Name: .rela.debug_line
153+
- Name: .eh_frame
154+
- Name: .rela.eh_frame
155+
- Name: .llvm_addrsig
156+
- Name: .symtab
157+
Symbols:
158+
- Name: ELF_skip_debug_sections.c
159+
Type: STT_FILE
160+
Index: SHN_ABS
161+
- Name: .text
162+
Type: STT_SECTION
163+
Section: .text
164+
- Name: .debug_str
165+
Type: STT_SECTION
166+
Section: .debug_str
167+
- Name: .debug_abbrev
168+
Type: STT_SECTION
169+
Section: .debug_abbrev
170+
- Name: .debug_line
171+
Type: STT_SECTION
172+
Section: .debug_line
173+
- Name: foo
174+
Type: STT_FUNC
175+
Section: .text
176+
Binding: STB_GLOBAL
177+
Size: 0x6
178+
- Name: main
179+
Type: STT_FUNC
180+
Section: .text
181+
Binding: STB_GLOBAL
182+
Value: 0x10
183+
Size: 0x6
184+
DWARF:
185+
debug_str:
186+
- 'clang version 10.0.0-4ubuntu1 '
187+
- ELF_skip_debug_sections.c
188+
- '/tmp'
189+
- foo
190+
- int
191+
- main
192+
- argc
193+
- argv
194+
- char
195+
...

0 commit comments

Comments
 (0)