[lld] r278781 - [ELF] Ignore .interp section in case linker script specifies PHDRS without PT_INTERP

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 23:40:58 PDT 2016


Author: evgeny777
Date: Tue Aug 16 01:40:58 2016
New Revision: 278781

URL: http://llvm.org/viewvc/llvm-project?rev=278781&view=rev
Log:
[ELF] Ignore .interp section in case linker script specifies PHDRS without PT_INTERP

Added:
    lld/trunk/test/ELF/linkerscript/linkerscript-discard-interp.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=278781&r1=278780&r2=278781&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Aug 16 01:40:58 2016
@@ -486,6 +486,15 @@ std::vector<PhdrEntry<ELFT>> LinkerScrip
   return Ret;
 }
 
+template <class ELFT> bool LinkerScript<ELFT>::ignoreInterpSection() {
+  // Ignore .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)

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=278781&r1=278780&r2=278781&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Tue Aug 16 01:40:58 2016
@@ -144,6 +144,7 @@ public:
   void createSections(OutputSectionFactory<ELFT> &Factory);
 
   std::vector<PhdrEntry<ELFT>> createPhdrs();
+  bool ignoreInterpSection();
 
   ArrayRef<uint8_t> getFiller(StringRef Name);
   bool shouldKeep(InputSectionBase<ELFT> *S);

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=278781&r1=278780&r2=278781&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Aug 16 01:40:58 2016
@@ -105,7 +105,8 @@ template <class ELFT> void elf::reportDi
 
 template <class ELFT> static bool needsInterpSection() {
   return !Symtab<ELFT>::X->getSharedFiles().empty() &&
-         !Config->DynamicLinker.empty();
+         !Config->DynamicLinker.empty() &&
+         !Script<ELFT>::X->ignoreInterpSection();
 }
 
 template <class ELFT> void elf::writeResult() {

Added: lld/trunk/test/ELF/linkerscript/linkerscript-discard-interp.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-discard-interp.s?rev=278781&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-discard-interp.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-discard-interp.s Tue Aug 16 01:40:58 2016
@@ -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:




More information about the llvm-commits mailing list