This is the mail archive of the mailing list for the crossgcc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: powerpc-unknown-eabi rom relocation

   Date: Wed, 2 Sep 1998 20:51:00 -0700 (PDT)
   From: Vaughan Hillman <>

   Ive got a cross compiler for the powerpc-eabi 
   hosted on under sunos.  I am trying to build
   a rom image that when loaded to the bootprom will move its data
   sections to ram.  I have compiled all source files with
   -mrelocatable-lib (not sure if this flag directly relates to what Im
   trying to accomplish).  For testing purposes I have been trying to
   relocate the .sdata section by using the following line in my linker

   .sdata 0x10000 : AT (0x50000) { *(*.sdata) }

   My understanding of what this line means is the following.  .sdata
   will be put at address 0x10000 in 
   the rom image but all references to this area (by code) will point to
   address offset 0x50000.  My code would then be responsible for copying
   this data from rom address to 0x10000 out to ram address 0x50000.

You've got it backwards.  0x50000 is the "load address".

   I have sifted through all the documentation for the linker file and
   gcc options at the Cygnus site and still seem to be stuck.

Did you read this snippet from [appended at the end]

   Is the -mrelocatable-lib flag supposed to be helping
   me with relocating this section?

I'm not a powerpc person so I can't help you there.

-- snip --
`AT ( LDADR )'
     The expression LDADR that follows the `AT' keyword specifies the
     load address of the section.  The default (if you do not use the
     `AT' keyword) is to make the load address the same as the
     relocation address.  This feature is designed to make it easy to
     build a ROM image.  For example, this `SECTIONS' definition
     creates two output sections: one called `.text', which starts at
     `0x1000', and one called `.mdata', which is loaded at the end of
     the `.text' section even though its relocation address is
     `0x2000'.  The symbol `_data' is defined with the value `0x2000':

            .text 0x1000 : { *(.text) _etext = . ; }
            .mdata 0x2000 :
              AT ( ADDR(.text) + SIZEOF ( .text ) )
              { _data = . ; *(.data); _edata = . ;  }
            .bss 0x3000 :
              { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}

     The run-time initialization code (for C programs, usually `crt0')
     for use with a ROM generated this way has to include something like
     the following, to copy the initialized data from the ROM image to
     its runtime address:

          char *src = _etext;
          char *dst = _data;
          /* ROM has data at end of text; copy it. */
          while (dst < _edata) {
            *dst++ = *src++;
          /* Zero bss */
          for (dst = _bstart; dst< _bend; dst++)
            *dst = 0;