Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The GNU linker. - <b>optional section attributes</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Optional Section Attributes
---------------------------

   Here is the full syntax of a section definition, including all the
optional portions:

     SECTIONS {
     ...
     SECNAME START BLOCK(ALIGN) (NOLOAD) : AT ( LDADR )
       { CONTENTS } >REGION :PHDR =FILL
     ...
     }

   SECNAME and CONTENTS are required.  Section Definition:, and   
Section Placement:, for details on CONTENTS.  The remaining   
elements--START, `BLOCK(ALIGN)', `(NOLOAD)', `AT ( LDADR )', `>REGION',
`:PHDR', and `=FILL'--are all optional.

`START'
     You can force the output section to be loaded at a specified
     address by specifying START immediately following the section name.
     START can be represented as any expression. The following example
     generates section OUTPUT at location `0x40000000':

          SECTIONS {
            ...
            output 0x40000000: {
              ...
              }
            ...
          }

`BLOCK(ALIGN)'
     You can include `BLOCK()' specification to advance the location
     counter `.' prior to the beginning of the section, so that the
     section will begin at the specified alignment.  ALIGN is an
     expression.

`(NOLOAD)'
     Use `(NOLOAD)' to prevent a section from being loaded into memory
     each time it is accessed.  For example, in the script sample
     below, the `ROM' segment is addressed at memory location `0' and
     does not need to be loaded into each object file:

          SECTIONS {
            ROM  0  (NOLOAD)  : { ... }
            ...
          }

`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':

          SECTIONS
            {
            .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;

`>REGION'
     Assign this section to a previously defined region of memory.
     MEMORY:.   

`:PHDR'
     Assign this section to a segment described by a program header.
     PHDRS:.  If a section is assigned to one or more segments,   
     then all subsequent allocated sections will be assigned to those
     segments as well, unless they use an explicitly `:PHDR' modifier.
     To prevent a section from being assigned to a segment when it would
     normally default to one, use `:NONE'.

`=FILL'
     Including `=FILL' in a section definition specifies the initial
     fill value for that section.  You may use any expression to
     specify FILL.  Any unallocated holes in the current output section
     when written to the output file will be filled with the two least
     significant bytes of the value, repeated as necessary.  You can
     also change the fill value with a `FILL' statement in the CONTENTS
     of a section definition.


See Also: Section Definition Section Placement MEMORY PHDRS

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson