链接描述文件

时间:2015-09-25 18:53:38

标签: c gcc linker arm ld

我尝试生成一个图像,其中有一小部分代码初始化电路板(Raspberry Pi 2B),将剩余的内容复制到高端内存中并开始运行其余的代码。

这个想法是整个图像首先加载到0x8000,“functonality”被复制到高端内存并启动,然后放弃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

[/编辑]

1 个答案:

答案 0 :(得分:0)

经过一些试验:“> EXEC AT> LOAD”开始工作。 它只是不喜欢'竞争定义':ALIGN(0x1000)。