Index: lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h =================================================================== --- lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h +++ lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h @@ -11,6 +11,7 @@ #include "MCTargetDesc/RISCVFixupKinds.h" #include "MCTargetDesc/RISCVMCTargetDesc.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCFixupKindInfo.h" #include "llvm/MC/MCSubtargetInfo.h" @@ -22,6 +23,7 @@ class RISCVAsmBackend : public MCAsmBackend { const MCSubtargetInfo &STI; + SmallSet ResolvedPCRelHiFixups; uint8_t OSABI; bool Is64Bit; bool ForceRelocs = false; Index: lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp =================================================================== --- lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -36,10 +36,13 @@ case RISCV::fixup_riscv_tls_got_hi20: case RISCV::fixup_riscv_tls_gd_hi20: return true; + case RISCV::fixup_riscv_pcrel_hi20: + ResolvedPCRelHiFixups.insert(&Fixup); + break; case RISCV::fixup_riscv_pcrel_lo12_i: case RISCV::fixup_riscv_pcrel_lo12_s: - // For pcrel_lo12, force a relocation if the target of the corresponding - // pcrel_hi20 is not in the same fragment or if the target is something + // For pcrel_lo12, force a relocation if the corresponding pcrel_hi20 hasn't + // already been resolved without a relocation or if the target is something // other than a pcrel_hi20 (such as a got_hi20).. const MCFixup *T = cast(Fixup.getValue())->getPCRelHiFixup(); if (!T) { @@ -58,8 +61,8 @@ ShouldForce = true; break; case RISCV::fixup_riscv_pcrel_hi20: - ShouldForce = T->getValue()->findAssociatedFragment() != - Fixup.getValue()->findAssociatedFragment(); + if (ResolvedPCRelHiFixups.count(T) == 0) + ShouldForce = true; break; } break; Index: test/MC/RISCV/fixups.s =================================================================== --- test/MC/RISCV/fixups.s +++ test/MC/RISCV/fixups.s @@ -24,6 +24,8 @@ # CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_s # CHECK-INSTR: sw a0, 1656(t1) +# Create a new fragment boundary here. +.align 0 1: auipc t1, %pcrel_hi(.LBB0) # CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_hi(.LBB0), kind: fixup_riscv_pcrel_hi20