Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -441,6 +441,10 @@ DynType = Target->TlsGotRel; else if (Preemptible) DynType = Target->GotRel; + else if (Body.isUndefined()) + // Weak undefined symbols evaluate to zero, so don't create + // relocations for them. + continue; else DynType = Target->RelativeRel; Out::RelaDyn->addReloc({DynType, Out::Got, Index: test/ELF/pie-weak.s =================================================================== --- /dev/null +++ test/ELF/pie-weak.s @@ -0,0 +1,12 @@ +# 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 -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: ] + +.weak foo + +.globl _start +_start: +mov foo@gotpcrel(%rip), %rax