Skip to content

Commit 3580ef1

Browse files
author
George Rimar
committedSep 15, 2017
[ELF] - Remove one of OutputSectionFactory::addInputSec().
Patch removes one of OutputSectionFactory::addInputSec methods. That allows to simplify reporting of discarded sections and should help to D37561. Differential revision: https://reviews.llvm.org/D37735 llvm-svn: 313361
1 parent 16807db commit 3580ef1

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed
 

‎lld/ELF/OutputSections.cpp

+46-40
Original file line numberDiff line numberDiff line change
@@ -205,46 +205,8 @@ void elf::reportDiscarded(InputSectionBase *IS) {
205205
IS->File->getName() + "'");
206206
}
207207

208-
void OutputSectionFactory::addInputSec(InputSectionBase *IS,
209-
StringRef OutsecName) {
210-
// Sections with the SHT_GROUP attribute reach here only when the - r option
211-
// is given. Such sections define "section groups", and InputFiles.cpp has
212-
// dedup'ed section groups by their signatures. For the -r, we want to pass
213-
// through all SHT_GROUP sections without merging them because merging them
214-
// creates broken section contents.
215-
if (IS->Type == SHT_GROUP) {
216-
OutputSection *Out = nullptr;
217-
addInputSec(IS, OutsecName, Out);
218-
return;
219-
}
220-
221-
// Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
222-
// relocation sections .rela.foo and .rela.bar for example. Most tools do
223-
// not allow multiple REL[A] sections for output section. Hence we
224-
// should combine these relocation sections into single output.
225-
// We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
226-
// other REL[A] sections created by linker itself.
227-
if (!isa<SyntheticSection>(IS) &&
228-
(IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
229-
auto *Sec = cast<InputSection>(IS);
230-
OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
231-
addInputSec(IS, OutsecName, Out->RelocationSection);
232-
return;
233-
}
234-
235-
SectionKey Key = createKey(IS, OutsecName);
236-
OutputSection *&Sec = Map[Key];
237-
addInputSec(IS, OutsecName, Sec);
238-
}
239-
240-
void OutputSectionFactory::addInputSec(InputSectionBase *IS,
241-
StringRef OutsecName,
242-
OutputSection *&Sec) {
243-
if (!IS->Live) {
244-
reportDiscarded(IS);
245-
return;
246-
}
247-
208+
static OutputSection *addSection(InputSectionBase *IS, StringRef OutsecName,
209+
OutputSection *Sec) {
248210
if (Sec && Sec->Live) {
249211
if (getIncompatibleFlags(Sec->Flags) != getIncompatibleFlags(IS->Flags))
250212
error("incompatible section flags for " + Sec->Name + "\n>>> " +
@@ -272,6 +234,50 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
272234
}
273235

274236
Sec->addSection(cast<InputSection>(IS));
237+
return Sec;
238+
}
239+
240+
void OutputSectionFactory::addInputSec(InputSectionBase *IS,
241+
StringRef OutsecName,
242+
OutputSection *OS) {
243+
if (!IS->Live) {
244+
reportDiscarded(IS);
245+
return;
246+
}
247+
248+
// If we have destination output section - use it directly.
249+
if (OS) {
250+
addSection(IS, OutsecName, OS);
251+
return;
252+
}
253+
254+
// Sections with the SHT_GROUP attribute reach here only when the - r option
255+
// is given. Such sections define "section groups", and InputFiles.cpp has
256+
// dedup'ed section groups by their signatures. For the -r, we want to pass
257+
// through all SHT_GROUP sections without merging them because merging them
258+
// creates broken section contents.
259+
if (IS->Type == SHT_GROUP) {
260+
addSection(IS, OutsecName, nullptr);
261+
return;
262+
}
263+
264+
// Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
265+
// relocation sections .rela.foo and .rela.bar for example. Most tools do
266+
// not allow multiple REL[A] sections for output section. Hence we
267+
// should combine these relocation sections into single output.
268+
// We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
269+
// other REL[A] sections created by linker itself.
270+
if (!isa<SyntheticSection>(IS) &&
271+
(IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
272+
auto *Sec = cast<InputSection>(IS);
273+
OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
274+
Out->RelocationSection = addSection(IS, OutsecName, Out->RelocationSection);
275+
return;
276+
}
277+
278+
SectionKey Key = createKey(IS, OutsecName);
279+
OutputSection *&Sec = Map[Key];
280+
Sec = addSection(IS, OutsecName, Sec);
275281
}
276282

277283
OutputSectionFactory::~OutputSectionFactory() {}

‎lld/ELF/OutputSections.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ class OutputSectionFactory {
161161
OutputSectionFactory();
162162
~OutputSectionFactory();
163163

164-
void addInputSec(InputSectionBase *IS, StringRef OutsecName);
165164
void addInputSec(InputSectionBase *IS, StringRef OutsecName,
166-
OutputSection *&Sec);
165+
OutputSection *OS = nullptr);
167166

168167
private:
169168
llvm::SmallDenseMap<SectionKey, OutputSection *> Map;

0 commit comments

Comments
 (0)
Please sign in to comment.