[PATCH] D127549: RISCV: handle 64-bit PCREL data relocations
Saleem Abdulrasool via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 14:39:55 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1582bcd0038d: RISCV: handle 64-bit PCREL data relocations (authored by compnerd).
Changed prior to commit:
https://reviews.llvm.org/D127549?vs=436887&id=436950#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127549/new/
https://reviews.llvm.org/D127549
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
llvm/test/MC/RISCV/riscv64-64b-pcrel.s
Index: llvm/test/MC/RISCV/riscv64-64b-pcrel.s
===================================================================
--- /dev/null
+++ llvm/test/MC/RISCV/riscv64-64b-pcrel.s
@@ -0,0 +1,37 @@
+# RUN: llvm-mc -triple riscv64-unknown-linux-gnu -filetype obj -o - %s \
+# RUN: | llvm-readobj -r - | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK: .relasx {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 y 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 x 0x0
+# CHECK: }
+# CHECK: .relasy {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 x 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 y 0x0
+# CHECK: }
+# CHECK: .relasz {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 z 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 a 0x0
+# CHECK: }
+# CHECK: .relasa {
+# CHECK-NEXT: 0x0 R_RISCV_ADD64 a 0x0
+# CHECK-NEXT: 0x0 R_RISCV_SUB64 z 0x0
+# CHECK: }
+# CHECK: ]
+
+ .section sx,"aw", at progbits
+x:
+ .quad y-x
+
+ .section sy,"aw", at progbits
+y:
+ .quad x-y
+
+ .section sz
+z:
+ .quad z-a
+
+ .section sa
+a:
+ .quad a-z
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -207,6 +207,10 @@
static bool requiresFixups(MCContext &C, const MCExpr *Value,
const MCExpr *&LHS, const MCExpr *&RHS) {
+ auto IsMetadataOrEHFrameSection = [](const MCSection &S) -> bool {
+ return S.getKind().isMetadata() || S.getName() == ".eh_frame";
+ };
+
const auto *MBE = dyn_cast<MCBinaryExpr>(Value);
if (MBE == nullptr)
return false;
@@ -225,10 +229,15 @@
MCConstantExpr::create(E.getConstant(), C), C);
RHS = E.getSymB();
- return (A.isInSection() ? A.getSection().hasInstructions()
- : !A.getName().empty()) ||
- (B.isInSection() ? B.getSection().hasInstructions()
- : !B.getName().empty());
+ // TODO: when available, R_RISCV_n_PCREL should be preferred.
+
+ // Avoid pairwise relocations for symbolic difference in debug and .eh_frame
+ if (A.isInSection())
+ return !IsMetadataOrEHFrameSection(A.getSection());
+ if (B.isInSection())
+ return !IsMetadataOrEHFrameSection(B.getSection());
+ // as well as for absolute symbols.
+ return !A.getName().empty() || !B.getName().empty();
}
void reset() override {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127549.436950.patch
Type: text/x-patch
Size: 2456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220614/96ca092f/attachment.bin>
More information about the llvm-commits
mailing list