【发布时间】:2014-07-30 14:07:08
【问题描述】:
我在设置 gcc 的 section 属性以定义变量应驻留在特定内存段而不是默认值时遇到问题。
我正在使用 arm cortex m3 LPC1759。我从 LPCXpresso IDE 获得了链接文件,但我不使用它,我有自己的 makefile。链接文件是:
通用链接文件
INCLUDE "./link/LPCmem.ld" /* see below */
ENTRY(ResetISR)
SECTIONS
{
/* MAIN TEXT SECTION */
.text : ALIGN(4)
{
FILL(0xff)
__vectors_start__ = ABSOLUTE(.) ;
KEEP(*(.isr_vector))
/* Global Section Table */
. = ALIGN(4) ;
__section_table_start = .;
__data_section_table = .;
LONG(LOADADDR(.data));
LONG( ADDR(.data));
LONG( SIZEOF(.data));
LONG(LOADADDR(.data_RAM2));
LONG( ADDR(.data_RAM2));
LONG( SIZEOF(.data_RAM2));
__data_section_table_end = .;
__bss_section_table = .;
LONG( ADDR(.bss));
LONG( SIZEOF(.bss));
LONG( ADDR(.bss_RAM2));
LONG( SIZEOF(.bss_RAM2));
__bss_section_table_end = .;
__section_table_end = . ;
/* End of Global Section Table */
*(.after_vectors*)
} >FLASH
.text : ALIGN(4)
{
*(.text*)
*(.rodata .rodata.* .constdata .constdata.*)
. = ALIGN(4);
} > FLASH
/*
* for exception handling/unwind - some Newlib functions (in common
* with C++ and STDC++) use this.
*/
.ARM.extab : ALIGN(4)
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx : ALIGN(4)
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
_etext = .;
/* DATA section for SRAM0 */
.data_RAM2 : ALIGN(4)
{
FILL(0xff)
*(.ramfunc.$RAM2)
*(.ramfunc.$SRAM0)
*(.data.$RAM2*)
*(.data.$SRAM0*)
. = ALIGN(4) ;
} > SRAM0 AT>FLASH
/* MAIN DATA SECTION */
.uninit_RESERVED : ALIGN(4)
{
KEEP(*(.bss.$RESERVED*))
. = ALIGN(4) ;
_end_uninit_RESERVED = .;
} > SRAM
/* Main DATA section (SRAM) */
.data : ALIGN(4)
{
FILL(0xff)
_data = . ;
*(vtable)
*(.ramfunc*)
*(.data*)
. = ALIGN(4) ;
_edata = . ;
} > SRAM AT>FLASH
/* BSS section for SRAM0 */
.bss_RAM2 : ALIGN(4)
{
*(.bss.$RAM2*)
*(.bss.$SRAM0*)
. = ALIGN(4) ;
} > SRAM0
/* MAIN BSS SECTION */
.bss : ALIGN(4)
{
_bss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4) ;
_ebss = .;
PROVIDE(end = .);
} > SRAM
/* NOINIT section for SRAM0 */
.noinit_RAM2 (NOLOAD) : ALIGN(4)
{
*(.noinit.$RAM2*)
*(.noinit.$SRAM0*)
. = ALIGN(4) ;
} > SRAM0
/* DEFAULT NOINIT SECTION */
.noinit (NOLOAD): ALIGN(4)
{
_noinit = .;
*(.noinit*)
. = ALIGN(4) ;
_end_noinit = .;
} > SRAM
PROVIDE(_pvHeapStart = .);
PROVIDE(_vStackTop = __top_SRAM - 0);
}
内存定义文件
/* Define each memory region */
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000 /* 512K bytes */
SRAM (rwx) : ORIGIN = 0x10000000, LENGTH = 0x8000 /* 32K bytes */
SRAM0 (rwx) : ORIGIN = 0x2007c000, LENGTH = 0x8000 /* 32K bytes */
}
/* Define a symbol for the top of each memory region */
__top_FLASH = 0x0 + 0x80000;
__top_SRAM = 0x10000000 + 0x8000;
__top_SRAM0 = 0x2007c000 + 0x8000;
上面是上一个文件包含的LPCmem.ld文件。
我强制将 freertos 堆变量放在自定义部分中,如下所示:
static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]
__attribute__((section(".data_RAM2")));
对象文件的链接没有错误,但是变量没有放在正确的内存位置,我如何用 nm 命令检查:
...
10000028 d ucHeap
10002028 d uxCriticalNesting
...
我尝试将部分更改为其他不存在的部分,只是为了检查链接器是否验证了名称,显然它没有。
【问题讨论】: