Linker Script Initialized Data

Ian Caddy ianc at
Wed Jan 7 02:40:03 UTC 2004

Hi Brett,

What you have to do here is get the linker to move store the .data 
section into a different spot and then copy it there in your startup code.

I have just cut a section out of our RAM makefile which should sort you out:

    .data   ALIGN (0x04) :
    AT ( ADDR(.data) + SIZEOF(.data) )
       copy_start = .;
       start_data = .;
       . = ALIGN (0x10);
       . = ALIGN (0x10);
      . = ALIGN (0x10);
       _edata = .;
       copy_end = .;
       end_data = .;
    } > ram

   . += SIZEOF(.data) ;

   .bss ALIGN (0x4) :

It is the AT command after the .data definition that get the loader to 
load the .data at the address specified, but all the information is 
linked to the address in the AT statement.  In this case, the data will 
be linked (as far as everyone else sees to just after the .data section).

Note then that you will need to reserve space for your temporary data 
space and then we start the .bss section.

Our startup code in our bootloader will copy the data section into the 
right place on startup.

If you need any more details just ask.

I hope this helps.

Ian Caddy.

Brett Swimley wrote:

> Hi All-
> My desire is to have a copy of initialized data that my BSP can copy to 
> the "working" data area at run time.  I'm downloading via BDM to a 
> target system, and have to download the entire executible each time due 
> to not having variables re-initialized to default values.  I'd like to 
> not have to dedicate a block of memory for this, but link the sections 
> contiguously, only allocating a separate section for the "src" of the 
> initialized data.
> I'm trying to follow the concepts listed on the following page:
> but I'm not convinced that things are working correctly.
> FWIW, I load my .text section first, then .data, then .bss.  All going 
> into the ram memory section (similar to the gen68340 linker script).  Is 
> there a way to confirm that the objcopy command is doing what is 
> expected? Do I need to change my linker script to rearrange how sections 
> are loaded?
> Can I accomplish the same thing just by making some changes in the 
> linkcmds file?
> Any help or advice is appreciated.
> Regards,
> Brett

More information about the users mailing list