[PATCH] D60657: [RISCV] Fix evaluation of %pcrel_lo
Roger Ferrer Ibanez via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 00:49:19 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41449c58c58e: [RISCV] Fix evaluation of %pcrel_lo (authored by rogfer01).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60657/new/
https://reviews.llvm.org/D60657
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/test/MC/RISCV/pcrel-fixups.s
Index: llvm/test/MC/RISCV/pcrel-fixups.s
===================================================================
--- /dev/null
+++ llvm/test/MC/RISCV/pcrel-fixups.s
@@ -0,0 +1,52 @@
+# RUN: llvm-mc -triple riscv32 -mattr=-relax -filetype obj %s \
+# RUN: | llvm-objdump -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix NORELAX %s
+# RUN: llvm-mc -triple riscv32 -mattr=+relax -filetype obj %s \
+# RUN: | llvm-objdump -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix RELAX %s
+# RUN: llvm-mc -triple riscv64 -mattr=-relax -filetype obj %s \
+# RUN: | llvm-objdump -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix NORELAX %s
+# RUN: llvm-mc -triple riscv64 -mattr=+relax -filetype obj %s \
+# RUN: | llvm-objdump -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix RELAX %s
+
+# Fixups for %pcrel_hi / %pcrel_lo can be evaluated within a section,
+# regardless of the fragment containing the target address.
+
+function:
+.Lpcrel_label1:
+ auipc a0, %pcrel_hi(other_function)
+ addi a1, a0, %pcrel_lo(.Lpcrel_label1)
+# NORELAX: auipc a0, 0
+# NORELAX-NOT: R_RISCV
+# NORELAX: addi a1, a0, 16
+# NORELAX-NOT: R_RISCV
+
+# RELAX: auipc a0, 0
+# RELAX: R_RISCV_PCREL_HI20 other_function
+# RELAX: R_RISCV_RELAX *ABS*
+# RELAX: addi a1, a0, 0
+# RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label1
+# RELAX: R_RISCV_RELAX *ABS*
+
+ .p2align 2 # Cause a new fragment be emitted here
+.Lpcrel_label2:
+ auipc a0, %pcrel_hi(other_function)
+ addi a1, a0, %pcrel_lo(.Lpcrel_label2)
+# NORELAX: auipc a0, 0
+# NORELAX-NOT: R_RISCV
+# NORELAX: addi a1, a0, 8
+# NORELAX-NOT: R_RISCV
+
+# RELAX: auipc a0, 0
+# RELAX: R_RISCV_PCREL_HI20 other_function
+# RELAX: R_RISCV_RELAX *ABS*
+# RELAX: addi a1, a0, 0
+# RELAX: R_RISCV_PCREL_LO12_I .Lpcrel_label2
+# RELAX: R_RISCV_RELAX *ABS*
+
+ .type other_function, at function
+other_function:
+ ret
+
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -64,11 +64,15 @@
case RISCV::fixup_riscv_tls_gd_hi20:
ShouldForce = true;
break;
- case RISCV::fixup_riscv_pcrel_hi20:
- ShouldForce = T->getValue()->findAssociatedFragment() !=
- Fixup.getValue()->findAssociatedFragment();
+ case RISCV::fixup_riscv_pcrel_hi20: {
+ MCFragment *TFragment = T->getValue()->findAssociatedFragment();
+ MCFragment *FixupFragment = Fixup.getValue()->findAssociatedFragment();
+ assert(FixupFragment && "We should have a fragment for this fixup");
+ ShouldForce =
+ !TFragment || TFragment->getParent() != FixupFragment->getParent();
break;
}
+ }
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60657.228377.patch
Type: text/x-patch
Size: 2820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191108/040c7acf/attachment.bin>
More information about the llvm-commits
mailing list