[PATCH] D43158: [RISCV] Always emit a symbol for R_RISCV_PCREL_LO12_I.
Michael Spencer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 10 03:21:06 PST 2018
Bigcheese created this revision.
Bigcheese added reviewers: ahmedcharles, asb.
Herald added subscribers: kito-cheng, niosHD, sabuasal, apazos, jordy.potman.lists, simoncook, johnrusso, rbar.
riscv-ld mislinks if a section relative symbol is used instead.
I've reported this as a bug
(https://github.com/riscv/riscv-binutils-gdb/issues/138), but it may be
defined as requiring a symbol.
Depends on: https://reviews.llvm.org/D43157
https://reviews.llvm.org/D43158
Files:
lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
test/MC/RISCV/pcrel-hilo.s
Index: test/MC/RISCV/pcrel-hilo.s
===================================================================
--- test/MC/RISCV/pcrel-hilo.s
+++ test/MC/RISCV/pcrel-hilo.s
@@ -16,4 +16,4 @@
# CHECK-INSTR: addi t1, t1, 0
# CHECK-REL: 0x0 R_RISCV_PCREL_HI20 foo 0x0
-# CHECK-REL: 0x4 R_RISCV_PCREL_LO12_I .text 0x0
+# CHECK-REL: 0x4 R_RISCV_PCREL_LO12_I .Ltmp0 0x0
Index: lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
===================================================================
--- lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
+++ lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
@@ -23,6 +23,9 @@
~RISCVELFObjectWriter() override;
+ bool needsRelocateWithSymbol(const MCSymbol &Sym,
+ unsigned Type) const override;
+
protected:
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
@@ -35,6 +38,13 @@
RISCVELFObjectWriter::~RISCVELFObjectWriter() {}
+bool RISCVELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
+ unsigned Type) const {
+ // riscv-ld depends on R_RISCV_PCREL_LO12_I directly targetting a symbol.
+ // See https://github.com/riscv/riscv-binutils-gdb/issues/138
+ return Type == ELF::R_RISCV_PCREL_LO12_I;
+}
+
unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
const MCValue &Target,
const MCFixup &Fixup,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43158.133747.patch
Type: text/x-patch
Size: 1546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180210/90630725/attachment.bin>
More information about the llvm-commits
mailing list