Possibility of the zero-cost stack overflow protection #273
Description
Well, this is not necessarily an issue, but maybe some information that could be used as a starting point to bring back the stack overflow protection.
After reading the zero-cost stack overflow protection article and realizing that the cortex-m-rt-ld no longer works, I've found that the following statemenet is somewhat false:
We can’t specify the start address of .bss+.data to be 0x2000_4000 or some other fixed number because the correct number depends on the size of the .bss+.data section and linker scripts don’t provide support to get the size of an output section
At least on the current nightly, the following works:
/* ## Sections in RAM */
/* ### .data */
.data ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.heap) - SIZEOF(.uninit) - SIZEOF(.bss) - SIZEOF(.data) - 4 : AT(__erodata) ALIGN(4)
{
. = ALIGN(4);
__sdata = .;
*(.data .data.*);
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
__edata = .;
} > RAM
/* LMA of .data */
__sidata = LOADADDR(.data);
/* ### .bss */
.bss ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.heap) - SIZEOF(.uninit) - SIZEOF(.bss) - 4 (NOLOAD) : ALIGN(4)
{
. = ALIGN(4);
__sbss = .;
*(.bss .bss.*);
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
__ebss = .;
} > RAM
/* ### .uninit */
.uninit ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.heap) - SIZEOF(.uninit) (NOLOAD) : ALIGN(4)
{
. = ALIGN(4);
*(.uninit .uninit.*);
. = ALIGN(4);
} > RAM
/* Heap */
.heap ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.heap) (NOLOAD): ALIGN(4)
{
. = ALIGN(4);
__sheap = .;
*(.heap .heap.*);
. = __sheap + __heap_size;
__eheap = .;
} > RAM
... and produces the following placement on an nRF52 with 64K RAM:
section size addr
.vector_table 0xdc 0x0
.text 0x14d6c 0xdc
.rodata 0x424c 0x14e50
.data 0x0 0x2000cd58
.bss 0xe5c 0x2000cd58
.uninit 0x1448 0x2000dbb8
.heap 0x1000 0x2000f000
[...]
I admit, it's not beautiful, but with PROVIDE(_stack_start = __sdata);
(I think) I have the sections arranged in a way that implements the overflow protection, without double linking.