DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
COFF link editor

Assignment statements

External symbols are globally visible functions or data items. They may be defined and assigned addresses by an assignment statement in a file of COFF ld directives.

Syntax

The syntax of the assignment statement is:

   symbol op expression;
op may be one of the operators ``='', ``+='', ``-='', ``*='', or ``/=''. Assignment statements must be terminated by a semicolon.

Interaction with source code

Assignments statements in an ifile may refer to symbols defined in the object files being linked. These statements cannot directly affect the value of the symbols in the object file, but they can affect the addresses of these symbols.

The following is an example of how assignment statements interact with the source code. Consider the C source file:

   int i = 100;
   int k = 22;
   int j;
   main() {
   	printf("Value of j is %d\n");
   }
Suppose that the object file corresponding to this program is linked with the following ifile:
   j=i+4;
This directive causes the external symbol j to be assigned the address of i plus 4 bytes. This is the same address as external symbol k. The value found at this address will be the integer 22. The action of the C program will be to print `22'.

All assignment statements (with one exception, described in the next paragraph) are evaluated after allocation has been performed. This occurs after all symbols defined in the input file are appropriately relocated but before the actual relocation of the text and data itself. Therefore, if an assignment statement contains any symbol name, the address used for that symbol in the evaluation of the expression reflects the symbols address in the output object file. References within text and data to symbols given a value through an assignment statement access this latest assigned value. Assignment statements are processed in the order in which they are input to ld.

The location counter symbol

Assignment statements are normally placed outside the scope of section definition directives (see ``Section definition directives''). However, there is a special symbol, the dot (.), that can occur only within a section definition directive. This symbol refers to the current address of ld's location counter (a pointer to the next memory address which may be allocated). Assignment expressions involving ``.'' are evaluated during the allocation phase of ld. Assigning a value to ``.'' within a section definition directive can increment (but not decrement) the location counter and create holes within the section, as described in ``Section definition directives''. Assigning the value of ``.'' to a symbol permits the final allocated address of a section to be saved.

Pseudo-functions

The pseudo-function ALIGN is used to increment the location counter so as to align a symbol to an n-byte boundary within an output section, where n is a power of 2. This is done with the expression:

   ALIGN(n)
This function call is equivalent to:
   . = (. + n - 1) &~(n - 1)
SIZEOF and ADDR are pseudo-functions that, given the name of a section, return the size or address of the section, respectively. These may be used in assignment statements.

Types of expression values

Link editor expressions may have either an absolute or a relocatable value. When ld creates a symbol through an assignment statement, the symbol's value is the same type absolute or relocatable, as the expression. That type depends on the following rules:


Next topic: Specifying a memory configuration
Previous topic: Operator Symbols

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003