Using GCC 4.8.4, it seems to me, that the nrf52_common.ld shiped with the sdk version 12.2 contains a bug:
If an image is defined where the .text
data fits into the flash, but where the .data
initialization data would lead to an overflow of the flash, the linker does not complain about the overflow.
The reasons for this seems to be that the linker script doesn't declare the .data
section to be within the flash MEMORY
. Adding AT > FLASH
to the end of the .data
section declaration seems to fix the issue:
__etext = .;
.data :
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN(4);
...
__data_end__ = .;
} > RAM AT > FLASH
The start of the section seems a little bit suspicious to me too. What happens if __etext
is not properly aligned?