GNU链接描述文件 - 将代码拆分为两个内存区域

时间:2012-12-04 09:13:29

标签: linker split gnu ld scatter

我正在尝试创建一个liker脚本,将代码分成两个代码区域和一个单独的BSS。

两个代码部分要链接在一起,但要分开加载 无论我尝试什么,代码总是混合。我尝试了不同的版本,对齐部分没有成功。

以下是我想要的描述:

闪存

------------ 0x0
| CODE 1   |
|          |
------------
| fill to  |
|alignment |
|          |
------------ 0x200000
| CODE 2   |
|          |
------------

加载到内存:

------------ 0x5c010000
| CODE 1   |
|          |
------------
.          .
.          .
------------ 0x81500000
| CODE 2   |
|          |
------------

我看到了链接器手册“输入部分示例”,但它对我不起作用。

以下是我的代码示例:

/*-------------------------------------------------------------------------
 * Filename:      startup.lds
 *-----------------------------------------------------------------------*/
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/

OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)

ENTRY(__main)


SECTIONS
{
    . = 0x5c006000;
    __bss_start = .;
    .bss : {    *(EXCLUDE_FILE (../../release/eshel_lte_evb3/usbdownload.o
        ../../release/eshel_lte_evb3/usbdriver.o
        ../../release/eshel_lte_evb3/xllp_udc.o)
        .bss) }
    .bss2 : {
        ../../release/eshel_lte_evb3/usbdownload.o (.bss)
        ../../release/eshel_lte_evb3/usbdriver.o (.bss)
     }

    . = ALIGN(4);

    . = 0x5c010000;

    .__main = .;

    . = ALIGN(4);

    .text : {
        *(EXCLUDE_FILE (../../release/eshel_lte_evb3/usbdownload.o
        ../../release/eshel_lte_evb3/usbdriver.o
        ../../release/eshel_lte_evb3/xllp_udc.o)
        .text)
        . = ALIGN(4);
    }

    .rodata : { *(EXCLUDE_FILE (../../release/eshel_lte_evb3/usbdownload.o
        ../../release/eshel_lte_evb3/usbdriver.o
        ../../release/eshel_lte_evb3/xllp_udc.o)
        .rodata) }

    . = ALIGN(4);

    .got : { *(EXCLUDE_FILE (../../release/eshel_lte_evb3/usbdownload.o
        ../../release/eshel_lte_evb3/usbdriver.o
        ../../release/eshel_lte_evb3/xllp_udc.o)
        .got) }


    . = ALIGN(4);

    __egot = .;




    . = ALIGN(4);

    __data_start = .;
    .data : AT (__egot) {*(.data) } =0xFFFFFFFF
    __data_end = .;

    . = ALIGN(16);
    _seg_CODE_end_ = .;

/*  ASSERT((_seg_CODE_end_ <= 0x5c020000), "Error: Code size to big")*/


    . = ALIGN(0x20000);
    __topofcode__ = .;

    . = 0x81500000;
    .__usb_code_start = .;
    .usb_code 0x81500000 : 
    AT(__topofcode__) 
    ALIGN(0x20000)
    SUBALIGN(0x20000)
    {
        ../../release/eshel_lte_evb3/usbdownload.o (.text)
        ../../release/eshel_lte_evb3/usbdriver.o (.text)

        ../../release/eshel_lte_evb3/usbdownload.o (.rodata)
        ../../release/eshel_lte_evb3/usbdriver.o (.rodata)

        ../../release/eshel_lte_evb3/usbdownload.o (.data)
        ../../release/eshel_lte_evb3/usbdriver.o (.data)
    }

    __bss_end = .;

}

0 个答案:

没有答案