[lld] r356374 - [ELF] Emit weak-undef symbols in .dynsym of a PIE binary only if linked against shared libs.
Siva Chandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 08:32:58 PDT 2019
Author: sivachandra
Date: Mon Mar 18 08:32:57 2019
New Revision: 356374
URL: http://llvm.org/viewvc/llvm-project?rev=356374&view=rev
Log:
[ELF] Emit weak-undef symbols in .dynsym of a PIE binary only if linked against shared libs.
Reviewers: espindola
Subscribers: emaste, arichardson, MaskRay, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59275
Added:
lld/trunk/test/ELF/Inputs/dummy-shared.s
lld/trunk/test/ELF/weak-undef-no-shared-libs.s
Modified:
lld/trunk/ELF/Symbols.cpp
lld/trunk/test/ELF/pie-weak.s
lld/trunk/test/ELF/relocation-relative-weak.s
lld/trunk/test/ELF/weak-undef.s
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=356374&r1=356373&r2=356374&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Mar 18 08:32:57 2019
@@ -267,6 +267,10 @@ bool Symbol::includeInDynsym() const {
return false;
if (computeBinding() == STB_LOCAL)
return false;
+ // If a PIE binary was not linked against any shared libraries, then we can
+ // safely drop weak undef symbols from .dynsym.
+ if (isUndefWeak() && Config->Pie && SharedFiles.empty())
+ return false;
if (!isDefined())
return true;
return ExportDynamic;
Added: lld/trunk/test/ELF/Inputs/dummy-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/dummy-shared.s?rev=356374&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/dummy-shared.s (added)
+++ lld/trunk/test/ELF/Inputs/dummy-shared.s Mon Mar 18 08:32:57 2019
@@ -0,0 +1,2 @@
+.globl bar
+bar:
Modified: lld/trunk/test/ELF/pie-weak.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/pie-weak.s?rev=356374&r1=356373&r2=356374&view=diff
==============================================================================
--- lld/trunk/test/ELF/pie-weak.s (original)
+++ lld/trunk/test/ELF/pie-weak.s Mon Mar 18 08:32:57 2019
@@ -1,6 +1,8 @@
# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/dummy-shared.s -o %t1.o
+# RUN: ld.lld %t1.o -shared -o %t1.so
# RUN: llvm-mc -filetype=obj -relax-relocations=false -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld --hash-style=sysv -pie %t.o -o %t
+# RUN: ld.lld --hash-style=sysv -pie %t.o %t1.so -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s
# RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s
@@ -15,6 +17,6 @@
.globl _start
_start:
# DISASM: _start:
-# DISASM-NEXT: 1000: 48 8b 05 99 10 00 00 movq 4249(%rip), %rax
+# DISASM-NEXT: 1000: 48 8b 05 a9 10 00 00 movq 4265(%rip), %rax
# ^ .got - (.text + 7)
mov foo at gotpcrel(%rip), %rax
Modified: lld/trunk/test/ELF/relocation-relative-weak.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-relative-weak.s?rev=356374&r1=356373&r2=356374&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-relative-weak.s (original)
+++ lld/trunk/test/ELF/relocation-relative-weak.s Mon Mar 18 08:32:57 2019
@@ -1,6 +1,8 @@
# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/dummy-shared.s -o %t1.o
+# RUN: ld.lld %t1.o -shared -o %t1.so
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t -pie
+# RUN: ld.lld %t.o %t1.so -o %t -pie
# RUN: llvm-readobj -dyn-relocations %t | FileCheck %s
# CHECK: Dynamic Relocations {
Added: lld/trunk/test/ELF/weak-undef-no-shared-libs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-undef-no-shared-libs.s?rev=356374&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-undef-no-shared-libs.s (added)
+++ lld/trunk/test/ELF/weak-undef-no-shared-libs.s Mon Mar 18 08:32:57 2019
@@ -0,0 +1,28 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -pie %t.o -o %t
+// RUN: llvm-readobj -V -dyn-symbols %t | FileCheck %s
+
+ .globl _start
+_start:
+ .type foo, at function
+ .weak foo
+ .long foo at gotpcrel
+
+// Test that an entry for weak undefined symbols is NOT emitted in .dynsym as
+// the PIE was not linked with any shared libraries. There are other tests which
+// ensure that the weak undefined symbols do get emitted in .dynsym for PIEs
+// linked against dynamic libraries.
+
+
+// CHECK: DynamicSymbols [
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name:
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Type: None (0x0)
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Undefined (0x0)
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
Modified: lld/trunk/test/ELF/weak-undef.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-undef.s?rev=356374&r1=356373&r2=356374&view=diff
==============================================================================
--- lld/trunk/test/ELF/weak-undef.s (original)
+++ lld/trunk/test/ELF/weak-undef.s Mon Mar 18 08:32:57 2019
@@ -1,6 +1,8 @@
# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/dummy-shared.s -o %t1.o
+# RUN: ld.lld %t1.o -shared -o %t1.so
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: ld.lld %t.o -o %t -pie
+# RUN: ld.lld %t.o -o %t %t1.so -pie
# RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
# CHECK: DynamicSymbols [
More information about the llvm-commits
mailing list