llvm-objcopy should not insert padding before a section if its
physical addresses is not aligned to section's alignment. This
behavior will match GNU objcopy and is important for embedded images
where the physical address is used to store the initial data image.
The loader typically will copy this image using a start symbol
created by the linker. If llvm-objcopy inserts padding before such a
section, the symbol address will not match the location in the image.
This commit refines the change in https://reviews.llvm.org/D128961
which intended to align sections which type changed from NOBITS and
their offset may not be aligned. However, it affected all sections.
I think the comment can be simplified.
" The loader typically will copy this image using a start symbol created by the linker. Since copying is
done by memcpy, the source alignment is not important but the symbol
address must match the initial image location." seems unnecessary to me.
Perhaps just use this:
Without converting the type of a NOBITS section, don't align the offset.
This matches GNU objcopy when the physical address of a section is not aligned.