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, 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