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>section data expressions</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Section Data Expressions
------------------------

   The foregoing statements arrange, in your output file, data
originating from your input files.  You can also place data directly in
an output section from the link command script.  Most of these
additional statements involve expressions (Expressions:.).   
Although these statements are shown separately here for ease of
presentation, no such segregation is needed within a section definition
in the `SECTIONS' command; you can intermix them freely with any of the
statements we've just described.

`CREATE_OBJECT_SYMBOLS'
     Create a symbol for each input file in the current section, set to
     the address of the first byte of data written from that input
     file.  For instance, with `a.out' files it is conventional to have
     a symbol for each input file.  You can accomplish this by defining
     the output `.text' section as follows:
          SECTIONS {
            .text 0x2020 :
               {
              CREATE_OBJECT_SYMBOLS
              *(.text)
              _etext = ALIGN(0x2000);
              }
            ...
          }

     If `sample.ld' is a file containing this script, and `a.o', `b.o',
     `c.o', and `d.o' are four input files with contents like the
     following--
          /* a.c */
          
          afunction() { }
          int adata=1;
          int abss;

     `ld -M -T sample.ld a.o b.o c.o d.o' would create a map like this,
     containing symbols matching the object file names:
          00000000 A __DYNAMIC
          00004020 B _abss
          00004000 D _adata
          00002020 T _afunction
          00004024 B _bbss
          00004008 D _bdata
          00002038 T _bfunction
          00004028 B _cbss
          00004010 D _cdata
          00002050 T _cfunction
          0000402c B _dbss
          00004018 D _ddata
          00002068 T _dfunction
          00004020 D _edata
          00004030 B _end
          00004000 T _etext
          00002020 t a.o
          00002038 t b.o
          00002050 t c.o
          00002068 t d.o

`SYMBOL = EXPRESSION ;'
`SYMBOL F= EXPRESSION ;'
     SYMBOL is any symbol name (Symbols:.).  "F=" refers to any   
     of the operators `&= += -= *= /=' which combine arithmetic and
     assignment.

     When you assign a value to a symbol within a particular section
     definition, the value is relative to the beginning of the section
     (Assignment:.).  If you write   

          SECTIONS {
            abs = 14 ;
            ...
            .data : { ... rel = 14 ; ... }
            abs2 = 14 + ADDR(.data);
            ...
          }

     `abs' and `rel' do not have the same value; `rel' has the same
     value as `abs2'.

`BYTE(EXPRESSION)'
`SHORT(EXPRESSION)'
`LONG(EXPRESSION)'
`QUAD(EXPRESSION)'
     By including one of these four statements in a section definition,
     you can explicitly place one, two, four, or eight bytes
     (respectively) at the current address of that section.  `QUAD' is
     only supported when using a 64 bit host or target.

     Multiple-byte quantities are represented in whatever byte order is
     appropriate for the output file format (BFD:.).   

`FILL(EXPRESSION)'
     Specify the "fill pattern" for the current section.  Any otherwise
     unspecified regions of memory within the section (for example,
     regions you skip over by assigning a new value to the location
     counter `.') are filled with the two least significant bytes from
     the EXPRESSION argument.  A `FILL' statement covers memory
     locations *after* the point it occurs in the section definition; by
     including more than one `FILL' statement, you can have different
     fill patterns in different parts of an output section.


See Also: Expressions Symbols Assignment BFD

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