本文主要是介绍GNU链接脚本学习-最简链接脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最简连接脚本必备的元素
注: 这里的最简是指能成功生成.bin文件的最简,不代表一定能使MCU跑起来,要跑起来还得指定中断向量表以及堆和栈
-
指定入口
ENTRY(ramcode_start), 其中ramcode_start 可以是汇编程序标号,也可以是c程序函数,但光指定入口连接器并不会把入口链接在最开头,还得在.c或.s中为ramcode_start划分一个段并在链接文件中将该段放在最前面,这样连接成的可执行文件开头的地址就是ramcode_start。 -
定于存储介质
/* Specify the memory areas */
MEMORY
{
FLASHCODE(rx) : ORIGIN = 0x8040000, LENGTH = 128K
FREERAM (xrw) : ORIGIN = 0x20019000, LENGTH = 50K
} -
必要的几个段,
必须包括.text段、.rodata段、.data段、.bss段 -
导出end, _end变量
连接器是根据这两个变量值来结束链接的,内存布局的边界也是通过此变量确定的,如果链接文件中没有用PROVIDE(end = .)导出end变量,那么链接器就不知道可执行文件的结束符在哪里,链接就会报如下错误:
所以,必须在最后一个段中 PROVIDE ( end = . ); PROVIDE ( _end = . );
/*
*****************************************************************************
**
** File : pipe485part.ld
**
** Abstract : Linker script for STM32F415VG Device with
** 1024KByte FLASH, 128KByte RAM, for run a part of code in SRAM and others in code flash.
**
** Set heap size, stack size and stack location according
** to application requirements.
**
** Set memory bank area and size if external memory is used.
**
** Target : STMicroelectronics STM32
**
** Environment : Atollic TrueSTUDIO(R)
**
** Distribution: The file is distributed ?as is,? without any warranty
** of any kind.
**
** (c)Copyright xxg .
** You may use this file as-is or modify it according to the needs of your
** project. This file may only be built (assembled or compiled and linked)
** using the Atollic TrueSTUDIO(R) product. The use of this file together
** with other tools than Atollic TrueSTUDIO(R) is not permitted.
**
*****************************************************************************
*//* Entry Point */
ENTRY(ramcode_start)/* Highest address of the user mode stack */
_estack = 0x2001FFFF; /* end of RAM *//* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x700; /* required amount of heap */
_Min_Stack_Size = 0x80; /* required amount of stack *//* Specify the memory areas */
MEMORY
{FLASHCODE(rx) : ORIGIN = 0x8040000, LENGTH = 128KFREERAM (xrw) : ORIGIN = 0x20019000, LENGTH = 50K
}/* Define output sections */
SECTIONS
{.FLASHCODE :{*(.FLASHCODE)} >FLASHCODE.text :{. = ALIGN(4);*(.text) /* .text sections (code) */*(.text*) /* .text* sections (code) */. = ALIGN(4);} >FREERAM.rodata :{. = ALIGN(4);*(.rodata) /* .rodata sections (constants, strings, etc.) */*(.rodata*) /* .rodata* sections (constants, strings, etc.) */. = ALIGN(4);} >FREERAM.data :{. = 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 */} >FREERAM. = 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;PROVIDE ( end = . );PROVIDE ( _end = . );} >FREERAM/*._user_heap_stack :{. = ALIGN(4);PROVIDE ( end = . );PROVIDE ( _end = . );. = . + _Min_Heap_Size;. = . + _Min_Stack_Size;. = ALIGN(4);} >FREERAM
*/}
这篇关于GNU链接脚本学习-最简链接脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!