【问题标题】:What's wrong with the linker script链接描述文件有什么问题
【发布时间】:2015-12-23 16:18:32
【问题描述】:

我尝试生成一个图像,其中有一小部分代码初始化板(Raspberry Pi 2B),将其余内容复制到上层内存中并开始在那里运行其余代码。

这个想法是,整个图像首先在 0x8000 加载,“功能”从那里复制到上层内存并开始,然后放弃 0x8000 中的东西。

它不起作用。我从 ld 得到错误:

...
/bin/ld: address 0x124ac of loader.elf section `.text2' is not within region `EXEC'
...
/bin/ld: address 0x1ff18 of loader.elf section `.bss' is not within region `EXEC'
...
/bin/ld: address 0x124ac of loader.elf section `.text2' is not within region `EXEC'
...
/bin/ld: address 0x1ff18 of loader.elf section `.bss' is not within region `EXEC'
...
/bin/ld: address 0x124ac of loader.elf section `.text2' is not within region `EXEC'
...
/bin/ld: address 0x1ff18 of loader.elf section `.bss' is not within region `EXEC'
...
/bin/ld: region `EXEC' overflowed by -520487144 bytes
collect2: error: ld returned 1 exit status
make: *** [loader.elf] Error 1
make: Target `all' not remade because of errors.

我的链接器脚本:

ENTRY(_start)

MEMORY
{
    LOAD (rwx) : ORIGIN = 0x00008000, LENGTH = 512k /* initial */
    EXEC (rwx) : ORIGIN = 0x1f000000, LENGTH = 512k /* runtime */
}

SECTIONS
{   
    /* Starts at LOADER_ADDR. */
    . = 0x8000;
    __text_start = .;
    .text :
    {
        *(.init)
        *start1.o(.text)
        *start1.o(.data)
        *start1.o(.bss)
        *(.text.startup)
    } >LOAD

    .text2 ALIGN(0x1000):
    {
         __code_begin = .;
        *loader.o(.text)
        *rpi2.o(.text)
        *serial.o(.text)
        *util.o(EXCLUDE_FILE(*instr_util.o).text)
        *gdb.o(.text)
        *(.text)
    } >EXEC AT>LOAD
    __text_end = .;


    __data_start = .;
    .data :
    {
        *(.data)
    } >EXEC AT>LOAD
    __data_end = .;


    __bss_start = .;
    .bss ALIGN(0x8):
    {
        bss = .;
        *(.bss)
        stacks = .;
        . = . + 512;    /* fiq stack size */
        __fiq_stack = .;
        . = . + 1024;   /* usr & sys stack size (common) */
        __usrsys_stack = .;
        . = . + 16384;  /* svc stack size (start-up) */
        __svc_stack = .;
        . = . + 4096;   /* irq stack size (serial) */
        __irq_stack = .;
        . = . + 512;    /* mon stack size */
        __mon_stack = .;
        . = . + 512;    /* hyp stack size */
        __hyp_stack = .;
        . = . + 512;    /* und stack size */
        __und_stack = .;
        . = . + 16384;  /* abrt stack size (gdb-stub) */
        __abrt_stack = .;
    } >EXEC AT>LOAD
    __bss_end = .;

    __new_org = 0x1f000000;


    /* gcc-generated crap */
    .note :
    {
        *(.note.*)
    } >LOAD

    .debug :
    {
        *(.debug*)
    } >LOAD

    __end = .;
}

它工作正常,当我只在任何地方使用 >LOAD 时(全部在较低的内存中)。 程序不大:

       0x0001ff18                __bss_end = .
       0x00032098                __end = .

忘了说:这是一个裸机程序。

[编辑] 有趣的是,这行得通(但我宁愿'连接'......)

.text2 0x1e000000:
{
     __code_begin = .;
    *loader.o(.text)
    *rpi2.o(.text)
    *serial.o(.text)
    *util.o(EXCLUDE_FILE(*instr_util.o).text)
    *gdb.o(.text)
    *(.text)
} AT>LOAD

[/编辑]

【问题讨论】:

    标签: c gcc linker arm ld


    【解决方案1】:

    经过相当多的试验:“>EXEC AT>LOAD”确实有效。 它只是不喜欢“竞争定义”:ALIGN(0x1000)。

    【讨论】:

      猜你喜欢
      • 2022-11-23
      • 2013-05-17
      • 2012-04-06
      • 2019-11-27
      • 1970-01-01
      • 2022-06-25
      • 2019-12-13
      • 2016-05-21
      • 1970-01-01
      相关资源
      最近更新 更多