On 1/5/26 12:26 PM, Sascha Hauer wrote:
> Add support for applying dynamic relocations to ELF binaries. This allows
> loading ET_DYN (position-independent) binaries and ET_EXEC binaries at
> custom load addresses.
> 
> Key changes:
> - Add elf_image.reloc_offset to track offset between vaddr and load address
> - Implement elf_compute_load_offset() to calculate relocation offset
> - Add elf_set_load_address() API to specify custom load address
> - Implement elf_find_dynamic_segment() to locate PT_DYNAMIC
> - Add elf_relocate() to apply relocations
> - Provide weak default elf_apply_relocations() stub for unsupported 
> architectures
> - Add ELF dynamic section accessors
> 
> The relocation offset type is unsigned long to properly handle pointer
> arithmetic and avoid casting issues.
> 
> Architecture-specific implementations should override the weak
> elf_apply_relocations() function to handle their relocation types.
> 
> Signed-off-by: Sascha Hauer <[email protected]>
> Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
> ---
> +     if (elf->reloc_offset) {
> +             u64 p_vaddr = elf_phdr_p_vaddr(elf, phdr);
> +             dst = (void *)(unsigned long)(elf->reloc_offset + p_vaddr);
> +     } else {
> +             dst = (void *)(unsigned long)elf_phdr_p_paddr(elf, phdr);
> +     }

This stanza repeats multiple times. Maybe factor out into a helper that
takes elf and phdr as arguments?


Cheers,
Ahmad

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |


Reply via email to