[PATCH] D23502: [ELF] Linkerscript: discard .interp section if we have custom PHDRS layout and PT_INTERP is not listed.
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 15 04:57:43 PDT 2016
evgeny777 created this revision.
evgeny777 added a reviewer: ruiu.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
Current version may allocate new PT_LOAD in this case, which wastes space in ELF image and breaks our product linking.
Repository:
rL LLVM
https://reviews.llvm.org/D23502
Files:
ELF/LinkerScript.cpp
ELF/LinkerScript.h
ELF/Writer.cpp
test/ELF/linkerscript/linkerscript-discard-interp.s
Index: test/ELF/linkerscript/linkerscript-discard-interp.s
===================================================================
--- test/ELF/linkerscript/linkerscript-discard-interp.s
+++ test/ELF/linkerscript/linkerscript-discard-interp.s
@@ -0,0 +1,12 @@
+// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/../Inputs/shared.s -o %t2.o
+// RUN: ld.lld -shared %t2.o -o %t2.so
+// RUN: echo "PHDRS { text PT_LOAD FILEHDR PHDRS; } \
+// RUN: SECTIONS { .text : { *(.text) } : text }" >> %t.script
+// RUN: ld.lld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar --script %t.script --export-dynamic %t.o %t2.so -o %t
+// RUN: llvm-readobj -s %t | FileCheck %s
+
+// CHECK-NOT: Name: .interp
+
+.global _start
+_start:
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -105,7 +105,8 @@
template <class ELFT> static bool needsInterpSection() {
return !Symtab<ELFT>::X->getSharedFiles().empty() &&
- !Config->DynamicLinker.empty();
+ !Config->DynamicLinker.empty() &&
+ !Script<ELFT>::X->discardInterpSection();
}
template <class ELFT> void elf::writeResult() {
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -144,6 +144,7 @@
void createSections(OutputSectionFactory<ELFT> &Factory);
std::vector<PhdrEntry<ELFT>> createPhdrs();
+ bool discardInterpSection();
ArrayRef<uint8_t> getFiller(StringRef Name);
bool shouldKeep(InputSectionBase<ELFT> *S);
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -486,6 +486,15 @@
return Ret;
}
+template <class ELFT> bool LinkerScript<ELFT>::discardInterpSection() {
+ // Discard .interp section in case we have PHDRS specification
+ // and PT_INTERP isn't listed.
+ return !Opt.PhdrsCommands.empty() &&
+ llvm::find_if(Opt.PhdrsCommands, [](const PhdrsCommand &Cmd) {
+ return Cmd.Type == PT_INTERP;
+ }) == Opt.PhdrsCommands.end();
+}
+
template <class ELFT>
ArrayRef<uint8_t> LinkerScript<ELFT>::getFiller(StringRef Name) {
for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23502.68018.patch
Type: text/x-patch
Size: 2394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160815/8145c0db/attachment.bin>
More information about the llvm-commits
mailing list