[llvm] [JITLink][RISC-V] Support R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128 for… (PR #153778)

Jonas Hahnfeld via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 06:35:47 PDT 2025


================
@@ -467,6 +485,18 @@ class ELFJITLinker_riscv : public JITLinker<ELFJITLinker_riscv> {
       *(little32_t *)FixupPtr = static_cast<uint32_t>(Value);
       break;
     }
+    case R_RISCV_SET_ULEB128:
+      break;
+    case R_RISCV_SUB_ULEB128: {
+      auto SetULEB128 = getRISCVSetULEB128(B, E);
+      if (!SetULEB128)
+        return SetULEB128.takeError();
+      uint64_t Value = SetULEB128->getTarget().getAddress() +
+                       SetULEB128->getAddend() - E.getTarget().getAddress() -
+                       E.getAddend();
+      encodeULEB128(Value, (reinterpret_cast<uint8_t *>(FixupPtr)));
----------------
hahnjo wrote:

from https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#uleb128-note

> The assembler must allocate sufficient space to accommodate the final value [...]

Should this check that there was enough space? We may need a different function for this, like LLD's `overwriteULEB128`.

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


More information about the llvm-commits mailing list