From e9c58065939ce1b086fdcdc5e91a49cac3f38f95 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 12 Feb 2016 20:41:43 +0000 Subject: [PATCH] ELF: Remove use of MapVector from LinkerScript. We don't have to use a MapVector here. Instead, just std::vector suffices. llvm-svn: 260724 --- lld/ELF/Driver.cpp | 1 - lld/ELF/LinkerScript.cpp | 28 ++++++++++++---------------- lld/ELF/LinkerScript.h | 11 +++++------ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index ea27580..67b583a 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -296,7 +296,6 @@ template void LinkerDriver::link(opt::InputArgList &Args) { SymbolTable Symtab; std::unique_ptr TI(createTarget()); Target = TI.get(); - Script->finalize(); if (!Config->Shared) { // Add entry symbol. diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 4f39acb..1e0e855 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -28,27 +28,22 @@ using namespace lld::elf2; LinkerScript *elf2::Script; -void LinkerScript::finalize() { - for (const std::pair> &P : Sections) - for (StringRef S : P.second) - RevSections[S] = P.first; -} - StringRef LinkerScript::getOutputSection(StringRef S) { - return RevSections.lookup(S); + return Sections.lookup(S); } bool LinkerScript::isDiscarded(StringRef S) { - return RevSections.lookup(S) == "/DISCARD/"; + return Sections.lookup(S) == "/DISCARD/"; } +// A compartor to sort output sections. Returns -1 or 1 if both +// A and B are mentioned in linker scripts. Otherwise, returns 0 +// to use the default rule which is implemented in Writer.cpp. int LinkerScript::compareSections(StringRef A, StringRef B) { - auto I = Sections.find(A); - auto E = Sections.end(); - if (I == E) - return 0; - auto J = Sections.find(B); - if (J == E) + auto E = SectionOrder.end(); + auto I = std::find(SectionOrder.begin(), E, A); + auto J = std::find(SectionOrder.begin(), E, B); + if (I == E || J == E) return 0; return I < J ? -1 : 1; } @@ -349,14 +344,15 @@ void ScriptParser::readSections() { } void ScriptParser::readOutputSectionDescription() { - std::vector &V = Script->Sections[next()]; + StringRef OutSec = next(); + Script->SectionOrder.push_back(OutSec); expect(":"); expect("{"); while (!Error && !skip("}")) { next(); // Skip input file name. expect("("); while (!Error && !skip(")")) - V.push_back(next()); + Script->Sections[next()] = OutSec; } } diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 7eb0773..bdfcb7d 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -32,15 +32,14 @@ public: StringRef getOutputSection(StringRef InputSection); bool isDiscarded(StringRef InputSection); int compareSections(StringRef A, StringRef B); - void finalize(); private: - // Map for SECTIONS command. The key is output section name - // and a value is a list of input section names. - llvm::MapVector> Sections; + // A map for SECTIONS command. The key is input section name + // and the value is the corresponding output section name. + llvm::DenseMap Sections; - // Inverse map of Sections. - llvm::DenseMap RevSections; + // Output sections are sorted by this order. + std::vector SectionOrder; llvm::BumpPtrAllocator Alloc; }; -- 2.7.4