Skip to content

Commit 6f81e6b

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd2a26af21034' from apple/master into swift/master-next
2 parents 4daeff3 + d2a26af commit 6f81e6b

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
6464
case RISCV::fixup_riscv_tls_gd_hi20:
6565
ShouldForce = true;
6666
break;
67-
case RISCV::fixup_riscv_pcrel_hi20:
68-
ShouldForce = T->getValue()->findAssociatedFragment() !=
69-
Fixup.getValue()->findAssociatedFragment();
67+
case RISCV::fixup_riscv_pcrel_hi20: {
68+
MCFragment *TFragment = T->getValue()->findAssociatedFragment();
69+
MCFragment *FixupFragment = Fixup.getValue()->findAssociatedFragment();
70+
assert(FixupFragment && "We should have a fragment for this fixup");
71+
ShouldForce =
72+
!TFragment || TFragment->getParent() != FixupFragment->getParent();
7073
break;
7174
}
75+
}
7276
break;
7377
}
7478

llvm/test/MC/RISCV/pcrel-fixups.s

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# RUN: llvm-mc -triple riscv32 -mattr=-relax -filetype obj %s \
2+
# RUN: | llvm-objdump -M no-aliases -d -r - \
3+
# RUN: | FileCheck --check-prefix NORELAX %s
4+
# RUN: llvm-mc -triple riscv32 -mattr=+relax -filetype obj %s \
5+
# RUN: | llvm-objdump -M no-aliases -d -r - \
6+
# RUN: | FileCheck --check-prefix RELAX %s
7+
# RUN: llvm-mc -triple riscv64 -mattr=-relax -filetype obj %s \
8+
# RUN: | llvm-objdump -M no-aliases -d -r - \
9+
# RUN: | FileCheck --check-prefix NORELAX %s
10+
# RUN: llvm-mc -triple riscv64 -mattr=+relax -filetype obj %s \
11+
# RUN: | llvm-objdump -M no-aliases -d -r - \
12+
# RUN: | FileCheck --check-prefix RELAX %s
13+
14+
# Fixups for %pcrel_hi / %pcrel_lo can be evaluated within a section,
15+
# regardless of the fragment containing the target address.
16+
17+
function:
18+
.Lpcrel_label1:
19+
auipc a0, %pcrel_hi(other_function)
20+
addi a1, a0, %pcrel_lo(.Lpcrel_label1)
21+
# NORELAX: auipc a0, 0
22+
# NORELAX-NOT: R_RISCV
23+
# NORELAX: addi a1, a0, 16
24+
# NORELAX-NOT: R_RISCV
25+
26+
# RELAX: auipc a0, 0
27+
# RELAX: R_RISCV_PCREL_HI20 other_function
28+
# RELAX: R_RISCV_RELAX *ABS*
29+
# RELAX: addi a1, a0, 0
30+
# RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label1
31+
# RELAX: R_RISCV_RELAX *ABS*
32+
33+
.p2align 2 # Cause a new fragment be emitted here
34+
.Lpcrel_label2:
35+
auipc a0, %pcrel_hi(other_function)
36+
addi a1, a0, %pcrel_lo(.Lpcrel_label2)
37+
# NORELAX: auipc a0, 0
38+
# NORELAX-NOT: R_RISCV
39+
# NORELAX: addi a1, a0, 8
40+
# NORELAX-NOT: R_RISCV
41+
42+
# RELAX: auipc a0, 0
43+
# RELAX: R_RISCV_PCREL_HI20 other_function
44+
# RELAX: R_RISCV_RELAX *ABS*
45+
# RELAX: addi a1, a0, 0
46+
# RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label2
47+
# RELAX: R_RISCV_RELAX *ABS*
48+
49+
.type other_function,@function
50+
other_function:
51+
ret
52+

0 commit comments

Comments
 (0)