From 8a9bb7baeb40fff34c8ddd664bde351e7aa3ea0b Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 24 Jul 2016 02:05:09 +0000 Subject: [PATCH] Rollback r276538 and r276540 to unbreak asan bot. llvm-svn: 276543 --- lld/ELF/LinkerScript.cpp | 59 +++++++++++++++++------------------------------- lld/ELF/LinkerScript.h | 3 --- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 073832c..b95287a 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -261,15 +261,26 @@ std::vector *> LinkerScript::createSections(OutputSectionFactory &Factory) { typedef const std::unique_ptr> ObjectFile; std::vector *> Result; + DenseSet *> Removed; // Add input section to output section. If there is no output section yet, // then create it and add to output section list. - auto AddInputSec = [&](InputSectionBase *C, StringRef Name) { + auto AddInputSec = [&](InputSectionBase *C, StringRef Name, + ConstraintKind Constraint) { OutputSectionBase *Sec; bool IsNew; std::tie(Sec, IsNew) = Factory.create(C, Name); if (IsNew) Result.push_back(Sec); + if ((!(C->getSectionHdr()->sh_flags & SHF_WRITE)) && + Constraint == ReadWrite) { + Removed.insert(Sec); + return; + } + if ((C->getSectionHdr()->sh_flags & SHF_WRITE) && Constraint == ReadOnly) { + Removed.insert(Sec); + return; + } Sec->addSection(C); }; @@ -295,7 +306,7 @@ LinkerScript::createSections(OutputSectionFactory &Factory) { if (OutCmd->Name == "/DISCARD/") S->Live = false; else - AddInputSec(S, OutCmd->Name); + AddInputSec(S, OutCmd->Name, OutCmd->Constraint); } } } @@ -307,46 +318,18 @@ LinkerScript::createSections(OutputSectionFactory &Factory) { for (InputSectionBase *S : F->getSections()) { if (!isDiscarded(S)) { if (!S->OutSec) - AddInputSec(S, getOutputSectionName(S)); + AddInputSec(S, getOutputSectionName(S), NoConstraint); } else reportDiscarded(S, F); } - // Remove from the output all the sections which did not meet - // the optional constraints. - return filter(Result); -} - -// Process ONLY_IF_RO and ONLY_IF_RW. -template -std::vector *> -LinkerScript::filter(std::vector *> &Sections) { - // Sections and OutputSectionCommands are parallel arrays. - // In this loop, we remove output sections if they don't satisfy - // requested properties. - auto It = Sections.begin(); - for (const std::unique_ptr &Base : Opt.Commands) { - auto *Cmd = dyn_cast(Base.get()); - if (!Cmd) - continue; - - if (Cmd->Constraint == ConstraintKind::NoConstraint) { - ++It; - continue; - } - - OutputSectionBase *Sec = *It; - bool Writable = (Sec->getFlags() & SHF_WRITE); - bool RO = (Cmd->Constraint == ConstraintKind::ReadOnly); - bool RW = (Cmd->Constraint == ConstraintKind::ReadWrite); - - if ((RO && Writable) || (RW && !Writable)) { - Sections.erase(It); - continue; - } - ++It; - } - return Sections; + // Remove from the output all the sections which did not met the constraints. + Result.erase(std::remove_if(Result.begin(), Result.end(), + [&](OutputSectionBase *Sec) { + return Removed.count(Sec); + }), + Result.end()); + return Result; } template diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 1f6db34..7e9f157 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -130,9 +130,6 @@ private: // "ScriptConfig" is a bit too long, so define a short name for it. ScriptConfiguration &Opt = *ScriptConfig; - std::vector *> - filter(std::vector *> &Sections); - int getSectionIndex(StringRef Name); std::vector getPhdrIndicesForSection(StringRef Name); void dispatchAssignment(SymbolAssignment *Cmd); -- 2.7.4