[ELF] Improve the condition to create .interp
authorFangrui Song <maskray@google.com>
Mon, 3 Jun 2019 05:25:03 +0000 (05:25 +0000)
committerFangrui Song <maskray@google.com>
Thu, 26 Dec 2019 21:26:43 +0000 (13:26 -0800)
Similar to rL362355, but with the `!config->shared` guard.

(1) {gcc,clang} -fuse-ld=bfd -pie -fPIE -nostdlib a.c => .interp created
(2) {gcc,clang} -fuse-ld=lld -pie -fPIE -nostdlib a.c => .interp not created
(3) {gcc,clang} -fuse-ld=lld -pie -fPIE -nostdlib a.c a.so => .interp created

The inconsistency of (2) is due to the condition `!Config->SharedFiles.empty()`.
To make lld behave more like ld.bfd, we could change the condition to:

    config->hasDynSymTab && !config->dynamicLinker.empty() && script->needsInterpSection();

However, that would bring another inconsistency as can be observed with:

(4) {gcc,clang} -fuse-ld=bfd -no-pie -nostdlib a.c => .interp not created

lld/ELF/Writer.cpp
lld/test/ELF/dynamic-linker.s
lld/test/ELF/ppc64-func-entry-points.s

index c0ad334..c20b748 100644 (file)
@@ -135,7 +135,7 @@ StringRef getOutputSectionName(const InputSectionBase *s) {
 }
 
 static bool needsInterpSection() {
-  return !sharedFiles.empty() && !config->dynamicLinker.empty() &&
+  return !config->shared && !config->dynamicLinker.empty() &&
          script->needsInterpSection();
 }
 
index d0da77f..b5e9f5f 100644 (file)
@@ -1,6 +1,4 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t1.o
-# RUN: ld.lld -shared %t1.o -o %t.so
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
 
 # RUN: ld.lld --dynamic-linker foo %t.o %t.so -o %t
 
 # CHECK: [Requesting program interpreter: foo]
 
-# RUN: ld.lld %t.o %t.so -o %t
+# RUN: ld.lld %t.o -o %t
 # RUN: llvm-readelf -program-headers %t | FileCheck --check-prefix=NO %s
 
-# RUN: ld.lld --dynamic-linker foo --no-dynamic-linker %t.o %t.so -o %t
-# RUN: llvm-readelf -program-headers %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
 
 # NO-NOT: PT_INTERP
 
index 1411cbe..c322f65 100644 (file)
@@ -3,13 +3,13 @@
 // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
 // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-func-global-entry.s -o %t2.o
 // RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %p/Inputs/ppc64-func-local-entry.s -o %t3.o
-// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o %t3.o -o %t
+// RUN: ld.lld %t.o %t2.o %t3.o -o %t
 // RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
 // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
 // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-func-global-entry.s -o %t2.o
 // RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/ppc64-func-local-entry.s -o %t3.o
-// RUN: ld.lld -dynamic-linker /lib64/ld64.so.2 %t.o %t2.o %t3.o -o %t
+// RUN: ld.lld %t.o %t2.o %t3.o -o %t
 // RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
        .text