[RFC] objcopy, elf: Align Header Offset [PR 32324]

Andreas Schwab schwab@suse.de
Tue Dec 3 10:08:02 GMT 2024


On Dez 02 2024, Andre Vieira (lists) wrote:

> diff --git a/bfd/elf.c b/bfd/elf.c
> index 74236a658fd9a10a61f466d9a2191998c2f4ce06..28d0143acca351203c840e6afc1dca710d6f671a 100644
> --- a/bfd/elf.c
> +++ b/bfd/elf.c
> @@ -6152,7 +6152,12 @@ assign_file_positions_for_load_sections (bfd *abfd,
>        if (m == phdr_load_seg)
>  	{
>  	  if (!m->includes_filehdr)
> -	    p->p_offset = off;
> +	    {
> +	      if (((bfd_vma) off) < p->p_align)
> +		p->p_offset = p->p_align;
> +	      else
> +		p->p_offset = off;
> +	    }

That is definitely wrong.  p_align only asserts that (p_offset -
p_vaddr) % p_align == 0.  It is _not_ required that p_offset % p_align
== 0.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Binutils mailing list