[llvm] 036b170 - [LoongArch] Produce a R_LARCH_32_PCREL relocation
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 18:05:08 PDT 2022
Author: wanglei
Date: 2022-09-29T09:04:44+08:00
New Revision: 036b170c24f77d83d2f09186490ef5332aa8e243
URL: https://github.com/llvm/llvm-project/commit/036b170c24f77d83d2f09186490ef5332aa8e243
DIFF: https://github.com/llvm/llvm-project/commit/036b170c24f77d83d2f09186490ef5332aa8e243.diff
LOG: [LoongArch] Produce a R_LARCH_32_PCREL relocation
LoongArchELFObjectWriter::getRelocType check IsPCRel for FK_Data_4
(which we produce a R_LARCH_32_PCREL relocation for if IsPCRel).
R_LARCH_32_PCREL is required for FDE relocation.
Differential Revision: https://reviews.llvm.org/D134715
Added:
llvm/test/MC/LoongArch/Relocations/fde-reloc.s
Modified:
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
index 87be0b0efc016..ee8774ed792f5 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -64,7 +64,7 @@ unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx,
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
index 0000000000000..6fff459230eac
--- /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
diff erence 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: }
More information about the llvm-commits
mailing list