[RFC PATCH v2 09/10] tools/nolibc: ppc: Add relocation support

Daniel Palmer posted 10 patches 4 days, 8 hours ago
[RFC PATCH v2 09/10] tools/nolibc: ppc: Add relocation support
Posted by Daniel Palmer 4 days, 8 hours ago
Add relocation support for 32bit and 64bit ppc.

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

diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arch-powerpc.h
index e0c7e0b81f7c..a23c41b51cf7 100644
--- a/tools/include/nolibc/arch-powerpc.h
+++ b/tools/include/nolibc/arch-powerpc.h
@@ -7,8 +7,16 @@
 #ifndef _NOLIBC_ARCH_POWERPC_H
 #define _NOLIBC_ARCH_POWERPC_H
 
+#include "elf.h"
+
+#define _NOLIBC_ARCH_HAS_RELOC
+#ifndef __powerpc64__
+#define _NOLIBC_ARCH_ELF32
+#endif
+
 #include "compiler.h"
 #include "crt.h"
+#include "reloc.h"
 
 /* Syscalls for PowerPC :
  *   - stack is 16-byte aligned
@@ -184,6 +192,22 @@
 #endif /* !__powerpc64__ */
 
 #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_PPC_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