Skip to content

Commit 42cb3c6

Browse files
committed
[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
1 parent 02f94a6 commit 42cb3c6

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx,
5959
case FK_Data_4:
6060
return IsPCRel ? ELF::R_LARCH_32_PCREL : ELF::R_LARCH_32;
6161
case FK_Data_8:
62-
return ELF::R_LARCH_64;
62+
return IsPCRel ? ELF::R_LARCH_64_PCREL : ELF::R_LARCH_64;
6363
case LoongArch::fixup_loongarch_b16:
6464
return ELF::R_LARCH_B16;
6565
case LoongArch::fixup_loongarch_b21:
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t
2+
# RUN: llvm-readobj -r %t | FileCheck %s
3+
4+
## Check that subtraction expressions emit R_LARCH_32_PCREL and R_LARCH_64_PCREL relocations.
5+
6+
## TODO: 1- or 2-byte data relocations are not supported for now.
7+
8+
# CHECK: Relocations [
9+
# CHECK-NEXT: Section ({{.*}}) .rela.data {
10+
# CHECK-NEXT: 0x0 R_LARCH_64_PCREL sx 0x0
11+
# CHECK-NEXT: 0x8 R_LARCH_64_PCREL sy 0x0
12+
# CHECK-NEXT: 0x10 R_LARCH_32_PCREL sx 0x0
13+
# CHECK-NEXT: 0x14 R_LARCH_32_PCREL sy 0x0
14+
# CHECK-NEXT: }
15+
16+
.section sx,"a"
17+
x:
18+
nop
19+
20+
.data
21+
.8byte x-.
22+
.8byte y-.
23+
.4byte x-.
24+
.4byte y-.
25+
26+
.section sy,"a"
27+
y:
28+
nop

0 commit comments

Comments
 (0)