9.6.5 Evaluation

The linker evaluates expressions lazily. It only computes the value of an expression when absolutely necessary.

The linker needs some information, such as the value of the start address of the first section, and the origins and lengths of memory regions, in order to do any linking at all. These values are computed as soon as possible when the linker reads in the linker script.

However, other values (such as symbol values) are not known or needed until after storage allocation. Such values are evaluated later, when other information (such as the sizes of output sections) is available for use in the symbol assignment expression.

The sizes of sections cannot be known until after allocation, so assignments dependent upon these are not performed until after allocation.

Some expressions, such as those depending upon the location counter (.), must be evaluated during section allocation.

If the result of an expression is required, but the value is not available, then an error results. For example, a script like the following:
SECTIONS
  {
    .text 9+this_isnt_constant :
      { *(.text) } 
  }
will cause the error message non-constant expression for initial address.