10.7.2. Reducing Memory Fragmentation

The linker’s allocation algorithm attempts to minimize memory fragmentation. This allows memory to be used more efficiently and increases the probability that your program will fit into memory. The algorithm comprises these steps:

  1. Each output section for which you supply a specific binding address is placed in memory at that address.

  2. Each output section that is included in a specific, named memory range or that has memory attribute restrictions is allocated. Each output section is placed into the first available space within the named area, considering alignment where necessary, unless the –honor_cmdfile_order option is used, in which case the output section is placed with respect to its sequence order as defined by the linker command file.

  3. Any remaining sections are allocated in the order in which they are defined. Sections not defined in a SECTIONS directive are allocated in the order in which they are encountered. Each output section is placed into the first available memory space, considering alignment where necessary.