Skip to content

Commit 464daad

Browse files
committedAug 22, 2016
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
1 parent 0672a27 commit 464daad

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed
 

‎lld/ELF/LinkerScript.cpp

+5-21
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,13 @@ template <class ELFT> void LinkerScript<ELFT>::assignAddresses() {
430430
Out<ELFT>::ProgramHeaders->setVA(Out<ELFT>::ElfHeader->getSize() + MinVA);
431431
}
432432

433+
// Creates program headers as instructed by PHDRS linker script command.
433434
template <class ELFT>
434435
std::vector<PhdrEntry<ELFT>> LinkerScript<ELFT>::createPhdrs() {
435-
ArrayRef<OutputSectionBase<ELFT> *> Sections = *OutputSections;
436436
std::vector<PhdrEntry<ELFT>> Ret;
437437

438+
// Process PHDRS and FILEHDR keywords because they are not
439+
// real output sections and cannot be added in the following loop.
438440
for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
439441
Ret.emplace_back(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags);
440442
PhdrEntry<ELFT> &Phdr = Ret.back();
@@ -443,30 +445,12 @@ std::vector<PhdrEntry<ELFT>> LinkerScript<ELFT>::createPhdrs() {
443445
Phdr.add(Out<ELFT>::ElfHeader);
444446
if (Cmd.HasPhdrs)
445447
Phdr.add(Out<ELFT>::ProgramHeaders);
446-
447-
switch (Cmd.Type) {
448-
case PT_INTERP:
449-
if (Out<ELFT>::Interp)
450-
Phdr.add(Out<ELFT>::Interp);
451-
break;
452-
case PT_DYNAMIC:
453-
if (Out<ELFT>::DynSymTab) {
454-
Phdr.H.p_flags = Out<ELFT>::Dynamic->getPhdrFlags();
455-
Phdr.add(Out<ELFT>::Dynamic);
456-
}
457-
break;
458-
case PT_GNU_EH_FRAME:
459-
if (!Out<ELFT>::EhFrame->empty() && Out<ELFT>::EhFrameHdr) {
460-
Phdr.H.p_flags = Out<ELFT>::EhFrameHdr->getPhdrFlags();
461-
Phdr.add(Out<ELFT>::EhFrameHdr);
462-
}
463-
break;
464-
}
465448
}
466449

450+
// Add output sections to program headers.
467451
PhdrEntry<ELFT> *Load = nullptr;
468452
uintX_t Flags = PF_R;
469-
for (OutputSectionBase<ELFT> *Sec : Sections) {
453+
for (OutputSectionBase<ELFT> *Sec : *OutputSections) {
470454
if (!(Sec->getFlags() & SHF_ALLOC))
471455
break;
472456

0 commit comments

Comments
 (0)