Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -430,11 +430,13 @@ 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 @@ 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;