diff options
author | Fangrui Song <maskray@google.com> | 2020-01-16 12:00:24 -0800 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-01-16 13:25:51 -0800 |
commit | fac11406197ed993f1965ed1edc0369a12a2f8e2 (patch) | |
tree | 9f5b0d2d0924979e838682ac0329d83bc675e50d | |
parent | ac446302ca4145cdc89f377c0c364c29ee303be5 (diff) | |
download | bcm5719-llvm-fac11406197ed993f1965ed1edc0369a12a2f8e2.tar.gz bcm5719-llvm-fac11406197ed993f1965ed1edc0369a12a2f8e2.zip |
[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)
-rw-r--r-- | lld/ELF/Writer.cpp | 4 | ||||
-rw-r--r-- | lld/test/ELF/dynamic-linker.s | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 6373044d880..ac332de2a05 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 4d1dab48aec..7330b52e155 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 |