Next: Input Section, Previous: Output Section Name, Up: SECTIONS [Contents][Index]

#### 3.6.3 Output Section Address

The address is an expression for the VMA (the virtual memory address) of the output section. This address is optional, but if it is provided then the output address will be set exactly as specified.

If the output address is not specified then one will be chosen for the section, based on the heuristic below. This address will be adjusted to fit the alignment requirement of the output section. The alignment requirement is the strictest alignment of any input section contained within the output section.

The output section address heuristic is as follows:

- If an output memory region is set for the section then it is added to this region and its address will be the next free address in that region.
- If the MEMORY command has been used to create a list of memory regions then the first region which has attributes compatible with the section is selected to contain it. The section’s output address will be the next free address in that region; MEMORY.
- If no memory regions were specified, or none match the section then the output address will be based on the current value of the location counter.

For example:

    .text . : { *(.text) }

and

    .text : { *(.text) }

are subtly different. The first will set the address of the ‘`.text`’ output section to the current value of the location counter. The second will set it to the current value of the location counter aligned to the strictest alignment of any of the ‘`.text`’ input sections.

The address may be an arbitrary expression; Expressions. For example, if you want to align the section on a 0x10 byte boundary, so that the lowest four bits of the section address are zero, you could do something like this:

    .text ALIGN(0x10) : { *(.text) }

This works because `ALIGN` returns the current location counter aligned upward to the specified value.

Specifying address for a section will change the value of the location counter, provided that the section is non-empty. (Empty sections are ignored).

Next: Input Section, Previous: Output Section Name, Up: SECTIONS [Contents][Index]