[llvm] [RISCV] Simplify fixup kinds that force relocations (PR #136088)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 21:33:33 PDT 2025


https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/136088

>From 5b29a842786f2dc6157ef5df9883a82b9eae85da Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 16 Apr 2025 23:41:07 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/include/llvm/MC/MCFixup.h                |  4 ++
 llvm/lib/MC/MCAsmStreamer.cpp                 | 12 +++-
 llvm/lib/MC/MCAssembler.cpp                   |  2 +-
 .../RISCV/MCTargetDesc/RISCVAsmBackend.cpp    | 61 ++++++-------------
 .../RISCV/MCTargetDesc/RISCVAsmBackend.h      |  6 +-
 .../MCTargetDesc/RISCVELFObjectWriter.cpp     | 38 ++----------
 .../RISCV/MCTargetDesc/RISCVFixupKinds.h      | 31 ----------
 .../RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp | 35 ++++++-----
 .../Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp | 23 ++++---
 llvm/test/MC/RISCV/linker-relaxation.s        | 36 +++++------
 llvm/test/MC/RISCV/option-exact.s             |  6 +-
 llvm/test/MC/RISCV/relocations.s              | 38 +-----------
 12 files changed, 91 insertions(+), 201 deletions(-)

diff --git a/llvm/include/llvm/MC/MCFixup.h b/llvm/include/llvm/MC/MCFixup.h
index f27ddeae8b173..2f2717d689049 100644
--- a/llvm/include/llvm/MC/MCFixup.h
+++ b/llvm/include/llvm/MC/MCFixup.h
@@ -89,6 +89,10 @@ class MCFixup {
     FI.Loc = Loc;
     return FI;
   }
+  static MCFixup create(uint32_t Offset, const MCExpr *Value, unsigned Kind,
+                        SMLoc Loc = SMLoc()) {
+    return create(Offset, Value, MCFixupKind(Kind), Loc);
+  }
 
   MCFixupKind getKind() const { return Kind; }
 
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 9fb79d676f2c7..007e7f85fa7fd 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -27,8 +27,10 @@
 #include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCSymbolXCOFF.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Object/ELF.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
@@ -2399,12 +2401,16 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
 
   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
     MCFixup &F = Fixups[i];
-    const MCFixupKindInfo &Info =
-        getAssembler().getBackend().getFixupKindInfo(F.getKind());
     OS << "  fixup " << char('A' + i) << " - "
        << "offset: " << F.getOffset() << ", value: ";
     F.getValue()->print(OS, MAI);
-    OS << ", kind: " << Info.Name << "\n";
+    OS << ", kind: ";
+    auto Kind = F.getKind();
+    if (FirstRelocationKind <= Kind)
+      OS << "relocation";
+    else
+      OS << getAssembler().getBackend().getFixupKindInfo(Kind).Name;
+    OS << '\n';
   }
 }
 
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 4e925809d20b0..1b3e7dd4f4ceb 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -203,7 +203,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
   if (IsResolved) {
     auto TargetVal = Target;
     TargetVal.Cst = Value;
-    if (Fixup.getKind() >= FirstLiteralRelocationKind ||
+    if (Fixup.getKind() >= FirstRelocationKind ||
         getBackend().shouldForceRelocation(*this, Fixup, TargetVal, STI))
       IsResolved = false;
   }
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index b36b8bd3fb436..152e3835caf33 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -34,6 +34,14 @@ static cl::opt<bool> ULEB128Reloc(
     "riscv-uleb128-reloc", cl::init(true), cl::Hidden,
     cl::desc("Emit R_RISCV_SET_ULEB128/E_RISCV_SUB_ULEB128 if appropriate"));
 
+RISCVAsmBackend::RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI,
+                                 bool Is64Bit, const MCTargetOptions &Options)
+    : MCAsmBackend(llvm::endianness::little,
+                   FirstRelocationKind + ELF::R_RISCV_RELAX),
+      STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {
+  RISCVFeatures::validate(STI.getTargetTriple(), STI.getFeatureBits());
+}
+
 std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind(StringRef Name) const {
   if (STI.getTargetTriple().isOSBinFormatELF()) {
     unsigned Type;
@@ -71,27 +79,13 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
        MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
       {"fixup_riscv_pcrel_lo12_s", 0, 32,
        MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
-      {"fixup_riscv_got_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel},
-      {"fixup_riscv_tprel_hi20", 12, 20, 0},
-      {"fixup_riscv_tprel_lo12_i", 20, 12, 0},
-      {"fixup_riscv_tprel_lo12_s", 0, 32, 0},
-      {"fixup_riscv_tprel_add", 0, 0, 0},
-      {"fixup_riscv_tls_got_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel},
-      {"fixup_riscv_tls_gd_hi20", 12, 20, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_jal", 12, 20, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_branch", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_rvc_jump", 2, 11, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_rvc_branch", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_call", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_call_plt", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
-      {"fixup_riscv_relax", 0, 0, 0},
-      {"fixup_riscv_align", 0, 0, 0},
 
-      {"fixup_riscv_tlsdesc_hi20", 12, 20,
-       MCFixupKindInfo::FKF_IsPCRel | MCFixupKindInfo::FKF_IsTarget},
-      {"fixup_riscv_tlsdesc_load_lo12", 20, 12, 0},
-      {"fixup_riscv_tlsdesc_add_lo12", 20, 12, 0},
-      {"fixup_riscv_tlsdesc_call", 0, 0, 0},
       {"fixup_riscv_qc_e_branch", 0, 48, MCFixupKindInfo::FKF_IsPCRel},
       {"fixup_riscv_qc_e_32", 16, 32, 0},
       {"fixup_riscv_qc_abs20_u", 12, 20, 0},
@@ -100,9 +94,9 @@ RISCVAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
   static_assert((std::size(Infos)) == RISCV::NumTargetFixupKinds,
                 "Not all fixup kinds added to Infos array");
 
-  // Fixup kinds from .reloc directive are like R_RISCV_NONE. They
-  // do not require any extra processing.
-  if (Kind >= FirstLiteralRelocationKind)
+  // Fixup kinds from raw relocation types and .reloc directive are like
+  // R_RISCV_NONE. They do not require any extra processing.
+  if (Kind >= FirstRelocationKind)
     return MCAsmBackend::getFixupKindInfo(FK_NONE);
 
   if (Kind < FirstTargetFixupKind)
@@ -131,11 +125,6 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
     if (Target.isAbsolute())
       return false;
     break;
-  case RISCV::fixup_riscv_got_hi20:
-  case RISCV::fixup_riscv_tls_got_hi20:
-  case RISCV::fixup_riscv_tls_gd_hi20:
-  case RISCV::fixup_riscv_tlsdesc_hi20:
-    return true;
   }
 
   return STI->hasFeature(RISCV::FeatureRelax) || ForceRelocs;
@@ -456,11 +445,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
   switch (Fixup.getTargetKind()) {
   default:
     llvm_unreachable("Unknown fixup kind!");
-  case RISCV::fixup_riscv_got_hi20:
-  case RISCV::fixup_riscv_tls_got_hi20:
-  case RISCV::fixup_riscv_tls_gd_hi20:
-  case RISCV::fixup_riscv_tlsdesc_hi20:
-    llvm_unreachable("Relocation should be unconditionally forced\n");
   case FK_Data_1:
   case FK_Data_2:
   case FK_Data_4:
@@ -469,8 +453,6 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
     return Value;
   case RISCV::fixup_riscv_lo12_i:
   case RISCV::fixup_riscv_pcrel_lo12_i:
-  case RISCV::fixup_riscv_tprel_lo12_i:
-  case RISCV::fixup_riscv_tlsdesc_load_lo12:
     return Value & 0xfff;
   case RISCV::fixup_riscv_12_i:
     if (!isInt<12>(Value)) {
@@ -480,11 +462,9 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
     return Value & 0xfff;
   case RISCV::fixup_riscv_lo12_s:
   case RISCV::fixup_riscv_pcrel_lo12_s:
-  case RISCV::fixup_riscv_tprel_lo12_s:
     return (((Value >> 5) & 0x7f) << 25) | ((Value & 0x1f) << 7);
   case RISCV::fixup_riscv_hi20:
   case RISCV::fixup_riscv_pcrel_hi20:
-  case RISCV::fixup_riscv_tprel_hi20:
     // Add 1 if bit 11 is 1, to compensate for low 12 bits being negative.
     return ((Value + 0x800) >> 12) & 0xfffff;
   case RISCV::fixup_riscv_jal: {
@@ -602,7 +582,6 @@ bool RISCVAsmBackend::evaluateTargetFixup(
   switch (Fixup.getTargetKind()) {
   default:
     llvm_unreachable("Unexpected fixup kind!");
-  case RISCV::fixup_riscv_tlsdesc_hi20:
   case RISCV::fixup_riscv_pcrel_hi20:
     AUIPCFixup = &Fixup;
     AUIPCDF = DF;
@@ -642,7 +621,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(
   Value = Asm.getSymbolOffset(SA) + AUIPCTarget.getConstant();
   Value -= Asm.getFragmentOffset(*AUIPCDF) + AUIPCFixup->getOffset();
 
-  return !shouldForceRelocation(Asm, *AUIPCFixup, AUIPCTarget, STI);
+  return AUIPCFixup->getTargetKind() == RISCV::fixup_riscv_pcrel_hi20;
 }
 
 bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
@@ -680,12 +659,10 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
   }
   MCValue A = MCValue::get(Target.getAddSym(), nullptr, Target.getConstant());
   MCValue B = MCValue::get(Target.getSubSym());
-  auto FA = MCFixup::create(
-      Fixup.getOffset(), nullptr,
-      static_cast<MCFixupKind>(FirstLiteralRelocationKind + TA));
-  auto FB = MCFixup::create(
-      Fixup.getOffset(), nullptr,
-      static_cast<MCFixupKind>(FirstLiteralRelocationKind + TB));
+  auto FA = MCFixup::create(Fixup.getOffset(), nullptr,
+                            static_cast<MCFixupKind>(FirstRelocationKind + TA));
+  auto FB = MCFixup::create(Fixup.getOffset(), nullptr,
+                            static_cast<MCFixupKind>(FirstRelocationKind + TB));
   auto &Assembler = const_cast<MCAssembler &>(Asm);
   Asm.getWriter().recordRelocation(Assembler, &F, FA, A, FixedValueA);
   Asm.getWriter().recordRelocation(Assembler, &F, FB, B, FixedValueB);
@@ -699,7 +676,7 @@ void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
                                  bool IsResolved,
                                  const MCSubtargetInfo *STI) const {
   MCFixupKind Kind = Fixup.getKind();
-  if (Kind >= FirstLiteralRelocationKind)
+  if (Kind >= FirstRelocationKind)
     return;
   MCContext &Ctx = Asm.getContext();
   MCFixupKindInfo Info = getFixupKindInfo(Kind);
@@ -767,8 +744,8 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
   MCContext &Ctx = Asm.getContext();
   const MCExpr *Dummy = MCConstantExpr::create(0, Ctx);
   // Create fixup_riscv_align fixup.
-  MCFixup Fixup =
-      MCFixup::create(0, Dummy, MCFixupKind(RISCV::fixup_riscv_align), SMLoc());
+  MCFixup Fixup = MCFixup::create(
+      0, Dummy, FirstRelocationKind + ELF::R_RISCV_ALIGN, SMLoc());
 
   uint64_t FixedValue = 0;
   MCValue NopBytes = MCValue::get(Count);
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
index 5d585b4efc116..23c8c2ce0b314 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
@@ -30,11 +30,7 @@ class RISCVAsmBackend : public MCAsmBackend {
 
 public:
   RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit,
-                  const MCTargetOptions &Options)
-      : MCAsmBackend(llvm::endianness::little, RISCV::fixup_riscv_relax),
-        STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {
-    RISCVFeatures::validate(STI.getTargetTriple(), STI.getFeatureBits());
-  }
+                  const MCTargetOptions &Options);
   ~RISCVAsmBackend() override = default;
 
   void setForceRelocs() { ForceRelocs = true; }
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
index a0b92b6bb9651..4b32130499f94 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
@@ -51,7 +51,6 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
                                             const MCFixup &Fixup,
                                             bool IsPCRel) const {
   const MCExpr *Expr = Fixup.getValue();
-  // Determine the type of the relocation
   unsigned Kind = Fixup.getTargetKind();
   auto Spec = RISCVMCExpr::Specifier(Target.getSpecifier());
   switch (Spec) {
@@ -74,6 +73,11 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
     break;
   }
 
+  // Extract the relocation type from the fixup kind, after applying STT_TLS as
+  // needed.
+  if (Kind >= FirstRelocationKind)
+    return Kind - FirstRelocationKind;
+
   if (IsPCRel) {
     switch (Kind) {
     default:
@@ -88,20 +92,6 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
       return ELF::R_RISCV_PCREL_LO12_I;
     case RISCV::fixup_riscv_pcrel_lo12_s:
       return ELF::R_RISCV_PCREL_LO12_S;
-    case RISCV::fixup_riscv_got_hi20:
-      return ELF::R_RISCV_GOT_HI20;
-    case RISCV::fixup_riscv_tls_got_hi20:
-      return ELF::R_RISCV_TLS_GOT_HI20;
-    case RISCV::fixup_riscv_tls_gd_hi20:
-      return ELF::R_RISCV_TLS_GD_HI20;
-    case RISCV::fixup_riscv_tlsdesc_hi20:
-      return ELF::R_RISCV_TLSDESC_HI20;
-    case RISCV::fixup_riscv_tlsdesc_load_lo12:
-      return ELF::R_RISCV_TLSDESC_LOAD_LO12;
-    case RISCV::fixup_riscv_tlsdesc_add_lo12:
-      return ELF::R_RISCV_TLSDESC_ADD_LO12;
-    case RISCV::fixup_riscv_tlsdesc_call:
-      return ELF::R_RISCV_TLSDESC_CALL;
     case RISCV::fixup_riscv_jal:
       return ELF::R_RISCV_JAL;
     case RISCV::fixup_riscv_branch:
@@ -125,12 +115,6 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
   default:
     Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
     return ELF::R_RISCV_NONE;
-  case RISCV::fixup_riscv_tlsdesc_load_lo12:
-    return ELF::R_RISCV_TLSDESC_LOAD_LO12;
-  case RISCV::fixup_riscv_tlsdesc_add_lo12:
-    return ELF::R_RISCV_TLSDESC_ADD_LO12;
-  case RISCV::fixup_riscv_tlsdesc_call:
-    return ELF::R_RISCV_TLSDESC_CALL;
 
   case FK_Data_1:
     Ctx.reportError(Fixup.getLoc(), "1-byte data relocations not supported");
@@ -160,18 +144,6 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
     return ELF::R_RISCV_LO12_I;
   case RISCV::fixup_riscv_lo12_s:
     return ELF::R_RISCV_LO12_S;
-  case RISCV::fixup_riscv_tprel_hi20:
-    return ELF::R_RISCV_TPREL_HI20;
-  case RISCV::fixup_riscv_tprel_lo12_i:
-    return ELF::R_RISCV_TPREL_LO12_I;
-  case RISCV::fixup_riscv_tprel_lo12_s:
-    return ELF::R_RISCV_TPREL_LO12_S;
-  case RISCV::fixup_riscv_tprel_add:
-    return ELF::R_RISCV_TPREL_ADD;
-  case RISCV::fixup_riscv_relax:
-    return ELF::R_RISCV_RELAX;
-  case RISCV::fixup_riscv_align:
-    return ELF::R_RISCV_ALIGN;
   case RISCV::fixup_riscv_qc_e_32:
     return ELF::R_RISCV_QC_E_32;
   case RISCV::fixup_riscv_qc_abs20_u:
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
index 596c4eb5fffaa..80fbed8d10f99 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVFixupKinds.h
@@ -32,25 +32,6 @@ enum Fixups {
   // 12-bit fixup corresponding to %pcrel_lo(foo) for the S-type store
   // instructions
   fixup_riscv_pcrel_lo12_s,
-  // 20-bit fixup corresponding to %got_pcrel_hi(foo) for instructions like
-  // auipc
-  fixup_riscv_got_hi20,
-  // 20-bit fixup corresponding to %tprel_hi(foo) for instructions like lui
-  fixup_riscv_tprel_hi20,
-  // 12-bit fixup corresponding to %tprel_lo(foo) for instructions like addi
-  fixup_riscv_tprel_lo12_i,
-  // 12-bit fixup corresponding to %tprel_lo(foo) for the S-type store
-  // instructions
-  fixup_riscv_tprel_lo12_s,
-  // Fixup corresponding to %tprel_add(foo) for PseudoAddTPRel, used as a linker
-  // hint
-  fixup_riscv_tprel_add,
-  // 20-bit fixup corresponding to %tls_ie_pcrel_hi(foo) for instructions like
-  // auipc
-  fixup_riscv_tls_got_hi20,
-  // 20-bit fixup corresponding to %tls_gd_pcrel_hi(foo) for instructions like
-  // auipc
-  fixup_riscv_tls_gd_hi20,
   // 20-bit fixup for symbol references in the jal instruction
   fixup_riscv_jal,
   // 12-bit fixup for symbol references in the branch instructions
@@ -65,18 +46,6 @@ enum Fixups {
   // Fixup representing a function call attached to the auipc instruction in a
   // pair composed of adjacent auipc+jalr instructions.
   fixup_riscv_call_plt,
-  // Used to generate an R_RISCV_RELAX relocation, which indicates the linker
-  // may relax the instruction pair.
-  fixup_riscv_relax,
-  // Used to generate an R_RISCV_ALIGN relocation, which indicates the linker
-  // should fixup the alignment after linker relaxation.
-  fixup_riscv_align,
-  // Fixups indicating a TLS descriptor code sequence, corresponding to auipc,
-  // lw/ld, addi, and jalr, respectively.
-  fixup_riscv_tlsdesc_hi20,
-  fixup_riscv_tlsdesc_load_lo12,
-  fixup_riscv_tlsdesc_add_lo12,
-  fixup_riscv_tlsdesc_call,
   // 12-bit fixup for symbol references in the 48-bit Xqcibi branch immediate
   // instructions
   fixup_riscv_qc_e_branch,
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
index 6283f1d120aaa..8af769d295ae8 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
@@ -181,7 +181,7 @@ void RISCVMCCodeEmitter::expandTLSDESCCall(const MCInst &MI,
   MCRegister Dest = MI.getOperand(1).getReg();
   int64_t Imm = MI.getOperand(2).getImm();
   Fixups.push_back(MCFixup::create(
-      0, Expr, MCFixupKind(RISCV::fixup_riscv_tlsdesc_call), MI.getLoc()));
+      0, Expr, FirstRelocationKind + ELF::R_RISCV_TLSDESC_CALL, MI.getLoc()));
   MCInst Call =
       MCInstBuilder(RISCV::JALR).addReg(Link).addReg(Dest).addImm(Imm);
 
@@ -210,13 +210,13 @@ void RISCVMCCodeEmitter::expandAddTPRel(const MCInst &MI,
 
   // Emit the correct tprel_add relocation for the symbol.
   Fixups.push_back(MCFixup::create(
-      0, Expr, MCFixupKind(RISCV::fixup_riscv_tprel_add), MI.getLoc()));
+      0, Expr, FirstRelocationKind + ELF::R_RISCV_TPREL_ADD, MI.getLoc()));
 
-  // Emit fixup_riscv_relax for tprel_add where the relax feature is enabled.
+  // Emit R_RISCV_RELAX for tprel_add where the relax feature is enabled.
   if (STI.hasFeature(RISCV::FeatureRelax)) {
     const MCConstantExpr *Dummy = MCConstantExpr::create(0, Ctx);
     Fixups.push_back(MCFixup::create(
-        0, Dummy, MCFixupKind(RISCV::fixup_riscv_relax), MI.getLoc()));
+        0, Dummy, FirstRelocationKind + ELF::R_RISCV_RELAX, MI.getLoc()));
   }
 
   // Emit a normal ADD instruction with the given operands.
@@ -567,7 +567,7 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
          "getImmOpValue expects only expressions or immediates");
   const MCExpr *Expr = MO.getExpr();
   MCExpr::ExprKind Kind = Expr->getKind();
-  RISCV::Fixups FixupKind = RISCV::fixup_riscv_invalid;
+  unsigned FixupKind = RISCV::fixup_riscv_invalid;
   bool RelaxCandidate = false;
   if (Kind == MCExpr::Target) {
     const RISCVMCExpr *RVExpr = cast<RISCVMCExpr>(Expr);
@@ -612,26 +612,26 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
       RelaxCandidate = true;
       break;
     case RISCVMCExpr::VK_GOT_HI:
-      FixupKind = RISCV::fixup_riscv_got_hi20;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_GOT_HI20;
       break;
     case RISCVMCExpr::VK_TPREL_LO:
       if (MIFrm == RISCVII::InstFormatI)
-        FixupKind = RISCV::fixup_riscv_tprel_lo12_i;
+        FixupKind = FirstRelocationKind + ELF::R_RISCV_TPREL_LO12_I;
       else if (MIFrm == RISCVII::InstFormatS)
-        FixupKind = RISCV::fixup_riscv_tprel_lo12_s;
+        FixupKind = FirstRelocationKind + ELF::R_RISCV_TPREL_LO12_S;
       else
         llvm_unreachable("VK_TPREL_LO used with unexpected instruction format");
       RelaxCandidate = true;
       break;
     case RISCVMCExpr::VK_TPREL_HI:
-      FixupKind = RISCV::fixup_riscv_tprel_hi20;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TPREL_HI20;
       RelaxCandidate = true;
       break;
     case RISCVMCExpr::VK_TLS_GOT_HI:
-      FixupKind = RISCV::fixup_riscv_tls_got_hi20;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLS_GOT_HI20;
       break;
     case RISCVMCExpr::VK_TLS_GD_HI:
-      FixupKind = RISCV::fixup_riscv_tls_gd_hi20;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLS_GD_HI20;
       break;
     case RISCVMCExpr::VK_CALL:
       FixupKind = RISCV::fixup_riscv_call;
@@ -642,16 +642,16 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
       RelaxCandidate = true;
       break;
     case RISCVMCExpr::VK_TLSDESC_HI:
-      FixupKind = RISCV::fixup_riscv_tlsdesc_hi20;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLSDESC_HI20;
       break;
     case RISCVMCExpr::VK_TLSDESC_LOAD_LO:
-      FixupKind = RISCV::fixup_riscv_tlsdesc_load_lo12;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLSDESC_LOAD_LO12;
       break;
     case RISCVMCExpr::VK_TLSDESC_ADD_LO:
-      FixupKind = RISCV::fixup_riscv_tlsdesc_add_lo12;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLSDESC_ADD_LO12;
       break;
     case RISCVMCExpr::VK_TLSDESC_CALL:
-      FixupKind = RISCV::fixup_riscv_tlsdesc_call;
+      FixupKind = FirstRelocationKind + ELF::R_RISCV_TLSDESC_CALL;
       break;
     case RISCVMCExpr::VK_QC_ABS20:
       FixupKind = RISCV::fixup_riscv_qc_abs20_u;
@@ -689,9 +689,8 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
   // relaxed.
   if (EnableRelax && RelaxCandidate) {
     const MCConstantExpr *Dummy = MCConstantExpr::create(0, Ctx);
-    Fixups.push_back(
-    MCFixup::create(0, Dummy, MCFixupKind(RISCV::fixup_riscv_relax),
-                    MI.getLoc()));
+    Fixups.push_back(MCFixup::create(
+        0, Dummy, FirstRelocationKind + ELF::R_RISCV_RELAX, MI.getLoc()));
     ++MCNumFixups;
   }
 
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
index d6650e156c8b3..7c953f55a409a 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
@@ -67,17 +67,20 @@ const MCFixup *RISCVMCExpr::getPCRelHiFixup(const MCFragment **DFOut) const {
   for (const MCFixup &F : DF->getFixups()) {
     if (F.getOffset() != Offset)
       continue;
-
-    switch ((unsigned)F.getKind()) {
-    default:
-      continue;
-    case RISCV::fixup_riscv_got_hi20:
-    case RISCV::fixup_riscv_tls_got_hi20:
-    case RISCV::fixup_riscv_tls_gd_hi20:
-    case RISCV::fixup_riscv_pcrel_hi20:
-    case RISCV::fixup_riscv_tlsdesc_hi20:
-      if (DFOut)
+    auto Kind = F.getTargetKind();
+    if (Kind < FirstRelocationKind) {
+      if (Kind == RISCV::fixup_riscv_pcrel_hi20) {
         *DFOut = DF;
+        return &F;
+      }
+      break;
+    }
+    switch (Kind - FirstRelocationKind) {
+    case ELF::R_RISCV_GOT_HI20:
+    case ELF::R_RISCV_TLS_GOT_HI20:
+    case ELF::R_RISCV_TLS_GD_HI20:
+    case ELF::R_RISCV_TLSDESC_HI20:
+      *DFOut = DF;
       return &F;
     }
   }
diff --git a/llvm/test/MC/RISCV/linker-relaxation.s b/llvm/test/MC/RISCV/linker-relaxation.s
index 6d0a05fb4267f..fb57a441dc4b1 100644
--- a/llvm/test/MC/RISCV/linker-relaxation.s
+++ b/llvm/test/MC/RISCV/linker-relaxation.s
@@ -19,7 +19,7 @@ call foo
 # RELAX-RELOC: R_RISCV_CALL_PLT foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 lui t1, %hi(foo)
 # NORELAX-RELOC: R_RISCV_HI20 foo 0x0
@@ -27,7 +27,7 @@ lui t1, %hi(foo)
 # RELAX-RELOC: R_RISCV_HI20 foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 addi t1, t1, %lo(foo)
 # NORELAX-RELOC: R_RISCV_LO12_I foo 0x0
@@ -35,7 +35,7 @@ addi t1, t1, %lo(foo)
 # RELAX-RELOC: R_RISCV_LO12_I foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 sb t1, %lo(foo)(a2)
 # NORELAX-RELOC: R_RISCV_LO12_S foo 0x0
@@ -43,7 +43,7 @@ sb t1, %lo(foo)(a2)
 # RELAX-RELOC: R_RISCV_LO12_S foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 1:
 auipc t1, %pcrel_hi(foo)
@@ -52,7 +52,7 @@ auipc t1, %pcrel_hi(foo)
 # RELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 addi t1, t1, %pcrel_lo(1b)
 # NORELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
@@ -60,7 +60,7 @@ addi t1, t1, %pcrel_lo(1b)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 sb t1, %pcrel_lo(1b)(a2)
 # NORELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
@@ -68,7 +68,7 @@ sb t1, %pcrel_lo(1b)(a2)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 
 # Check behaviour when a locally defined symbol is referenced.
@@ -78,7 +78,7 @@ beq s1, s1, bar
 # NORELAX-RELOC-NOT: R_RISCV_BRANCH
 # RELAX-RELOC: R_RISCV_BRANCH bar 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_branch
-# RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: relocation
 
 call bar
 # NORELAX-RELOC-NOT: R_RISCV_CALL
@@ -86,7 +86,7 @@ call bar
 # RELAX-RELOC: R_RISCV_CALL_PLT bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_call
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 lui t1, %hi(bar)
 # NORELAX-RELOC: R_RISCV_HI20 bar 0x0
@@ -94,7 +94,7 @@ lui t1, %hi(bar)
 # RELAX-RELOC: R_RISCV_HI20 bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(bar), kind: fixup_riscv_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 addi t1, t1, %lo(bar)
 # NORELAX-RELOC: R_RISCV_LO12_I bar 0x0
@@ -102,7 +102,7 @@ addi t1, t1, %lo(bar)
 # RELAX-RELOC: R_RISCV_LO12_I bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 sb t1, %lo(bar)(a2)
 # NORELAX-RELOC: R_RISCV_LO12_S bar 0x0
@@ -110,7 +110,7 @@ sb t1, %lo(bar)(a2)
 # RELAX-RELOC: R_RISCV_LO12_S bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 2:
 auipc t1, %pcrel_hi(bar)
@@ -119,7 +119,7 @@ auipc t1, %pcrel_hi(bar)
 # RELAX-RELOC: R_RISCV_PCREL_HI20 bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(bar), kind: fixup_riscv_pcrel_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 addi t1, t1, %pcrel_lo(2b)
 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_I
@@ -127,7 +127,7 @@ addi t1, t1, %pcrel_lo(2b)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp1 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 sb t1, %pcrel_lo(2b)(a2)
 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_S
@@ -135,7 +135,7 @@ sb t1, %pcrel_lo(2b)(a2)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp1 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
 
 ## %hi/%lo on an absolute symbol (not yet defined) leads to relocations when relaxation is enabled.
 lui t2, %hi(abs)
@@ -143,14 +143,14 @@ lui t2, %hi(abs)
 # RELAX-RELOC:      R_RISCV_HI20 - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %hi(abs), kind: fixup_riscv_hi20
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
 
 addi t2, t2, %lo(abs)
 # NORELAX-RELOC-NOT: R_RISCV_
 # RELAX-RELOC:      R_RISCV_LO12_I - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %lo(abs), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
 
 .set abs, 0x12345
 
@@ -158,7 +158,7 @@ lui t3, %hi(abs)
 # RELAX-RELOC:      R_RISCV_HI20 - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %hi(74565), kind: fixup_riscv_hi20
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
 
 # Check that a relocation is not emitted for a symbol difference which has
 # been folded to a fixup with an absolute value. This can happen when a
diff --git a/llvm/test/MC/RISCV/option-exact.s b/llvm/test/MC/RISCV/option-exact.s
index f90bd00621c42..f2326dfc3187c 100644
--- a/llvm/test/MC/RISCV/option-exact.s
+++ b/llvm/test/MC/RISCV/option-exact.s
@@ -30,7 +30,7 @@ c.lw a0, 0(a0)
 # CHECK-ASM: call undefined
 # CHECK-ASM-SAME: # encoding: [0x97'A',A,A,A,0xe7'A',0x80'A',A,A]
 # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt
-# CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: relocation
 # CHECK-OBJDUMP: auipc ra, 0
 # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined
 # CHECK-OBJDUMP-NEXT: R_RISCV_RELAX *ABS*
@@ -68,7 +68,7 @@ c.lw a0, 0(a0)
 # CHECK-ASM: call undefined
 # CHECK-ASM-SAME: # encoding: [0x97'A',A,A,A,0xe7'A',0x80'A',A,A]
 # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt
-# CHECK-ASM-NOT: fixup_riscv_relax
+# CHECK-ASM-NOT: relocation
 # CHECK-OBJDUMP: auipc ra, 0
 # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined
 # CHECK-OBJDUMP-NOT: R_RISCV_RELAX
@@ -105,7 +105,7 @@ c.lw a0, 0(a0)
 # CHECK-ASM: call undefined
 # CHECK-ASM-SAME: # encoding: [0x97'A',A,A,A,0xe7'A',0x80'A',A,A]
 # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt
-# CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax
+# CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: relocation
 # CHECK-OBJDUMP: auipc ra, 0
 # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined
 # CHECK-OBJDUMP-NEXT: R_RISCV_RELAX *ABS*
diff --git a/llvm/test/MC/RISCV/relocations.s b/llvm/test/MC/RISCV/relocations.s
index 85a25fee118ed..aa85f85fb3b2a 100644
--- a/llvm/test/MC/RISCV/relocations.s
+++ b/llvm/test/MC/RISCV/relocations.s
@@ -1,11 +1,10 @@
 # RUN: llvm-mc -triple riscv32 -M no-aliases < %s -show-encoding \
-# RUN:     | FileCheck -check-prefix=INSTR -check-prefix=FIXUP %s
+# RUN:     | FileCheck -check-prefix=INSTR %s
 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \
 # RUN:     | llvm-readobj -r - | FileCheck -check-prefix=RELOC %s
 
 # Check prefixes:
 # RELOC - Check the relocation in the object.
-# FIXUP - Check the fixup on the instruction.
 # INSTR - Check the instruction is handled properly by the ASMPrinter
 
 .long foo
@@ -17,99 +16,80 @@
 lui t1, %hi(foo)
 # RELOC: R_RISCV_HI20 foo 0x0
 # INSTR: lui t1, %hi(foo)
-# FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20
 
 lui t1, %hi(foo+4)
 # RELOC: R_RISCV_HI20 foo 0x4
 # INSTR: lui t1, %hi(foo+4)
-# FIXUP: fixup A - offset: 0, value: %hi(foo+4), kind: fixup_riscv_hi20
 
 lui t1, %tprel_hi(foo)
 # RELOC: R_RISCV_TPREL_HI20 foo 0x0
 # INSTR: lui t1, %tprel_hi(foo)
-# FIXUP: fixup A - offset: 0, value: %tprel_hi(foo), kind: fixup_riscv_tprel_hi20
 
 lui t1, %tprel_hi(foo+4)
 # RELOC: R_RISCV_TPREL_HI20 foo 0x4
 # INSTR: lui t1, %tprel_hi(foo+4)
-# FIXUP: fixup A - offset: 0, value: %tprel_hi(foo+4), kind: fixup_riscv_tprel_hi20
 
 addi t1, t1, %lo(foo)
 # RELOC: R_RISCV_LO12_I foo 0x0
 # INSTR: addi t1, t1, %lo(foo)
-# FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i
 
 addi t1, t1, %lo(foo+4)
 # RELOC: R_RISCV_LO12_I foo 0x4
 # INSTR: addi t1, t1, %lo(foo+4)
-# FIXUP: fixup A - offset: 0, value: %lo(foo+4), kind: fixup_riscv_lo12_i
 
 addi t1, t1, %tprel_lo(foo)
 # RELOC: R_RISCV_TPREL_LO12_I foo 0x0
 # INSTR: addi t1, t1, %tprel_lo(foo)
-# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo), kind: fixup_riscv_tprel_lo12_i
 
 addi t1, t1, %tprel_lo(foo+4)
 # RELOC: R_RISCV_TPREL_LO12_I foo 0x4
 # INSTR: addi t1, t1, %tprel_lo(foo+4)
-# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo+4), kind: fixup_riscv_tprel_lo12_i
 
 sb t1, %lo(foo)(a2)
 # RELOC: R_RISCV_LO12_S foo 0x0
 # INSTR: sb t1, %lo(foo)(a2)
-# FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s
 
 sb t1, %lo(foo+4)(a2)
 # RELOC: R_RISCV_LO12_S foo 0x4
 # INSTR: sb t1, %lo(foo+4)(a2)
-# FIXUP: fixup A - offset: 0, value: %lo(foo+4), kind: fixup_riscv_lo12_s
 
 sb t1, %tprel_lo(foo)(a2)
 # RELOC: R_RISCV_TPREL_LO12_S foo 0x0
 # INSTR: sb t1, %tprel_lo(foo)(a2)
-# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo), kind: fixup_riscv_tprel_lo12_s
 
 sb t1, %tprel_lo(foo+4)(a2)
 # RELOC: R_RISCV_TPREL_LO12_S foo 0x4
 # INSTR: sb t1, %tprel_lo(foo+4)(a2)
-# FIXUP: fixup A - offset: 0, value: %tprel_lo(foo+4), kind: fixup_riscv_tprel_lo12_s
 
 .L0:
 auipc t1, %pcrel_hi(foo)
 # RELOC: R_RISCV_PCREL_HI20 foo 0x0
 # INSTR: auipc t1, %pcrel_hi(foo)
-# FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20
 
 auipc t1, %pcrel_hi(foo+4)
 # RELOC: R_RISCV_PCREL_HI20 foo 0x4
 # INSTR: auipc t1, %pcrel_hi(foo+4)
-# FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo+4), kind: fixup_riscv_pcrel_hi20
 
 addi t1, t1, %pcrel_lo(.L0)
 # RELOC: R_RISCV_PCREL_LO12_I .L0 0x0
 # INSTR: addi t1, t1, %pcrel_lo(.L0)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_i
 
 sb t1, %pcrel_lo(.L0)(a2)
 # RELOC: R_RISCV_PCREL_LO12_S .L0 0x0
 # INSTR: sb t1, %pcrel_lo(.L0)(a2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L0), kind: fixup_riscv_pcrel_lo12_s
 
 .L1:
 auipc t1, %got_pcrel_hi(foo)
 # RELOC: R_RISCV_GOT_HI20 foo 0x0
 # INSTR: auipc t1, %got_pcrel_hi(foo)
-# FIXUP: fixup A - offset: 0, value: %got_pcrel_hi(foo), kind: fixup_riscv_got_hi20
 
 addi t1, t1, %pcrel_lo(.L1)
 # RELOC: R_RISCV_PCREL_LO12_I .L1 0x0
 # INSTR: addi t1, t1, %pcrel_lo(.L1)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L1), kind: fixup_riscv_pcrel_lo12_i
 
 sb t1, %pcrel_lo(.L1)(a2)
 # RELOC: R_RISCV_PCREL_LO12_S .L1 0x0
 # INSTR: sb t1, %pcrel_lo(.L1)(a2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L1), kind: fixup_riscv_pcrel_lo12_s
 
 # Check that GOT relocations aren't evaluated to a constant when the symbol is
 # in the same object file.
@@ -117,83 +97,67 @@ sb t1, %pcrel_lo(.L1)(a2)
 auipc t1, %got_pcrel_hi(.L1)
 # RELOC: R_RISCV_GOT_HI20 .L1 0x0
 # INSTR: auipc t1, %got_pcrel_hi(.L1)
-# FIXUP: fixup A - offset: 0, value: %got_pcrel_hi(.L1), kind: fixup_riscv_got_hi20
 
 addi t1, t1, %pcrel_lo(.L2)
 # RELOC: R_RISCV_PCREL_LO12_I .L2 0x0
 # INSTR: addi t1, t1, %pcrel_lo(.L2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L2), kind: fixup_riscv_pcrel_lo12_i
 
 sb t1, %pcrel_lo(.L2)(a2)
 # RELOC: R_RISCV_PCREL_LO12_S .L2 0x0
 # INSTR: sb t1, %pcrel_lo(.L2)(a2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L2), kind: fixup_riscv_pcrel_lo12_s
 
 .L3:
 auipc t1, %tls_ie_pcrel_hi(foo)
 # RELOC: R_RISCV_TLS_GOT_HI20 foo 0x0
 # INSTR: auipc t1, %tls_ie_pcrel_hi(foo)
-# FIXUP: fixup A - offset: 0, value: %tls_ie_pcrel_hi(foo), kind: fixup_riscv_tls_got_hi20
 
 addi t1, t1, %pcrel_lo(.L3)
 # RELOC: R_RISCV_PCREL_LO12_I .L3 0x0
 # INSTR: addi t1, t1, %pcrel_lo(.L3)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_i
 
 sb t1, %pcrel_lo(.L3)(a2)
 # RELOC: R_RISCV_PCREL_LO12_S .L3 0x0
 # INSTR: sb t1, %pcrel_lo(.L3)(a2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L3), kind: fixup_riscv_pcrel_lo12_s
 
 .L4:
 auipc t1, %tls_gd_pcrel_hi(foo)
 # RELOC: R_RISCV_TLS_GD_HI20 foo 0x0
 # INSTR: auipc t1, %tls_gd_pcrel_hi(foo)
-# FIXUP: fixup A - offset: 0, value: %tls_gd_pcrel_hi(foo), kind: fixup_riscv_tls_gd_hi20
 
 addi t1, t1, %pcrel_lo(.L4)
 # RELOC: R_RISCV_PCREL_LO12_I .L4 0x0
 # INSTR: addi t1, t1, %pcrel_lo(.L4)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_i
 
 sb t1, %pcrel_lo(.L4)(a2)
 # RELOC: R_RISCV_PCREL_LO12_S .L4 0x0
 # INSTR: sb t1, %pcrel_lo(.L4)(a2)
-# FIXUP: fixup A - offset: 0, value: %pcrel_lo(.L4), kind: fixup_riscv_pcrel_lo12_s
 
 add t1, t1, tp, %tprel_add(foo)
 # RELOC: R_RISCV_TPREL_ADD foo 0x0
 # INSTR: add t1, t1, tp, %tprel_add(foo)
-# FIXUP: fixup A - offset: 0, value: %tprel_add(foo), kind: fixup_riscv_tprel_add
 
 jal zero, foo
 # RELOC: R_RISCV_JAL
 # INSTR: jal zero, foo
-# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_jal
 
 # Since foo is undefined, this will be relaxed to (bltu; jal)
 bgeu a0, a1, foo
 # RELOC: R_RISCV_JAL
 # INSTR: bgeu a0, a1, foo
-# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_branch
 
 .L5:
 auipc a0, %tlsdesc_hi(a_symbol)
 # RELOC: R_RISCV_TLSDESC_HI20
 # INSTR: auipc a0, %tlsdesc_hi(a_symbol)
-# FIXUP: fixup A - offset: 0, value: %tlsdesc_hi(a_symbol), kind: fixup_riscv_tlsdesc_hi20
 
 lw a1, %tlsdesc_load_lo(.L5)(a0)
 # RELOC: R_RISCV_TLSDESC_LOAD_LO12
 # INSTR: lw a1, %tlsdesc_load_lo(.L5)(a0)
-# FIXUP: fixup A - offset: 0, value: %tlsdesc_load_lo(.L5), kind: fixup_riscv_tlsdesc_load_lo12
 
 addi a0, a0, %tlsdesc_add_lo(.L5)
 # RELOC: R_RISCV_TLSDESC_ADD_LO12
 # INSTR: addi a0, a0, %tlsdesc_add_lo(.L5)
-# FIXUP: fixup A - offset: 0, value: %tlsdesc_add_lo(.L5), kind: fixup_riscv_tlsdesc_add_lo12
 
 jalr t0, 0(a1), %tlsdesc_call(.L5)
 # RELOC: R_RISCV_TLSDESC_CALL
 # INSTR: jalr t0, 0(a1), %tlsdesc_call(.L5)
-# FIXUP: fixup A - offset: 0, value: %tlsdesc_call(.L5), kind: fixup_riscv_tlsdesc_call

>From f5818365a06ad951b8998d9421a5984eb84f00f2 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 17 Apr 2025 09:58:18 -0700
Subject: [PATCH 2/2] show relocation type number

Created using spr 1.3.5-bogner
---
 llvm/lib/MC/MCAsmStreamer.cpp                 |  2 +-
 .../RISCV/MCTargetDesc/RISCVAsmBackend.cpp    |  8 ++---
 llvm/test/MC/RISCV/linker-relaxation.s        | 36 +++++++++----------
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 007e7f85fa7fd..7596bc3aad4b5 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -2407,7 +2407,7 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
     OS << ", kind: ";
     auto Kind = F.getKind();
     if (FirstRelocationKind <= Kind)
-      OS << "relocation";
+      OS << "relocation type " << (Kind - FirstRelocationKind);
     else
       OS << getAssembler().getBackend().getFixupKindInfo(Kind).Name;
     OS << '\n';
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 152e3835caf33..f9799a062c95e 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -659,10 +659,10 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
   }
   MCValue A = MCValue::get(Target.getAddSym(), nullptr, Target.getConstant());
   MCValue B = MCValue::get(Target.getSubSym());
-  auto FA = MCFixup::create(Fixup.getOffset(), nullptr,
-                            static_cast<MCFixupKind>(FirstRelocationKind + TA));
-  auto FB = MCFixup::create(Fixup.getOffset(), nullptr,
-                            static_cast<MCFixupKind>(FirstRelocationKind + TB));
+  auto FA =
+      MCFixup::create(Fixup.getOffset(), nullptr, FirstRelocationKind + TA);
+  auto FB =
+      MCFixup::create(Fixup.getOffset(), nullptr, FirstRelocationKind + TB);
   auto &Assembler = const_cast<MCAssembler &>(Asm);
   Asm.getWriter().recordRelocation(Assembler, &F, FA, A, FixedValueA);
   Asm.getWriter().recordRelocation(Assembler, &F, FB, B, FixedValueB);
diff --git a/llvm/test/MC/RISCV/linker-relaxation.s b/llvm/test/MC/RISCV/linker-relaxation.s
index fb57a441dc4b1..7af01cedf0aeb 100644
--- a/llvm/test/MC/RISCV/linker-relaxation.s
+++ b/llvm/test/MC/RISCV/linker-relaxation.s
@@ -19,7 +19,7 @@ call foo
 # RELAX-RELOC: R_RISCV_CALL_PLT foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 lui t1, %hi(foo)
 # NORELAX-RELOC: R_RISCV_HI20 foo 0x0
@@ -27,7 +27,7 @@ lui t1, %hi(foo)
 # RELAX-RELOC: R_RISCV_HI20 foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(foo), kind: fixup_riscv_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 addi t1, t1, %lo(foo)
 # NORELAX-RELOC: R_RISCV_LO12_I foo 0x0
@@ -35,7 +35,7 @@ addi t1, t1, %lo(foo)
 # RELAX-RELOC: R_RISCV_LO12_I foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 sb t1, %lo(foo)(a2)
 # NORELAX-RELOC: R_RISCV_LO12_S foo 0x0
@@ -43,7 +43,7 @@ sb t1, %lo(foo)(a2)
 # RELAX-RELOC: R_RISCV_LO12_S foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(foo), kind: fixup_riscv_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 1:
 auipc t1, %pcrel_hi(foo)
@@ -52,7 +52,7 @@ auipc t1, %pcrel_hi(foo)
 # RELAX-RELOC: R_RISCV_PCREL_HI20 foo 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(foo), kind: fixup_riscv_pcrel_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 addi t1, t1, %pcrel_lo(1b)
 # NORELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
@@ -60,7 +60,7 @@ addi t1, t1, %pcrel_lo(1b)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp0 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 sb t1, %pcrel_lo(1b)(a2)
 # NORELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
@@ -68,7 +68,7 @@ sb t1, %pcrel_lo(1b)(a2)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp0 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp0), kind: fixup_riscv_pcrel_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 
 # Check behaviour when a locally defined symbol is referenced.
@@ -78,7 +78,7 @@ beq s1, s1, bar
 # NORELAX-RELOC-NOT: R_RISCV_BRANCH
 # RELAX-RELOC: R_RISCV_BRANCH bar 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_branch
-# RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP-NOT: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 call bar
 # NORELAX-RELOC-NOT: R_RISCV_CALL
@@ -86,7 +86,7 @@ call bar
 # RELAX-RELOC: R_RISCV_CALL_PLT bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: bar, kind: fixup_riscv_call
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 lui t1, %hi(bar)
 # NORELAX-RELOC: R_RISCV_HI20 bar 0x0
@@ -94,7 +94,7 @@ lui t1, %hi(bar)
 # RELAX-RELOC: R_RISCV_HI20 bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %hi(bar), kind: fixup_riscv_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 addi t1, t1, %lo(bar)
 # NORELAX-RELOC: R_RISCV_LO12_I bar 0x0
@@ -102,7 +102,7 @@ addi t1, t1, %lo(bar)
 # RELAX-RELOC: R_RISCV_LO12_I bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 sb t1, %lo(bar)(a2)
 # NORELAX-RELOC: R_RISCV_LO12_S bar 0x0
@@ -110,7 +110,7 @@ sb t1, %lo(bar)(a2)
 # RELAX-RELOC: R_RISCV_LO12_S bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %lo(bar), kind: fixup_riscv_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 2:
 auipc t1, %pcrel_hi(bar)
@@ -119,7 +119,7 @@ auipc t1, %pcrel_hi(bar)
 # RELAX-RELOC: R_RISCV_PCREL_HI20 bar 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_hi(bar), kind: fixup_riscv_pcrel_hi20
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 addi t1, t1, %pcrel_lo(2b)
 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_I
@@ -127,7 +127,7 @@ addi t1, t1, %pcrel_lo(2b)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_I .Ltmp1 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_i
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 sb t1, %pcrel_lo(2b)(a2)
 # NORELAX-RELOC-NOT: R_RISCV_PCREL_LO12_S
@@ -135,7 +135,7 @@ sb t1, %pcrel_lo(2b)(a2)
 # RELAX-RELOC: R_RISCV_PCREL_LO12_S .Ltmp1 0x0
 # RELAX-RELOC: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_s
-# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: relocation type 51
 
 ## %hi/%lo on an absolute symbol (not yet defined) leads to relocations when relaxation is enabled.
 lui t2, %hi(abs)
@@ -143,14 +143,14 @@ lui t2, %hi(abs)
 # RELAX-RELOC:      R_RISCV_HI20 - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %hi(abs), kind: fixup_riscv_hi20
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation type 51
 
 addi t2, t2, %lo(abs)
 # NORELAX-RELOC-NOT: R_RISCV_
 # RELAX-RELOC:      R_RISCV_LO12_I - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %lo(abs), kind: fixup_riscv_lo12_i
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation type 51
 
 .set abs, 0x12345
 
@@ -158,7 +158,7 @@ lui t3, %hi(abs)
 # RELAX-RELOC:      R_RISCV_HI20 - 0x12345
 # RELAX-RELOC-NEXT: R_RISCV_RELAX - 0x0
 # RELAX-FIXUP:      fixup A - offset: 0, value: %hi(74565), kind: fixup_riscv_hi20
-# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation
+# RELAX-FIXUP:      fixup B - offset: 0, value: 0, kind: relocation type 51
 
 # Check that a relocation is not emitted for a symbol difference which has
 # been folded to a fixup with an absolute value. This can happen when a



More information about the llvm-commits mailing list