ELF: Remove use of MapVector from LinkerScript.

We don't have to use a MapVector here. Instead, just std::vector suffices.

llvm-svn: 260724
This commit is contained in:
Rui Ueyama 2016-02-12 20:41:43 +00:00
parent 232f447782
commit e9c5806593
3 changed files with 17 additions and 23 deletions

View File

@ -296,7 +296,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
SymbolTable<ELFT> Symtab;
std::unique_ptr<TargetInfo> TI(createTarget());
Target = TI.get();
Script->finalize();
if (!Config->Shared) {
// Add entry symbol.

View File

@ -28,27 +28,22 @@ using namespace lld::elf2;
LinkerScript *elf2::Script;
void LinkerScript::finalize() {
for (const std::pair<StringRef, std::vector<StringRef>> &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<StringRef> &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;
}
}

View File

@ -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<StringRef, std::vector<StringRef>> Sections;
// A map for SECTIONS command. The key is input section name
// and the value is the corresponding output section name.
llvm::DenseMap<StringRef, StringRef> Sections;
// Inverse map of Sections.
llvm::DenseMap<StringRef, StringRef> RevSections;
// Output sections are sorted by this order.
std::vector<StringRef> SectionOrder;
llvm::BumpPtrAllocator Alloc;
};