From: Rui Ueyama Date: Sun, 20 Nov 2016 23:15:52 +0000 (+0000) Subject: Add a flag to InputSectionBase for linker script. X-Git-Tag: llvmorg-4.0.0-rc1~4037 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f94efdddc0ae3f979ad8840ff1a53017548012a4;p=platform%2Fupstream%2Fllvm.git 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/InputSection.h b/lld/ELF/InputSection.h index 5b0c6fc..bb780fd 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -45,8 +45,8 @@ public: // If GC is disabled, all sections are considered live by default. InputSectionData(Kind SectionKind, StringRef Name, ArrayRef 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 Data; 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 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) { size_t SizeBefore = I->Sections.size(); for (InputSectionBase *S : Symtab::X->Sections) { - if (!S->Live || S->OutSec) + if (!S->Live || S->Assigned) continue; StringRef Filename; @@ -207,8 +207,10 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) { 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::computeInputSections(InputSectionDescription *I) { 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 *>(S); - S2->OutSec = (OutputSectionBase *)-1; - } } template @@ -263,12 +258,6 @@ LinkerScript::createInputSectionList(OutputSectionCommand &OutCmd) { Ret.push_back(static_cast *>(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 *S : Ret) - S->OutSec = nullptr; - return Ret; } @@ -343,7 +332,7 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) { if (!matchConstraints(V, Cmd->Constraint)) { for (InputSectionBase *S : V) - S->OutSec = nullptr; + S->Assigned = false; Opt.Commands.erase(Iter); --I; continue;