[lld] [lld][riscv] Remove integer check for R_RISCV_SET32 (PR #219143)

Gergely Futo via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 03:48:31 PDT 2026


https://github.com/futog updated https://github.com/llvm/llvm-project/pull/219143

>From 145c91e3a9578036b6b7d9db79c0cee2f2830c24 Mon Sep 17 00:00:00 2001
From: Gergely Futo <gergely.futo at hightec-rt.com>
Date: Tue, 25 Aug 2026 14:27:05 +0200
Subject: [PATCH] [lld][riscv] Remove integer check for R_RISCV_SET32

It is checked if the value for the R_RISCV_SET32 relocation fits a 32-bit
signed integer (and a range error is issued if it does not). This is not
correct, since R_RISCV_SET32 is an absolute relocation type.
---
 lld/ELF/Arch/RISCV.cpp           |  2 ++
 lld/test/ELF/riscv-reloc-set32.s | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 lld/test/ELF/riscv-reloc-set32.s

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 49c41ff9ebe84..13c919c195e2e 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -702,6 +702,8 @@ void RISCV::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
     write16le(loc, val);
     return;
   case R_RISCV_SET32:
+    write32le(loc, val);
+    return;
   case R_RISCV_32_PCREL:
   case R_RISCV_PLT32:
   case R_RISCV_GOT32_PCREL:
diff --git a/lld/test/ELF/riscv-reloc-set32.s b/lld/test/ELF/riscv-reloc-set32.s
new file mode 100644
index 0000000000000..aa75a7e92fcb2
--- /dev/null
+++ b/lld/test/ELF/riscv-reloc-set32.s
@@ -0,0 +1,21 @@
+# REQUIRES: riscv
+
+# RUN: llvm-mc -filetype=obj -triple=riscv32 %s -o %t.o
+# RUN: llvm-readobj -r -x .data %t.o | FileCheck %s --check-prefix=REL
+# RUN: ld.lld %t.o --defsym=foo=0xffffffff -o %t.32
+# RUN: llvm-readelf -x .data %t.32 | FileCheck %s --check-prefix=HEX
+
+# REL:      .rela.data {
+# REL-NEXT:   0x0 R_RISCV_SET32 foo 0x0
+
+# HEX:      section '.data':
+# HEX-NEXT: 0x{{[0-9a-f]+}} ffffffff
+
+.globl foo
+
+.globl _start
+_start:
+.data
+    .reloc   ., R_RISCV_SET32, foo
+    .word    0;
+



More information about the llvm-commits mailing list