You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[elf2bin] Exclude zero-length segments from --bincombined. (#481)
(And also from --vhxcombined, which uses the same underlying code, but
that didn't fit in a sensible-length subject line.)
Last week I found Arm Toolchain had generated an ELF image in which
three segments had p_paddr in the bottom few Kb of the address space,
but there was also a segment with zero p_filesz (but nonzero p_memsz),
with p_paddr > 0x20000000. Running that through `elf2bin --physical
--bincombined`, it didn't notice that the segment at a high address had
length 0, so it padded the output file to half a Gb in size to reach the
start address, and then didn't actually write anything there.
I worked around it at the time by selecting a subset of the segments to
put in the --bincombined output file. But I think a better answer is to
discard the zero-length segment completely when writing --bincombined
output, because the padding in the output file is only there to get the
file position to the place where some actually important data needs to
be written. If there _is_ no important data to put at that position,
there's no need to go there at all.
(Incidentally, I think I know why my image came out like that. The
target memory map had Flash at 0, and RAM at 0x20000000. The code
segments were in Flash, and the initialized data segment had its p_paddr
in Flash but its p_vaddr at 0x20000000, representing respectively where
the startup code would memcpy it from and to. The segment with
p_filesz==0 represented the program's zero-initialized data, so its
p_vaddr was in RAM, representing where the data would be at run time –
but since it didn't need to be memcpy()ed from anywhere, the linker had
left its p_paddr the same as its p_vaddr, and not bothered to allocate
it a different one. In other words, the linker felt that if the segment
was 0 bytes long then it didn't need a meaningful p_paddr at all.)
The new behavior adapts appropriately if you use the --zi option: in
that situation, a segment with zero p_filesz but nonzero p_memsz doesn't
count as empty, because the user _does_ want zero bytes in the
--bincombined output file at its address.
0 commit comments