Hi,

On 1/8/26 4:50 PM, Sascha Hauer wrote:
> +     /*
> +      * Calculate relocation offset for the in-place binary.
> +      * For ET_DYN, we need to find the first PT_LOAD segment
> +      * and use it as the relocation base.
> +      */
> +     if (elf->type == ET_DYN) {
> +             u64 text_vaddr = 0;
> +             u64 text_offset = 0;
> +             bool found_text = false;
> +
> +             /* Find first PT_LOAD segment */
> +             phdr = buf + elf_hdr_e_phoff(elf, buf);
> +             for (i = 0; i < elf_hdr_e_phnum(elf, buf); i++) {
> +                     if (elf_phdr_p_type(elf, phdr) == PT_LOAD) {
> +                             text_vaddr = elf_phdr_p_vaddr(elf, phdr);
> +                             text_offset = elf_phdr_p_offset(elf, phdr);
> +                             found_text = true;
> +                             break;
> +                     }
> +                     phdr += elf_size_of_phdr(elf);
> +             }
> +
> +             if (!found_text) {
> +                     pr_err("No PT_LOAD segment found\n");

A bit confusing to call it found_text and check if it's PT_LOAD.
As mentioned before, I am unsure if text indeed is always the
first segment in iteration order.

Would it not be more correct to factor out the initial loop in
elf_compute_load_offset to a helper function and use that here
to determine the lowest loadable segment and use that instead of
the first? Should reduce the diff too.

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