Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -570,6 +570,10 @@ // R_RISCV_PCREL_LO12's symbol and addend. static Relocation *getRISCVPCRelHi20(const Symbol *Sym, uint64_t Addend) { const Defined *D = cast(Sym); + if (!D->Section) { + error("R_RISCV_PCREL_LO12 relocation points to an absolute symbol"); + return nullptr; + } InputSection *IS = cast(D->Section); if (Addend != 0) Index: test/ELF/riscv-pcrel-hilo-error.s =================================================================== --- /dev/null +++ test/ELF/riscv-pcrel-hilo-error.s @@ -0,0 +1,7 @@ +# REQUIRES: riscv +# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o +# RUN: not ld.lld %t.o --defsym external=0 2>&1 | FileCheck %s + +# CHECK: error: R_RISCV_PCREL_LO12 relocation points to an absolute symbol + +addi sp,sp,%pcrel_lo(external)