[PATCH] D153872: [LoongArch] Emit R_LARCH_64_PCREL relocation for FK_Data_8 when IsPCRel is true

Lu Weining via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 07:01:12 PDT 2023


SixWeining created this revision.
SixWeining added reviewers: xen0n, xry111, MaskRay, hev, wangleiat.
Herald added a subscriber: hiraditya.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153872

Files:
  llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
  llvm/test/MC/LoongArch/Relocations/sub-expr.s


Index: llvm/test/MC/LoongArch/Relocations/sub-expr.s
===================================================================
--- /dev/null
+++ llvm/test/MC/LoongArch/Relocations/sub-expr.s
@@ -0,0 +1,19 @@
+# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+## Check that subtraction expressions emit R_LARCH_32_PCREL and R_LARCH_64_PCREL relocations.
+
+## TODO: 1- or 2-byte data relocations are not supported for now.
+
+.section sx
+x:
+nop
+
+.data
+.8byte x-.   # CHECK: 0x0 R_LARCH_64_PCREL sx 0x0
+.8byte y-.   # CHECK: 0x8 R_LARCH_64_PCREL sy 0x0
+.4byte x-.   # CHECK: 0x10 R_LARCH_32_PCREL sx 0x0
+.4byte y-.   # CHECK: 0x14 R_LARCH_32_PCREL sy 0x0
+
+.section sy
+y:
Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -59,7 +59,7 @@
   case FK_Data_4:
     return IsPCRel ? ELF::R_LARCH_32_PCREL : ELF::R_LARCH_32;
   case FK_Data_8:
-    return ELF::R_LARCH_64;
+    return IsPCRel ? ELF::R_LARCH_64_PCREL : ELF::R_LARCH_64;
   case LoongArch::fixup_loongarch_b16:
     return ELF::R_LARCH_B16;
   case LoongArch::fixup_loongarch_b21:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153872.534968.patch
Type: text/x-patch
Size: 1337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230627/a5a6dcd9/attachment.bin>


More information about the llvm-commits mailing list