From f9bc3bd2cf6651c1cdaf2d5915c280a313a9043e Mon Sep 17 00:00:00 2001 From: Eugene Leviant Date: Tue, 16 Aug 2016 06:40:58 +0000 Subject: [PATCH] [ELF] Ignore .interp section in case linker script specifies PHDRS without PT_INTERP llvm-svn: 278781 --- lld/ELF/LinkerScript.cpp | 9 +++++++++ lld/ELF/LinkerScript.h | 1 + lld/ELF/Writer.cpp | 3 ++- lld/test/ELF/linkerscript/linkerscript-discard-interp.s | 12 ++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/linkerscript/linkerscript-discard-interp.s diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index dd9ef6a..7195d8f 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -486,6 +486,15 @@ std::vector> LinkerScript::createPhdrs() { return Ret; } +template bool LinkerScript::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 ArrayRef LinkerScript::getFiller(StringRef Name) { for (const std::unique_ptr &Base : Opt.Commands) diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index 53a6db5..d33c12e 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -144,6 +144,7 @@ public: void createSections(OutputSectionFactory &Factory); std::vector> createPhdrs(); + bool ignoreInterpSection(); ArrayRef getFiller(StringRef Name); bool shouldKeep(InputSectionBase *S); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 108ca54..5a39559 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -105,7 +105,8 @@ template void elf::reportDiscarded(InputSectionBase *IS) { template static bool needsInterpSection() { return !Symtab::X->getSharedFiles().empty() && - !Config->DynamicLinker.empty(); + !Config->DynamicLinker.empty() && + !Script::X->ignoreInterpSection(); } template void elf::writeResult() { diff --git a/lld/test/ELF/linkerscript/linkerscript-discard-interp.s b/lld/test/ELF/linkerscript/linkerscript-discard-interp.s new file mode 100644 index 0000000..5f2d82e --- /dev/null +++ b/lld/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: -- 2.7.4