[llvm-branch-commits] [lld] fac1140 - [ELF] -r: don't create .interp

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 16 13:26:05 PST 2020


Author: Fangrui Song
Date: 2020-01-16T13:25:51-08:00
New Revision: fac11406197ed993f1965ed1edc0369a12a2f8e2

URL: https://github.com/llvm/llvm-project/commit/fac11406197ed993f1965ed1edc0369a12a2f8e2
DIFF: https://github.com/llvm/llvm-project/commit/fac11406197ed993f1965ed1edc0369a12a2f8e2.diff

LOG: [ELF] -r: don't create .interp

`{clang,gcc} -nostdlib -r a.c` passes --dynamic-linker to the linker,
and the expected behavior is to ignore it.

If .interp is kept in the relocatable object file, a final link will get
PT_INTERP even if --dynamic-linker is not specified. glibc ld.so expects
to see PT_DYNAMIC and the executable will likely fail to run.

Ignore --dynamic-linker in -r mode as well as -shared.

(cherry picked from commit 2d7a8cf90478cd845ffb39763b0e95b7715322d2)

Added: 
    

Modified: 
    lld/ELF/Writer.cpp
    lld/test/ELF/dynamic-linker.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 6373044d8804..ac332de2a057 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -135,8 +135,8 @@ StringRef getOutputSectionName(const InputSectionBase *s) {
 }
 
 static bool needsInterpSection() {
-  return !config->shared && !config->dynamicLinker.empty() &&
-         script->needsInterpSection();
+  return !config->relocatable && !config->shared &&
+         !config->dynamicLinker.empty() && script->needsInterpSection();
 }
 
 template <class ELFT> void writeResult() { Writer<ELFT>().run(); }

diff  --git a/lld/test/ELF/dynamic-linker.s b/lld/test/ELF/dynamic-linker.s
index 4d1dab48aec6..7330b52e155e 100644
--- a/lld/test/ELF/dynamic-linker.s
+++ b/lld/test/ELF/dynamic-linker.s
@@ -10,11 +10,16 @@
 # CHECK: [Requesting program interpreter: foo]
 
 # RUN: ld.lld %t.o -o %t
-# RUN: llvm-readelf -program-headers %t | FileCheck --check-prefix=NO %s
+# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=NO %s
 
 # RUN: ld.lld --dynamic-linker foo --no-dynamic-linker %t.o -o %t
-# RUN: llvm-readelf --program-headers %t | FileCheck --check-prefix=NO %s
+# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=NO %s
 
+## {clang,gcc} -nostdlib -r passes --dynamic-linker, and the expected behavior is to ignore it.
+# RUN: ld.lld -r --dynamic-linker foo %t.o -o %t
+# RUN: llvm-readelf -S -l %t | FileCheck --check-prefix=NO %s
+
+# NO-NOT: .interp
 # NO-NOT: PT_INTERP
 
 .globl _start


        


More information about the llvm-branch-commits mailing list