From 9b9800951da1c342223bd174dc1fcd441b6061b7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 6 Apr 2017 21:05:39 +0000 Subject: [PATCH] Cache the result of findSection. This avoids calling it multiple times. In particular, we don't have to call in in assignAddresses any more. llvm-svn: 299709 --- lld/ELF/LinkerScript.cpp | 10 +++++++--- lld/ELF/LinkerScript.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9e39a5de32e7..c7a8a056a841 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -567,7 +567,7 @@ MemoryRegion *LinkerScript::findMemoryRegion(OutputSectionCommand *Cmd, // This function assigns offsets to input sections and an output section // for a single sections command (e.g. ".text { *(.text); }"). void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) { - OutputSection *Sec = findSection(Cmd->Name, *OutputSections); + OutputSection *Sec = Cmd->Sec; if (!Sec) return; @@ -614,7 +614,7 @@ void LinkerScript::removeEmptyCommands() { auto Pos = std::remove_if( Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) { if (auto *Cmd = dyn_cast(Base)) - return !findSection(Cmd->Name, *OutputSections); + return !Cmd->Sec; return false; }); Opt.Commands.erase(Pos, Opt.Commands.end()); @@ -639,6 +639,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { if (!Cmd) continue; if (OutputSection *Sec = findSection(Cmd->Name, *OutputSections)) { + Cmd->Sec = Sec; Flags = Sec->Flags; Type = Sec->Type; continue; @@ -649,6 +650,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { auto *OutSec = make(Cmd->Name, Type, Flags); OutputSections->push_back(OutSec); + Cmd->Sec = OutSec; } } @@ -764,7 +766,9 @@ void LinkerScript::placeOrphanSections() { return Cmd && Cmd->Name == Name; }); if (Pos == E) { - Opt.Commands.insert(CmdIter, make(Name)); + auto *Cmd = make(Name); + Cmd->Sec = Sec; + Opt.Commands.insert(CmdIter, Cmd); ++CmdIndex; continue; } diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index e1962c04d928..e1fc3c43aee4 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -105,6 +105,7 @@ struct OutputSectionCommand : BaseCommand { static bool classof(const BaseCommand *C); + OutputSection *Sec = nullptr; StringRef Name; Expr AddrExpr; Expr AlignExpr;