diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp @@ -64,7 +64,7 @@ Ctx.reportError(Fixup.getLoc(), "2-byte data relocations not supported"); return ELF::R_LARCH_NONE; case FK_Data_4: - return ELF::R_LARCH_32; + return IsPCRel ? ELF::R_LARCH_32_PCREL : ELF::R_LARCH_32; case FK_Data_8: return ELF::R_LARCH_64; case LoongArch::fixup_loongarch_b16: diff --git a/llvm/test/MC/LoongArch/Relocations/fde-reloc.s b/llvm/test/MC/LoongArch/Relocations/fde-reloc.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/LoongArch/Relocations/fde-reloc.s @@ -0,0 +1,14 @@ +# RUN: llvm-mc --filetype=obj --triple=loongarch64 < %s \ +# RUN: | llvm-readobj -r - | FileCheck %s + +## Ensure that the eh_frame records the symbolic difference with +## the R_LARCH_32_PCREL relocation. + +func: + .cfi_startproc + ret + .cfi_endproc + +# CHECK: Section (4) .rela.eh_frame { +# CHECK-NEXT: 0x1C R_LARCH_32_PCREL - 0x0 +# CHECK-NEXT: }