[RFC PATCH 6/9] tools/nolibc: riscv: Add relocation support

Daniel Palmer posted 9 patches 1 week, 1 day ago
There is a newer version of this series
[RFC PATCH 6/9] tools/nolibc: riscv: Add relocation support
Posted by Daniel Palmer 1 week, 1 day ago
Add relocation support for 32 and 64bit riscv.

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
 tools/include/nolibc/arch-riscv.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/include/nolibc/arch-riscv.h b/tools/include/nolibc/arch-riscv.h
index 1c00cacf57e1..76618d4c001d 100644
--- a/tools/include/nolibc/arch-riscv.h
+++ b/tools/include/nolibc/arch-riscv.h
@@ -7,6 +7,11 @@
 #ifndef _NOLIBC_ARCH_RISCV_H
 #define _NOLIBC_ARCH_RISCV_H
 
+#if __riscv_xlen == 32
+#define NOLIBC_ARCH_ELF32
+#endif
+#define NOLIBC_ARCH_HAS_RELOC
+
 #include "compiler.h"
 #include "crt.h"
 
@@ -140,6 +145,19 @@
 })
 
 #ifndef NOLIBC_NO_RUNTIME
+static int __relocate_rela(unsigned long base, elf_rela *entry)
+{
+	switch (elf_r_type(entry->r_info)) {
+	case R_RISCV_RELATIVE:
+		__relocate_rela_relative(base, entry);
+		break;
+	default:
+		return -1;
+	}
+
+	return 0;
+}
+
 /* startup code */
 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
 {
-- 
2.51.0