[llvm] [RISCV] Vendor Relocations for Xqci extension (PR #135400)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 3 20:50:19 PDT 2025


================
@@ -611,6 +612,50 @@ bool RISCVAsmBackend::evaluateTargetFixup(const MCFixup &Fixup,
          isPCRelFixupResolved(AUIPCTarget.getAddSym(), *AUIPCDF);
 }
 
+void RISCVAsmBackend::maybeAddVendorReloc(const MCFragment &F,
+                                          const MCFixup &Fixup) {
+  MCContext &Ctx = Asm->getContext();
+
+  StringRef VendorIdentifier;
+
+  switch (Fixup.getTargetKind()) {
+  default:
+    // No Vendor Relocation Required.
+    return;
+  case RISCV::fixup_riscv_qc_e_branch:
+  case RISCV::fixup_riscv_qc_abs20_u:
+  case RISCV::fixup_riscv_qc_e_32:
+  case RISCV::fixup_riscv_qc_e_jump_plt:
+    VendorIdentifier = "QUALCOMM";
+    break;
+  }
+
+  // Create a local symbol for the vendor relocation to reference. It's fine if
+  // the symbol has the same name as an existing symbol.
+  MCSymbol *VendorSymbol = Ctx.createLocalSymbol(VendorIdentifier);
+  auto [It, Inserted] =
+      VendorSymbols.try_emplace(VendorIdentifier, VendorSymbol);
+
+  if (Inserted) {
+    // Setup the just-created symbol
+    VendorSymbol->setVariableValue(MCConstantExpr::create(0, Ctx));
+    Asm->registerSymbol(*VendorSymbol);
+  } else {
+    // Fetch the existing symbol
+    VendorSymbol = It->getValue();
+  }
+
+  const MCExpr *VendorExpr = MCSymbolRefExpr::create(VendorSymbol, Ctx);
+  MCFixup VendorFixup =
+      MCFixup::create(Fixup.getOffset(), VendorExpr, ELF::R_RISCV_VENDOR);
----------------
MaskRay wrote:

`MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_RISCV_VENDOR)` Then delete MCSymbolRefExpr::create .  MCFixup::Value isn't used

https://github.com/llvm/llvm-project/pull/135400


More information about the llvm-commits mailing list