From feed7506767533338c0f990237452e3f69de0eae Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 6 Apr 2017 21:31:24 +0000 Subject: [PATCH] Move call to findMemoryRegion before assignAddresses. This removes a bit more work from assignAddresses. llvm-svn: 299716 --- lld/ELF/LinkerScript.cpp | 8 ++++++-- lld/ELF/LinkerScript.h | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index f20dbff..d97db84 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -583,8 +583,7 @@ void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) { if (Cmd->AlignExpr) Sec->updateAlignment(Cmd->AlignExpr().getValue()); - // Try and find an appropriate memory region to assign offsets in. - CurMemRegion = findMemoryRegion(Cmd); + CurMemRegion = Cmd->MemRegion; if (CurMemRegion) Dot = CurMemRegion->Offset; switchTo(Sec); @@ -657,6 +656,11 @@ void LinkerScript::adjustSectionsBeforeSorting() { void LinkerScript::adjustSectionsAfterSorting() { placeOrphanSections(); + // Try and find an appropriate memory region to assign offsets in. + for (BaseCommand *Base : Opt.Commands) + if (auto *Cmd = dyn_cast(Base)) + Cmd->MemRegion = findMemoryRegion(Cmd); + // If output section command doesn't specify any segments, // and we haven't previously assigned any section to segment, // then we simply assign section to the very first load segment. diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index f27eb65..9841f4f 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -99,6 +99,18 @@ struct SymbolAssignment : BaseCommand { // with ONLY_IF_RW is created if all input sections are RW. enum class ConstraintKind { NoConstraint, ReadOnly, ReadWrite }; +// This struct is used to represent the location and size of regions of +// target memory. Instances of the struct are created by parsing the +// MEMORY command. +struct MemoryRegion { + std::string Name; + uint64_t Origin; + uint64_t Length; + uint64_t Offset; + uint32_t Flags; + uint32_t NegFlags; +}; + struct OutputSectionCommand : BaseCommand { OutputSectionCommand(StringRef Name) : BaseCommand(OutputSectionKind), Name(Name) {} @@ -106,6 +118,7 @@ struct OutputSectionCommand : BaseCommand { static bool classof(const BaseCommand *C); OutputSection *Sec = nullptr; + MemoryRegion *MemRegion = nullptr; StringRef Name; Expr AddrExpr; Expr AlignExpr; @@ -177,18 +190,6 @@ struct PhdrsCommand { Expr LMAExpr; }; -// This struct is used to represent the location and size of regions of -// target memory. Instances of the struct are created by parsing the -// MEMORY command. -struct MemoryRegion { - std::string Name; - uint64_t Origin; - uint64_t Length; - uint64_t Offset; - uint32_t Flags; - uint32_t NegFlags; -}; - // ScriptConfiguration holds linker script parse results. struct ScriptConfiguration { // Used to assign addresses to sections. -- 2.7.4