diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -267,6 +267,8 @@ return false; if (computeBinding() == STB_LOCAL) return false; + if (isUndefWeak() && Config->Pie && Config->Static) + return false; if (!isDefined()) return true; return ExportDynamic; diff --git a/lld/test/ELF/Inputs/static-pie-weak-undef.s b/lld/test/ELF/Inputs/static-pie-weak-undef.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/Inputs/static-pie-weak-undef.s @@ -0,0 +1,2 @@ + .global main +main: diff --git a/lld/test/ELF/static-pie-weak-undef.s b/lld/test/ELF/static-pie-weak-undef.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/static-pie-weak-undef.s @@ -0,0 +1,28 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/static-pie-weak-undef.s -o %t2.o +// RUN: ld.lld -static -pie %t2.o %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 emitted in .dynsym. There +// are other tests which ensure that the weak undefined symbols do get emitted in .dynsym +// for non-static PIEs. + + +// 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: ]