Author: hans Date: Mon Aug 6 03:15:52 2018 New Revision: 339000 URL: http://llvm.org/viewvc/llvm-project?rev=339000&view=rev Log: Merging r338679, r338684, r338697, r338699:
------------------------------------------------------------------------ r338679 | grimar | 2018-08-02 10:07:07 +0200 (Thu, 02 Aug 2018) | 10 lines [LLD] - Improve handling of AT> linker script commands Patch by Konstantin Schwarz! The condition to create a new phdr must also check the usage of "AT>" linker script command, and create a new PT_LOAD header if a new LMARegion is used. This fixes PR38307 Differential revision: https://reviews.llvm.org/D50052 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r338684 | grimar | 2018-08-02 10:13:56 +0200 (Thu, 02 Aug 2018) | 9 lines [LLD] Only increase LMARegion if different from MemRegion Patch by Konstantin Schwarz! If both the MemRegion and LMARegion are set for an output section in a linker script, we should only increase the LMARegion if it is different from the MemRegion. Otherwise, we reserve the memory twice. Differential revision: https://reviews.llvm.org/D50065 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r338697 | grimar | 2018-08-02 12:45:46 +0200 (Thu, 02 Aug 2018) | 9 lines [LLD] Do not overwrite LMAOffset of PT_LOAD header Patch by Konstantin Schwarz! If more than a single output section is added to a PT_LOAD header, only the first section should set the LMAOffset of the segment. Otherwise, we get a load-address overlap error Differential revision: https://reviews.llvm.org/D50133 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r338699 | grimar | 2018-08-02 12:59:28 +0200 (Thu, 02 Aug 2018) | 5 lines [LLD][ELF] - Simplify. NFC. isHeaderSection can be useful I believe, but probably not right now and not for this case. ------------------------------------------------------------------------ Added: lld/branches/release_70/test/ELF/linkerscript/Inputs/at6.s - copied unchanged from r338679, lld/trunk/test/ELF/linkerscript/Inputs/at6.s lld/branches/release_70/test/ELF/linkerscript/Inputs/at7.s - copied unchanged from r338684, lld/trunk/test/ELF/linkerscript/Inputs/at7.s lld/branches/release_70/test/ELF/linkerscript/Inputs/at8.s - copied unchanged from r338697, lld/trunk/test/ELF/linkerscript/Inputs/at8.s lld/branches/release_70/test/ELF/linkerscript/at6.test - copied unchanged from r338679, lld/trunk/test/ELF/linkerscript/at6.test lld/branches/release_70/test/ELF/linkerscript/at7.test - copied unchanged from r338684, lld/trunk/test/ELF/linkerscript/at7.test lld/branches/release_70/test/ELF/linkerscript/at8.test - copied unchanged from r338697, lld/trunk/test/ELF/linkerscript/at8.test Modified: lld/branches/release_70/ (props changed) lld/branches/release_70/ELF/LinkerScript.cpp lld/branches/release_70/ELF/Writer.cpp Propchange: lld/branches/release_70/ ------------------------------------------------------------------------------ svn:mergeinfo = /lld/trunk:338679,338684,338697,338699 Modified: lld/branches/release_70/ELF/LinkerScript.cpp URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/ELF/LinkerScript.cpp?rev=339000&r1=338999&r2=339000&view=diff ============================================================================== --- lld/branches/release_70/ELF/LinkerScript.cpp (original) +++ lld/branches/release_70/ELF/LinkerScript.cpp Mon Aug 6 03:15:52 2018 @@ -116,7 +116,8 @@ void LinkerScript::expandMemoryRegions(u if (Ctx->MemRegion) expandMemoryRegion(Ctx->MemRegion, Size, Ctx->MemRegion->Name, Ctx->OutSec->Name); - if (Ctx->LMARegion) + // Only expand the LMARegion if it is different from MemRegion. + if (Ctx->LMARegion && Ctx->MemRegion != Ctx->LMARegion) expandMemoryRegion(Ctx->LMARegion, Size, Ctx->LMARegion->Name, Ctx->OutSec->Name); } @@ -750,6 +751,13 @@ MemoryRegion *LinkerScript::findMemoryRe return nullptr; } +static OutputSection *findFirstSection(PhdrEntry *Load) { + for (OutputSection *Sec : OutputSections) + if (Sec->PtLoad == Load) + return Sec; + return nullptr; +} + // This function assigns offsets to input sections and an output section // for a single sections command (e.g. ".text { *(.text); }"). void LinkerScript::assignOffsets(OutputSection *Sec) { @@ -775,8 +783,11 @@ void LinkerScript::assignOffsets(OutputS // will set the LMA such that the difference between VMA and LMA for the // section is the same as the preceding output section in the same region // https://sourceware.org/binutils/docs-2.20/ld/Output-Section-LMA.html + // This, however, should only be done by the first "non-header" section + // in the segment. if (PhdrEntry *L = Ctx->OutSec->PtLoad) - L->LMAOffset = Ctx->LMAOffset; + if (Sec == findFirstSection(L)) + L->LMAOffset = Ctx->LMAOffset; // We can call this method multiple times during the creation of // thunks and want to start over calculation each time. @@ -953,13 +964,6 @@ void LinkerScript::adjustSectionsAfterSo } } -static OutputSection *findFirstSection(PhdrEntry *Load) { - for (OutputSection *Sec : OutputSections) - if (Sec->PtLoad == Load) - return Sec; - return nullptr; -} - static uint64_t computeBase(uint64_t Min, bool AllocateHeaders) { // If there is no SECTIONS or if the linkerscript is explicit about program // headers, do our best to allocate them. Modified: lld/branches/release_70/ELF/Writer.cpp URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_70/ELF/Writer.cpp?rev=339000&r1=338999&r2=339000&view=diff ============================================================================== --- lld/branches/release_70/ELF/Writer.cpp (original) +++ lld/branches/release_70/ELF/Writer.cpp Mon Aug 6 03:15:52 2018 @@ -1815,12 +1815,14 @@ template <class ELFT> std::vector<PhdrEn // Segments are contiguous memory regions that has the same attributes // (e.g. executable or writable). There is one phdr for each segment. // Therefore, we need to create a new phdr when the next section has - // different flags or is loaded at a discontiguous address using AT linker - // script command. At the same time, we don't want to create a separate - // load segment for the headers, even if the first output section has - // an AT attribute. + // different flags or is loaded at a discontiguous address or memory + // region using AT or AT> linker script command, respectively. At the same + // time, we don't want to create a separate load segment for the headers, + // even if the first output section has an AT or AT> attribute. uint64_t NewFlags = computeFlags(Sec->getPhdrFlags()); - if ((Sec->LMAExpr && Load->LastSec != Out::ProgramHeaders) || + if (((Sec->LMAExpr || + (Sec->LMARegion && (Sec->LMARegion != Load->FirstSec->LMARegion))) && + Load->LastSec != Out::ProgramHeaders) || Sec->MemRegion != Load->FirstSec->MemRegion || Flags != NewFlags) { Load = AddHdr(PT_LOAD, NewFlags); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits