Commit 2d7a8cf9 authored by Fangrui Song's avatar Fangrui Song
Browse files

[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.
parent d0b02aec
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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(); }
+7 −2
Original line number Diff line number Diff line
@@ -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