Section and Memory Maps

Section Definition

A section map is formatted as follows:

SECTIONS {
...
secname [start_expression] [attributes] : [{ contents }]
...
}

Only secname and the : (colon) are required. All other entries may be omitted. All sections in input files which participate in memory layout must be referenced in the section map.

start_expression

The value of this expression is used as the starting address of this section. If omitted, the section starts at the current address. In either case, the starting address is further modified to fit alignment constraints of the subsections included by contents.

attributes

Any number of attributes from the Section Attributes, below, may be specified.

{ contents }

Any number of section inclusion commands and expressions may be specified.

Section inclusion commands are of the form filename(secname), which directs that the section secname from filename should be included. filename may be replaced by * to specify sections in all files not specifically mentioned.

If '{', contents, and '}' or if "{ contents }" are omitted, the linker includes sections named secname from all files, as if { *(secname) } had been entered. To avoid this, specify an empty section as follows: { }.

Expressions may be used to create or modify the value of any symbol. If a non-existent symbol is assigned a value, that symbol is created relative to that section.

The special symbol . (dot) may be referred to in expressions; it evaluates to the current position, which is the offset from the beginning of the section. An assignment increasing the value of dot will add padding at the current position. An assignment decreasing the value of dot will result in an error.

All assignments to any symbol are section relative; the numbers involved are offsets from the start address of the section. See the ABSOLUTE function to get an address.

Depending on the target and the enabled optimizations, program layout may occur multiple times. Therefore you should avoid using expressions which depend on the number of evaluations. If necessary, you may use the expression final() to ensure that an expression is evaluated during the final layout only.

Example:

To set the low bit of a symbol func if the symbol already exists:

.text : { isdefined(func) ? (func += 1) : 0; } /*incorrect, may increment multiple times */
.text : { final(isdefined(func) ? (func += 1) : 0); } /* correct */

Previous

Next



Copyright © 1999, Green Hills Software. All rights reserved.