[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260204124542.523567-7-daniel@thingy.jp>
Date: Wed, 4 Feb 2026 21:45:38 +0900
From: Daniel Palmer <daniel@...ngy.jp>
To: w@....eu,
linux@...ssschuh.net
Cc: linux-kernel@...r.kernel.org,
Daniel Palmer <daniel@...ngy.jp>
Subject: [RFC PATCH v2 06/10] tools/nolibc: riscv: Add relocation support
Add relocation support for 32 and 64bit riscv.
Signed-off-by: Daniel Palmer <daniel@...ngy.jp>
---
tools/include/nolibc/arch-riscv.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h
index 1c00cacf57e1..0a6a4300c318 100644
--- a/tools/include/nolibc/arch-riscv.h
+++ b/tools/include/nolibc/arch-riscv.h
@@ -7,8 +7,18 @@
#ifndef _NOLIBC_ARCH_RISCV_H
#define _NOLIBC_ARCH_RISCV_H
+#include "elf.h"
+
+#ifdef R_RISCV_RELATIVE
+#define _NOLIBC_ARCH_HAS_RELOC
+#if __riscv_xlen == 32
+#define _NOLIBC_ARCH_ELF32
+#endif
+#endif
+
#include "compiler.h"
#include "crt.h"
+#include "reloc.h"
/* Syscalls for RISCV :
* - stack is 16-byte aligned
@@ -140,6 +150,22 @@
})
#ifndef NOLIBC_NO_RUNTIME
+
+#ifdef NOLIBC_WANT_RELOC
+static __inline__ int __relocate_rela(unsigned long base, _nolibc_elf_rela *entry)
+{
+ switch (_nolibc_elf_r_type(entry->r_info)) {
+ case R_RISCV_RELATIVE:
+ __relocate_rela_relative(base, entry);
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+#endif /* NOLIBC_WANT_RELOC */
+
/* startup code */
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
{
--
2.51.0
Powered by blists - more mailing lists