From 849d499e6d402f33c3e8e579476c3604d4cb1350 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 21 Oct 2017 00:05:01 +0000 Subject: [PATCH] Don't call buildSectionOrder multiple times. This takes linking the linux kernel from 1.52s to 0.58s. llvm-svn: 316251 --- lld/ELF/InputSection.cpp | 5 ++++- lld/ELF/LinkerScript.cpp | 13 +++++++------ lld/ELF/LinkerScript.h | 7 +++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 4593cc4..35f4df4 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -46,6 +46,10 @@ std::string lld::toString(const InputSectionBase *Sec) { } DenseMap elf::buildSectionOrder() { + DenseMap SectionOrder; + if (Config->SymbolOrderingFile.empty()) + return SectionOrder; + // Build a map from symbols to their priorities. Symbols that didn't // appear in the symbol ordering file have the lowest priority 0. // All explicitly mentioned symbols have negative (higher) priorities. @@ -55,7 +59,6 @@ DenseMap elf::buildSectionOrder() { SymbolOrder.insert({S, Priority++}); // Build a map from sections to their priorities. - DenseMap SectionOrder; for (InputFile *File : ObjectFiles) { for (SymbolBody *Body : File->getSymbols()) { auto *D = dyn_cast(Body); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index b75802f..31fe3b9 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -274,9 +274,9 @@ static void sortInputSections( // Compute and remember which sections the InputSectionDescription matches. std::vector -LinkerScript::computeInputSections(const InputSectionDescription *Cmd) { +LinkerScript::computeInputSections(const InputSectionDescription *Cmd, + const DenseMap &Order) { std::vector Ret; - DenseMap Order = buildSectionOrder(); // Collects all sections that satisfy constraints of Cmd. for (const SectionPattern &Pat : Cmd->SectionPatterns) { @@ -326,13 +326,13 @@ void LinkerScript::discard(ArrayRef V) { } } -std::vector -LinkerScript::createInputSectionList(OutputSection &OutCmd) { +std::vector LinkerScript::createInputSectionList( + OutputSection &OutCmd, const DenseMap &Order) { std::vector Ret; for (BaseCommand *Base : OutCmd.SectionCommands) { if (auto *Cmd = dyn_cast(Base)) { - Cmd->Sections = computeInputSections(Cmd); + Cmd->Sections = computeInputSections(Cmd, Order); Ret.insert(Ret.end(), Cmd->Sections.begin(), Cmd->Sections.end()); } } @@ -359,6 +359,7 @@ void LinkerScript::processSectionCommands() { Ctx = make_unique(); Ctx->OutSec = Aether; + DenseMap Order = buildSectionOrder(); // Add input sections to output sections. for (size_t I = 0; I < SectionCommands.size(); ++I) { // Handle symbol assignments outside of any output section. @@ -368,7 +369,7 @@ void LinkerScript::processSectionCommands() { } if (auto *Sec = dyn_cast(SectionCommands[I])) { - std::vector V = createInputSectionList(*Sec); + std::vector V = createInputSectionList(*Sec, Order); // The output section name `/DISCARD/' is special. // Any input section assigned to it is discarded. diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 03c8392..1afb27c 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -205,9 +205,12 @@ class LinkerScript final { void setDot(Expr E, const Twine &Loc, bool InSec); std::vector - computeInputSections(const InputSectionDescription *); + computeInputSections(const InputSectionDescription *, + const llvm::DenseMap &Order); - std::vector createInputSectionList(OutputSection &Cmd); + std::vector + createInputSectionList(OutputSection &Cmd, + const llvm::DenseMap &Order); std::vector getPhdrIndices(OutputSection *Sec); -- 2.7.4