SBSFU: Issue with 16-byte alignment in linker script?
I've run into an issue with the section of the UserApp linker script which ensures that the binary size is a multiple of 16 bytes:
.align16 :
{
. = . + 1; /* _edata=. is aligned on 8 bytes so could be aligned on 16 bytes: add 1 byte gap */
. = ALIGN(16) - 1; /* increment the location counter until next 16 bytes aligned address (-1 byte) */
BYTE(0); /* allocate 1 byte (value is 0) to be a multiple of 16 bytes */
} > APPLI_region_ROMThis seems to fail for some binary sizes, where the following error is given:
ld.exe:STM32WB5MMGHX_FLASH.ld:139 cannot move location counter backwards (from 0000000008032340 to 000000000803233f)If I change the size of the binary by adding some other command, the error goes away. I believe what's happening here is this:
- For a binary size of 0x3233f bytes, the first line advances the location counter to 0x32340.
- The second line rounds this to 0x32340, since it's already a multiple of 16 bytes, but then subtracts 1 byte, so it's attempting to set the location counter to 0x3233f, i.e., moving it backwards.
- The third line would advance the counter to 0x32340 again, except that it never gets called because an error is thrown in the second line.
I'm struggling to come up with an alternative to this which will ensure that the binary is a multiple of 16 bytes, but won't have the same issue.
