I'm using the aarch64 bare-metal toolchain provided by Linaro, based on the newlib C library, and I need to specify the heap location in the linker script in order to be able of using C++ STL data structures with dynamic-memory (e.g. std::vector
).
Following the example here, I've defined the end
symbol as shown below.
.data : {
*(.data)
}
. = ALIGN(8);
/* "end" is used by newlib's syscalls! */
PROVIDE(end = .);
. = ALIGN(16);
stack_bottom = .;
. = ALIGN(4096);
. = . + 0x10000;
stack_top = .;
However, this way there is no way of checking if the heap has reached a maximum value (after which we get stack corruption).
I'd therefore like to know if the bare-metal newlib library has some further symbol for specifying the maximum heap size.
As explained in the newlib mailing list, there are two scenarios:
SYS_HEAPINFO
._sbrk()
system call checks if the allocated memory is going to overwrite the current stack. However, there is no check that the stack when growing overwrites the heap. Therefore, there is no newlib symbol for specifying the heap size, thus imposing a strong partitioning between the stack and the heap memory areas.