[lld] [lld] Add infrastructure for handling RISCV vendor-specific relocations. (PR #159987)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 15 21:10:36 PDT 2025
================
@@ -1476,3 +1482,54 @@ void elf::mergeRISCVAttributesSections(Ctx &ctx) {
}
void elf::setRISCVTargetInfo(Ctx &ctx) { ctx.target.reset(new RISCV(ctx)); }
+
+template <class ELFT, class RelTy>
+void RISCV::scanSectionImpl(InputSectionBase &sec, Relocs<RelTy> rels) {
+ RelocScan rs(ctx, &sec);
+ // Many relocations end up in sec.relocations.
+ sec.relocations.reserve(rels.size());
+
+ StringRef rvVendor;
+ for (auto it = rels.begin(); it != rels.end(); ++it) {
+ RelType type = it->getType(false);
+ uint32_t symIndex = it->getSymbol(false);
+ Symbol &sym = sec.getFile<ELFT>()->getSymbol(symIndex);
+ const uint8_t *loc = sec.content().data() + it->r_offset;
+
+ if (type == R_RISCV_VENDOR) {
+ if (!rvVendor.empty())
+ Err(ctx) << getErrorLoc(ctx, loc)
+ << "malformed consecutive R_RISCV_VENDOR relocations";
+ rvVendor = sym.getName();
+ continue;
+ } else if (!rvVendor.empty()) {
+ Err(ctx) << getErrorLoc(ctx, loc)
----------------
lenary wrote:
The idea is that, once implemented, we'll override `type` in here to become a vendor-specific value (i.e. a value that can differentiate QUALCOMM's CUSTOM192 from e.g. CherIoT's CUSTOM192)?
And then those will be mapped back to the conventional RelExpr?
This is not a blocking comment, I'm just trying to understand the next step for someone implementing their relocations.
https://github.com/llvm/llvm-project/pull/159987
More information about the llvm-commits
mailing list