[lld] r287508 - Add a flag to InputSectionBase for linker script.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 20 15:15:53 PST 2016
Author: ruiu
Date: Sun Nov 20 17:15:52 2016
New Revision: 287508
URL: http://llvm.org/viewvc/llvm-project?rev=287508&view=rev
Log:
Add a flag to InputSectionBase for linker script.
Previously, we set (uintptr_t)-1 to InputSectionBase::OutSec to record
that a section has already been set to be assigned to some output section
by linker scripts. Later, we restored nullptr to the pointer to use
the field for the original purpose. That overloading is not very easy to
understand.
This patch adds a bit flag for that purpose, so that we don't need
to piggyback the flag on an unrelated pointer.
Modified:
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=287508&r1=287507&r2=287508&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sun Nov 20 17:15:52 2016
@@ -45,8 +45,8 @@ public:
// If GC is disabled, all sections are considered live by default.
InputSectionData(Kind SectionKind, StringRef Name, ArrayRef<uint8_t> Data,
bool Compressed, bool Live)
- : SectionKind(SectionKind), Live(Live), Compressed(Compressed),
- Name(Name), Data(Data) {}
+ : SectionKind(SectionKind), Live(Live), Assigned(false),
+ Compressed(Compressed), Name(Name), Data(Data) {}
private:
unsigned SectionKind : 3;
@@ -54,8 +54,9 @@ private:
public:
Kind kind() const { return (Kind)SectionKind; }
- unsigned Live : 1; // for garbage collection
- unsigned Compressed : 1;
+ unsigned Live : 1; // for garbage collection
+ unsigned Assigned : 1; // for linker script
+ unsigned Compressed : 1; // true if section data is compressed
uint32_t Alignment;
StringRef Name;
ArrayRef<uint8_t> Data;
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=287508&r1=287507&r2=287508&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sun Nov 20 17:15:52 2016
@@ -199,7 +199,7 @@ void LinkerScript<ELFT>::computeInputSec
size_t SizeBefore = I->Sections.size();
for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections) {
- if (!S->Live || S->OutSec)
+ if (!S->Live || S->Assigned)
continue;
StringRef Filename;
@@ -207,8 +207,10 @@ void LinkerScript<ELFT>::computeInputSec
Filename = sys::path::filename(F->getName());
if (I->FilePat.match(Filename) && !Pat.ExcludedFilePat.match(Filename) &&
- Pat.SectionPat.match(S->Name))
+ Pat.SectionPat.match(S->Name)) {
I->Sections.push_back(S);
+ S->Assigned = true;
+ }
}
// Sort sections as instructed by SORT-family commands and --sort-section
@@ -232,13 +234,6 @@ void LinkerScript<ELFT>::computeInputSec
sortSections(Begin, End, Pat.SortOuter);
}
}
-
- // We do not add duplicate input sections, so mark them with a dummy output
- // section for now.
- for (InputSectionData *S : I->Sections) {
- auto *S2 = static_cast<InputSectionBase<ELFT> *>(S);
- S2->OutSec = (OutputSectionBase *)-1;
- }
}
template <class ELFT>
@@ -263,12 +258,6 @@ LinkerScript<ELFT>::createInputSectionLi
Ret.push_back(static_cast<InputSectionBase<ELFT> *>(S));
}
- // After we created final list we should now set OutSec pointer to null,
- // instead of -1. Otherwise we may get a crash when writing relocs, in
- // case section is discarded by linker script
- for (InputSectionBase<ELFT> *S : Ret)
- S->OutSec = nullptr;
-
return Ret;
}
@@ -343,7 +332,7 @@ void LinkerScript<ELFT>::processCommands
if (!matchConstraints<ELFT>(V, Cmd->Constraint)) {
for (InputSectionBase<ELFT> *S : V)
- S->OutSec = nullptr;
+ S->Assigned = false;
Opt.Commands.erase(Iter);
--I;
continue;
More information about the llvm-commits
mailing list