cancel
Showing results for 
Search instead for 
Did you mean: 

GCC based Linker file for the STM32F0

halherta2
Associate II
Posted on June 26, 2012 at 18:26

Hello all I just wrote a simple linker file to be used in the gcc environment. One of my goals was to define a stack and heap section in the linker file. The linker file is provided below. It seems to compile with a simple led blinky project for the STM32F0.

In the linker file I included the preinit, init and fini sections to make the linker compatible with C++. I did see in some linker files an .arm.extab section. Does anyone know the purpose of this section ? Please feel free to provide me with any other feedback on the linker file. Thank you!

/******************************************************************************
*based on linker file at https://launchpadlibrarian.net/99003318/readme.txt
******************************************************************************/
/* Entry Point */
ENTRY(Reset_Handler)
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x10000 
/*64K*/
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x02000 
/*8K*/
}
/* define stack size and heap size here */
stack_size = 1024;
heap_size = 256; 
/* define beginning and ending of stack */
_stack_end = ORIGIN(RAM)+LENGTH(RAM);
_stack_begin = _stack_end - stack_size;
/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) 
/* Startup code */
. = ALIGN(4);
} >FLASH
/* The program code and other data goes into FLASH */
.text :
{
. = ALIGN(4);
*(.text) 
/* .text sections (code) */
*(.text*) 
/* .text* sections (code) */
*(.rodata) 
/* .rodata sections (constants, strings, etc.) */
*(.rodata*) 
/* .rodata* sections (constants, strings, etc.) */
*(.glue_7) 
/* glue arm to thumb code */
*(.glue_7t) 
/* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; 
/* define a global symbols at end of code */
} >FLASH
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = .;
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT ( _sidata )
{
. = ALIGN(4);
_sdata = .; 
/* create a global symbol at data start */
*(.data) 
/* .data sections */
*(.data*) 
/* .data* sections */
. = ALIGN(4);
_edata = .; 
/* define a global symbol at data end */
} >RAM
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; 
/* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; 
/* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
. = ALIGN(4);
.heap :
{
_heap_start = .;
. = . + heap_size;
} > RAM
. = ALIGN(4);
. = _stack_begin;
.stack :
{
. = . + stack_size;
} > RAM
}

#gcc-linker-file-stm32f0
1 REPLY 1
Posted on June 26, 2012 at 18:48

Thanks, always good to see examples

.extab and .exidx relate to EHABI unwinding as I recall.


 -funwind-tables

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..