Linker and Libraries Guide

SEGMENT_ORDER Directive

The SEGMENT_ORDER directive is used to specify a non-default ordering for segments in the output object.

SEGMENT_ORDER accepts a space separated list of segment names.

        SEGMENT_ORDER  = segment_name...;
        SEGMENT_ORDER += segment_name...;

When the “=” form of assignment is used, the previous segment order list is discarded, and replaced with the new list. The “+=” form of assignment concatenates the new list to the end of the existing list.

By default, the link-editor orders segments as follows.

  1. Loadable segments with explicit addresses set with the VADDR attribute of the LOAD_SEGMENT directive, sorted by address.

  2. Segments ordered using the SEGMENT_ORDER directive, in the order specified.

  3. Loadable segments without explicit addresses, not found in the SEGMENT_ORDER list.

  4. Note segments without explicit addresses, not found in the SEGMENT_ORDER list.

  5. Null segments without explicit addresses, not found in the SEGMENT_ORDER list.


Note –

ELF has some implicit conventions that must be followed by a well formed object.

Mapfiles can be used to create objects that violate these requirements. This should be avoided, as the result of running such an object is undefined.


Unless the HDR_NOALLOC directive is specified, the link-editor enforces the requirement that the first segment must be a loadable segment, and not a note or null segment. HDR_NOALLOC cannot be used for userland objects, and is therefore of little practical use. This feature is used when building operating system kernels.