[PATCH] D23702: Do not add .interp, .dynamic nor .eh_frame_hdr to segments just by type.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 19:01:49 PDT 2016
ruiu created this revision.
ruiu added a reviewer: evgeny777.
ruiu added a subscriber: llvm-commits.
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.
https://reviews.llvm.org/D23702
Files:
ELF/LinkerScript.cpp
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -425,43 +425,27 @@
Out<ELFT>::ProgramHeaders->setVA(Out<ELFT>::ElfHeader->getSize() + MinVA);
}
+// Creates program headers as instructed by PHDRS linker script command.
template <class ELFT>
std::vector<PhdrEntry<ELFT>> LinkerScript<ELFT>::createPhdrs() {
- ArrayRef<OutputSectionBase<ELFT> *> Sections = *OutputSections;
std::vector<PhdrEntry<ELFT>> 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<ELFT> &Phdr = Ret.back();
if (Cmd.HasFilehdr)
Phdr.add(Out<ELFT>::ElfHeader);
if (Cmd.HasPhdrs)
Phdr.add(Out<ELFT>::ProgramHeaders);
-
- switch (Cmd.Type) {
- case PT_INTERP:
- if (Out<ELFT>::Interp)
- Phdr.add(Out<ELFT>::Interp);
- break;
- case PT_DYNAMIC:
- if (Out<ELFT>::DynSymTab) {
- Phdr.H.p_flags = Out<ELFT>::Dynamic->getPhdrFlags();
- Phdr.add(Out<ELFT>::Dynamic);
- }
- break;
- case PT_GNU_EH_FRAME:
- if (!Out<ELFT>::EhFrame->empty() && Out<ELFT>::EhFrameHdr) {
- Phdr.H.p_flags = Out<ELFT>::EhFrameHdr->getPhdrFlags();
- Phdr.add(Out<ELFT>::EhFrameHdr);
- }
- break;
- }
}
+ // Add output sections to program headers.
PhdrEntry<ELFT> *Load = nullptr;
uintX_t Flags = PF_R;
- for (OutputSectionBase<ELFT> *Sec : Sections) {
+ for (OutputSectionBase<ELFT> *Sec : *OutputSections) {
if (!(Sec->getFlags() & SHF_ALLOC))
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23702.68643.patch
Type: text/x-patch
Size: 1779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160819/bbdaf23c/attachment.bin>
More information about the llvm-commits
mailing list