I need to add a small heap to use standard library functions on a TM4C ARM microcontroller (_sbrk
requires the end
symbol).
This is my linker script (came with a microcontroller demo):
/* Entry Point */
ENTRY(Reset_Handler)
HEAP_SIZE = 1024;
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00100000
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00040000
}
SECTIONS
{
.text :
{
_text = .;
KEEP(*(.isr_vector))
*(.text*)
*(.rodata*)
_etext = .;
} > FLASH
.data : AT(ADDR(.text) + SIZEOF(.text))
{
_data = .;
_ldata = LOADADDR (.data);
*(vtable)
*(.data*)
_edata = .;
} > SRAM
.bss :
{
_bss = .;
*(.bss*)
*(COMMON)
_ebss = .;
} > SRAM
.heap : AT(ADDR(.bss) + SIZEOF(.bss))
{
. = ALIGN(8);
__end__ = .;
PROVIDE(end = .);
__HeapBase = .;
. += HEAP_SIZE;
__HeapLimit = .;
} > SRAM
}
I only added .heap after .bss analogically to .data/.text but I get link error:
ld: section .init loaded at [000126b4,000126bf] overlaps section .data loaded at [000126b4,00012f8f]
collect2: error: ld returned 1 exit status
It also happens when I remove AT(ADDR(.bss) + SIZEOF(.bss))
. When I remove .heap and calls to libc functions everything compiles and links, the output binary runs correctly.
How should I adjust the script to correctly place heap after bss?