diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 3342da9192a8..1e54a29c3a9c 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -750,7 +750,9 @@ void OutputSection::relocate( Type = R_X86_64_PC32; break; case SymbolBody::UndefinedKind: - continue; + assert(Body->isWeak() && "Undefined symbol reached writer"); + SymVA = 0; + break; case SymbolBody::LazyKind: llvm_unreachable("Lazy symbol reached writer"); } diff --git a/lld/test/elf2/relocation-undefined-weak.s b/lld/test/elf2/relocation-undefined-weak.s new file mode 100644 index 000000000000..db670a78bf6e --- /dev/null +++ b/lld/test/elf2/relocation-undefined-weak.s @@ -0,0 +1,12 @@ +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t +// RUN: lld -flavor gnu2 %t -o %tout +// RUN: llvm-objdump -d %tout | FileCheck %s +// REQUIRES: x86 + +.global _start +_start: + movl $1, sym1(%rip) + +.weak sym1 + +// CHECK: movl $1, -69642(%rip)