[PATCH v3 07/23] riscv: implement elf_apply_relocations() for ELF relocation support
Sascha Hauer
s.hauer at pengutronix.de
Thu Jan 8 07:50:04 PST 2026
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 <noreply at anthropic.com>
Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
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
More information about the barebox
mailing list