10.2.2 Assigning Output Sections to Regions

Once the sizes of all output sections are known, they are assigned to memory regions. Normally a region is specified in the output section definition. If a region is not specified, the first defined memory region will be used.

Memory regions are filled sequentially, from lower to higher addresses, in the same order that sections appear in the section map. A location counter, unique to each region, keeps track of the next available memory location. There are two conditions which may cause gaps in the allocation of memory within a region:

  • The section map specifies an absolute address for an output section.
  • The output section has a particular alignment requirement.

In either case, any intervening memory between the current location counter and the absolute (or aligned) address is skipped. The exact address of all items allocated in memory may be determined from the link map file.

For a section containing an aligned memory block (with the aligned attribute in C or .align directive in assembly), the section must also be aligned, to the same (or greater) alignment value. If two or more input sections have different alignment requirements, the largest alignment is used for the output section.