From 464daadc3de8be1801e3aace6366c7255f08e531 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 22 Aug 2016 04:55:20 +0000 Subject: [PATCH] Do not add .interp, .dynamic nor .eh_frame_hdr to segments just by type. Summary: We previously added these output sections to segments just by type. Therefore, if there's a PHDRS command like this PHDRS { headers PT_PHDR PHDRS; interp PT_INTERP; } SECTIONS { . = SIZEOF_HEADERS; .interp : { *(.interp) } :text } then .interp was added to "interp" segment even though the linker is not instructed to do so by SECTIONS command. This patch removes the default behavior to simplify. Differential Revision: https://reviews.llvm.org/D23702 llvm-svn: 279414 --- lld/ELF/LinkerScript.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9cfbb48..ed6b39e 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -430,11 +430,13 @@ template void LinkerScript::assignAddresses() { Out::ProgramHeaders->setVA(Out::ElfHeader->getSize() + MinVA); } +// Creates program headers as instructed by PHDRS linker script command. template std::vector> LinkerScript::createPhdrs() { - ArrayRef *> Sections = *OutputSections; std::vector> Ret; + // Process PHDRS and FILEHDR keywords because they are not + // real output sections and cannot be added in the following loop. for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) { Ret.emplace_back(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags); PhdrEntry &Phdr = Ret.back(); @@ -443,30 +445,12 @@ std::vector> LinkerScript::createPhdrs() { Phdr.add(Out::ElfHeader); if (Cmd.HasPhdrs) Phdr.add(Out::ProgramHeaders); - - switch (Cmd.Type) { - case PT_INTERP: - if (Out::Interp) - Phdr.add(Out::Interp); - break; - case PT_DYNAMIC: - if (Out::DynSymTab) { - Phdr.H.p_flags = Out::Dynamic->getPhdrFlags(); - Phdr.add(Out::Dynamic); - } - break; - case PT_GNU_EH_FRAME: - if (!Out::EhFrame->empty() && Out::EhFrameHdr) { - Phdr.H.p_flags = Out::EhFrameHdr->getPhdrFlags(); - Phdr.add(Out::EhFrameHdr); - } - break; - } } + // Add output sections to program headers. PhdrEntry *Load = nullptr; uintX_t Flags = PF_R; - for (OutputSectionBase *Sec : Sections) { + for (OutputSectionBase *Sec : *OutputSections) { if (!(Sec->getFlags() & SHF_ALLOC)) break; -- 2.7.4