Add architecture-specific ELF relocation support for RISC-V,
enabling dynamic relocation of position-independent ELF binaries.
The implemetation reuses the existing relocate_image().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Reviewed-by: Ahmad Fatoum <[email protected]>
Signed-off-by: Sascha Hauer <[email protected]>
---
 arch/riscv/lib/reloc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/riscv/lib/reloc.c b/arch/riscv/lib/reloc.c
index 
18b13a7013cff4032c12b999470f265dbda13c51..71d59d4ab62ec07e23bc2ae3d9932f8d2baa7a81
 100644
--- a/arch/riscv/lib/reloc.c
+++ b/arch/riscv/lib/reloc.c
@@ -75,3 +75,19 @@ void relocate_to_current_adr(void)
 
        sync_caches_for_execution();
 }
+
+int elf_apply_relocations(struct elf_image *elf, const void *dyn_seg)
+{
+       void *rela_ptr = NULL, *symtab = NULL;
+       u64 relasz;
+       phys_addr_t base = (phys_addr_t)elf->reloc_offset;
+       int ret;
+
+       ret = elf_parse_dynamic_section_rela(elf, dyn_seg, &rela_ptr, &relasz, 
&symtab);
+       if (ret)
+               return ret;
+
+       relocate_image(base, rela_ptr, rela_ptr + relasz, symtab, NULL);
+
+       return 0;
+}

-- 
2.47.3


Reply via email to