Consider the following linker script which I have written for an ARM based microcontroller:
/* Configure memory regions */
MEMORY
{
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
BKPRAM (rw) : ORIGIN = 0x40024000, LENGTH = 4K
CCMRAM (rwx) : ORIGIN = 0x1000000, LENGTH = 64K
}
SECTIONS
{
.text :
{
. = ALIGN(4);
KEEP(*(.isr_vector*))
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
. = ALIGN(4);
} > RAM
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > RAM
.ARM.exidx :
{
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} > RAM
__etext = .;
.data : AT (__etext)
{
. = ALIGN(4);
__data_start__ = .;
*(.data*)
. = ALIGN(4);
__data_end__ = .;
} > RAM
.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
.heap_dummy :
{
. = ALIGN(4);
__end__ = .;
end = __end__;
. = . + __HEAP_SIZE;
. = ALIGN(4);
__HeapLimit = .;
} > RAM
.stack_dummy :
{
. = ALIGN(4);
. = . + __STACK_SIZE;
__StackTop = .;
. = ALIGN(4);
} > RAM
}
It seems to work fine and, at least according to the disassembly and the map file, it places all sections as it should. However, it has one minor problem:
As one can see, I have included the "heap_dummy" and "stack_dummy" sections, both of which shall not really contain data, but I have created those sections such that I get a warning if either the heap size or the stack size are adjusted such that they wouldn't fit into the RAM. This works very well. However, when I used a stack size of 1024, the arm-none-eabi-size
tool reports the following
test_ram.elf
text data bss dec hex filename
124 0 1024 1152 480 bin/test_ram.elf
i.e. the size of the "stack dummy" section is considered as if it was a bss section. However, I don't want the linker to actually count the size of the two dummy sections, as they don't really exist but are only used to reserve some space. How can I suppress this and still keep my dummy sections? Or, alternatively, can I also somehow keep track of the memory usage for stack and heap without the dummy sections?