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.
llvm-svn: 287508
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 03a0349..388640c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -199,7 +199,7 @@
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 @@
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 @@
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 @@
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 @@
if (!matchConstraints<ELFT>(V, Cmd->Constraint)) {
for (InputSectionBase<ELFT> *S : V)
- S->OutSec = nullptr;
+ S->Assigned = false;
Opt.Commands.erase(Iter);
--I;
continue;