[llvm] 42cb3c6 - [LoongArch] Emit R_LARCH_64_PCREL relocation for FK_Data_8 when IsPCRel is true
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 20:17:17 PDT 2023
Author: Weining Lu
Date: 2023-06-29T11:16:54+08:00
New Revision: 42cb3c6346fcd2799060189e399a5b494687f40b
URL: https://github.com/llvm/llvm-project/commit/42cb3c6346fcd2799060189e399a5b494687f40b
DIFF: https://github.com/llvm/llvm-project/commit/42cb3c6346fcd2799060189e399a5b494687f40b.diff
LOG: [LoongArch] Emit R_LARCH_64_PCREL relocation for FK_Data_8 when IsPCRel is true
Reviewed By: xen0n, MaskRay, hev
Differential Revision: https://reviews.llvm.org/D153872
Added:
llvm/test/MC/LoongArch/Relocations/sub-expr.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 57330dd31f710..a6b9c0652639f 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -59,7 +59,7 @@ unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx,
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:
diff --git a/llvm/test/MC/LoongArch/Relocations/sub-expr.s b/llvm/test/MC/LoongArch/Relocations/sub-expr.s
new file mode 100644
index 0000000000000..0179e1027af8f
--- /dev/null
+++ b/llvm/test/MC/LoongArch/Relocations/sub-expr.s
@@ -0,0 +1,28 @@
+# 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.
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section ({{.*}}) .rela.data {
+# CHECK-NEXT: 0x0 R_LARCH_64_PCREL sx 0x0
+# CHECK-NEXT: 0x8 R_LARCH_64_PCREL sy 0x0
+# CHECK-NEXT: 0x10 R_LARCH_32_PCREL sx 0x0
+# CHECK-NEXT: 0x14 R_LARCH_32_PCREL sy 0x0
+# CHECK-NEXT: }
+
+.section sx,"a"
+x:
+nop
+
+.data
+.8byte x-.
+.8byte y-.
+.4byte x-.
+.4byte y-.
+
+.section sy,"a"
+y:
+nop
More information about the llvm-commits
mailing list