ARM GCC linker 脚本介绍


1. Reference

arm-2011.03/share/doc/arm-arm-none-eabi/pdf/ld.pdf


2. An example


OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")

/* Use OUTPUT_FORMAT with three arguments to use different formats based
on the ‘-EB’ and ‘-EL’ command line options. This permits the linker script to
set the output format based on the desired endianness.*/


MEMORY
{
rom (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00008000
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 0x00002000
}


/* Program code and read-only data go into the ROM. Read-write data goes into
the RAM. An image of the initialized data is loaded into the ROM and will be
copied during system start into the RAM.

*/



/* Section Definitions */ 
SECTIONS 

    .text : 
    { 
        KEEP(*(.isr_vector .isr_vector.*)) 
        *(.text .text.* .gnu.linkonce.t.*)      
        *(.glue_7t) *(.glue_7)                
        *(.rodata .rodata* .gnu.linkonce.r.*)                      
    } > rom

    .ARM.extab : 
    {
        *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > rom
    
    .ARM.exidx :
    {
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > rom

    . = ALIGN(4); 

    _etext = .;

/* Program code */


    _sidata = .; 
/* Initialized data is  at _sidata */

    .data : AT (_etext) 
    { 
        _sdata = .; 
        *(.data .data.*) 
        . = ALIGN(4); 
        _edata = . ;
    } > ram

/*  Initialized data will be
copied during system start into the RAM */


    /* .bss section which is used for uninitialized data */ 
    .bss (NOLOAD) : 
    { 
        _sbss = . ; 
        *(.bss .bss.*) 
        *(COMMON) 
        . = ALIGN(4); 
        _ebss = . ; 
    } > ram
    

/*  None initialized  data will be
placed to the RAM */


    /* stack section */
    .co_stack (NOLOAD):
    {
        . = ALIGN(8);
        *(.co_stack .co_stack.*)
    } > ram

/*  Other ram are used as stack */
       
    . = ALIGN(4); 
    _end = . ; 



你可能感兴趣的:(ARM GCC linker 脚本介绍)