[RFC] objcopy, elf: Align Header Offset [PR 32324]
Andre Vieira (lists)
andre.simoesdiasvieira@arm.com
Mon Dec 2 14:16:30 GMT 2024
Hello,
This RFC 'fixes' the issue described in PR32324, but I doubt this is the
right thing to do. I am not at all familiar with this piece of code but
it looked wrong for the offset after objcopy to be lower than the
'Align' value, whereas all other headers seem to have an 'Offset' that
is larger than their 'Align'.
Debugging this also hinted that had the offset been the same as 'Align'
and in fact the original 'Offset' then everything would fall in place.
(deleted some leading 0s so it would fit in 80-char line).
Before objcopy/strip:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
...
LOAD 0x00000000200000 0x00000000600000 0x00000000600000
0x0000000040467c 0x0000000040467c R E 0x200000
After objcopy/strip:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
...
LOAD 0x00000000030120 0x00000000430120 0x00000000600000
0x0000000040467c 0x0000000040467c R E 0x200000
So I decided to try this hack for now and for this case it seems to work
for the binary I was using to reproduce this.
This is just intended as breadcrumbs for the next person to pick this up.
My reasoning was that I was seeing that the p_offset and p_vaddr of the
Header where things went wrong was much lower than the original, however
the section addresses were not, so some sections were no longer fitting
in this Segment and were being moved to the next one and eventually we
ran out of space for some Sections, hence the warnings.
Kind regards,
Andre
-------------- next part --------------
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;
+ }
off += actual * bed->s->sizeof_phdr;
}
More information about the Binutils
mailing list