Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linker 链接器脚本:将节标记为在两个内存段中占用空间_Linker_Ld - Fatal编程技术网

Linker 链接器脚本:将节标记为在两个内存段中占用空间

Linker 链接器脚本:将节标记为在两个内存段中占用空间,linker,ld,Linker,Ld,我有一个用于嵌入式系统的链接器脚本,它正在执行一些重定位(代码加载到设备的闪存中,但在启动时复制到RAM中执行)。它使用的是,它似乎就是为了这样设计的 问题在于,重新定位部分的大小目前仅计入ram内存区域,而实际上,它应计入rom和ram区域(设备静止时占用前者,设备活动时占用后者)。当前,如果数据单独适合rom,但数据+重新定位超过rom,则不会收到任何错误或警告 如何使.relocate部分将其大小计入rom和ram内存区域 最小化链接器脚本: MEMORY { rom (rx) :

我有一个用于嵌入式系统的链接器脚本,它正在执行一些重定位(代码加载到设备的闪存中,但在启动时复制到RAM中执行)。它使用的是,它似乎就是为了这样设计的

问题在于,重新定位部分的大小目前仅计入
ram
内存区域,而实际上,它应计入
rom
ram
区域(设备静止时占用前者,设备活动时占用后者)。当前,如果
数据
单独适合
rom
,但
数据+重新定位
超过
rom
,则不会收到任何错误或警告

如何使
.relocate
部分将其大小计入
rom
ram
内存区域

最小化链接器脚本:

MEMORY
{
  rom (rx)  : ORIGIN =  ROM_ORIGIN, LENGTH =  ROM_LENGTH
  ram (rwx) : ORIGIN =  RAM_ORIGIN, LENGTH =  RAM_LENGTH
}

__stack_size__ = DEFINED(__stack_size__) ? __stack_size__ : 0x1000;

SECTIONS
{
    .text :
    {
        . = ALIGN(4);
        _stext = .;         /* First of standard s,e (start/end) pair */
        KEEP(*(.vectors .vectors.*))
        KEEP(*(.irqs))

        *(.text .text.* .gnu.linkonce.t.*)
        *(.rodata .rodata* .gnu.linkonce.r.*)
    } > rom

    /* Mark the end of static elements */
    . = ALIGN(4);
    _etext = .;

    /* This is program data that is exepected to live in SRAM, but is
     * initialized with a value. This data is physically placed into flash and
     * is copied into SRAM at boot. The symbols here will be defined with
     * addresses in SRAM.
     *
     * This is the section that needs to be charged to BOTH rom and ram */
    .relocate : AT (_etext)
    {
        . = ALIGN(4);
        _srelocate = .;
        *(.ramfunc .ramfunc.*);
        *(.data .data.*);

        . = ALIGN(4);
        _erelocate = .;
    } > ram

    .sram (NOLOAD) :
    {
        . = ALIGN(8);
         _sstack = .;

        . = . + __stack_size__;

        . = ALIGN(8);
        _estack = .;


        /* BSS section. Memory that is expected to be initialized to zero. */
        . = ALIGN(4);
        _szero = .;

        *(.bss .bss.*)
        *(COMMON)

        . = ALIGN(4);
        _ezero = .;
    } > ram
}

或者是这里。

我们设法解决了这个问题。解决方案是更改如何指定
重新定位
节的位置,具体来说,这是错误的:

# Bad:
.relocate : AT (_etext)
{
...
} > ram
相反,
AT
指令应该在末尾,如下所示:

# Correct
.relocate :
{
...
} > ram AT > rom
这将导致链接器对
的大小进行充电。将
重新定位到
ram
rom
,同时将节“物理”放置在
rom

(指向问题中链接的完整链接器脚本)