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;
--- /dev/null
+.globl bar
+bar:
# 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
.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@gotpcrel(%rip), %rax
# 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 {
--- /dev/null
+// 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,@function
+ .weak foo
+ .long foo@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: ]
# 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 [