From d803cda42997f42649910309ac18170d2d6f2214 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 3 May 2017 20:26:46 +0000 Subject: Vendor import of lld trunk r302069: https://llvm.org/svn/llvm-project/lld/trunk@302069 --- ELF/LinkerScript.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'ELF/LinkerScript.cpp') diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp index 22a5b639469b..3f872c65897f 100644 --- a/ELF/LinkerScript.cpp +++ b/ELF/LinkerScript.cpp @@ -428,13 +428,12 @@ void LinkerScript::fabricateDefaultCommands(bool AllocateHeader) { if (AllocateHeader) StartAddr += elf::getHeaderSize(); - // The Sections with -T
are sorted in order of ascending address - // we must use this if it is lower than StartAddr as calls to setDot() must - // be monotonically increasing - if (!Config->SectionStartMap.empty()) { - uint64_t LowestSecStart = Config->SectionStartMap.begin()->second; - StartAddr = std::min(StartAddr, LowestSecStart); - } + // The Sections with -T
have been sorted in order of ascending + // address. We must lower StartAddr if the lowest -T
as + // calls to setDot() must be monotonically increasing. + for (auto& KV : Config->SectionStartMap) + StartAddr = std::min(StartAddr, KV.second); + Commands.push_back( make(".", [=] { return StartAddr; }, "")); @@ -444,17 +443,19 @@ void LinkerScript::fabricateDefaultCommands(bool AllocateHeader) { if (!(Sec->Flags & SHF_ALLOC)) continue; + auto *OSCmd = make(Sec->Name); + OSCmd->Sec = Sec; + + // Prefer user supplied address over additional alignment constraint auto I = Config->SectionStartMap.find(Sec->Name); if (I != Config->SectionStartMap.end()) Commands.push_back( make(".", [=] { return I->second; }, "")); - - auto *OSCmd = make(Sec->Name); - OSCmd->Sec = Sec; - if (Sec->PageAlign) + else if (Sec->PageAlign) OSCmd->AddrExpr = [=] { return alignTo(Script->getDot(), Config->MaxPageSize); }; + Commands.push_back(OSCmd); if (Sec->Sections.size()) { auto *ISD = make(""); -- cgit v1.3