The sections .stack and .heap are user defined. In the startup, build and linker scripts provided, together with our newlibc example implementation, we provide you with an explanatory implementation of those.
Within the wscript in the Targets directory you are able to define the stack and heap size for each target individually.
The heap itself is used in the newlibc implementation within the sbrk function. However, the heap area has to be initialized upfront. If you are using an operating system, you need to take care on how the stacks and heaps are used.
If you now receive the message: "ld.exe: region RAM overflowed with stack" it is because the defined size of stack and heap cannot be linked correctly.
In our examples, the heap is positioned after the sections containing .text, .rodata, .data, .bss and others containing compile time known data. The stack is always placed at the end of the selected memory. While the heap grows to the end of the memory, the stack grows from the end of it backwards in the direction of the heap.
Our example does not check the consistency of heap and stack during runtime, and it is possible, that stack and heap might overwrite each other.