[lld] [lld][LoongArch] Support reloc types for LA32R/LA32S (PR #172618)
Jessica Clarke via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 15 10:08:32 PST 2026
================
@@ -628,6 +647,24 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
write32le(loc, setD10k16(read32le(loc), val >> 2));
return;
+ case R_LARCH_CALL30: {
+ // This relocation is designed for adjacent pcaddu12i+jirl pairs that
+ // are patched in one time.
+ // The relocation range is [-2G, +2G) (of course must be 4-byte aligned).
+ if ((int64_t)val != llvm::SignExtend64(val, 32))
+ reportRangeError(ctx, loc, rel, Twine(val), llvm::minIntN(32),
+ llvm::maxIntN(32));
+ checkAlignment(ctx, loc, val, 4, rel);
+ // Although jirl adds the immediate as a signed value, it is always positive
+ // in this case, so no adjustment is needed, unlink CALL36.
+ uint32_t hi20 = extractBits(val, 31, 12);
+ // Despite the name, the lower part is actually 12 bits with 4-byte aligned.
+ uint32_t lo10 = extractBits(val, 11, 2);
+ write32le(loc, setJ20(read32le(loc), hi20));
+ write32le(loc + 4, setK10(read32le(loc + 4), lo10));
----------------
jrtc27 wrote:
(Otherwise it's particularly confusing as setK10 makes it sound like it's a new instruction format with a 10-bit immediate, which it's not)
https://github.com/llvm/llvm-project/pull/172618
More information about the llvm-commits
mailing list