Closure Segments

An important feature of the linker is deadstripping unused code and data. At times, however, an output file should keep symbols even if there are no direct references to the symbols. Linking for interrupt handlers, for example, is usually at special addresses, without any explicit, control-transfer jumps.

Closure segments let you make symbols immune from deadstripping. This closure is transitive, so that closing a symbol also forces closure on all other referenced symbols.

For example, suppose that:

Specifying symbol _abc in a closure segment would force closure on all six of these symbols.

The three closure-segment directives have specific uses:

The following listing shows an example of each directive.

Listing: Example Closure Sections
# 1st closure segment keeps 3 symbols in link

FORCE_ACTIVE {break_handler, interrupt_handler, my_function}

# 2nd closure segment keeps 2 sections in link

KEEP_SECTION {.interrupt1, .interrupt2}

# 3rd closure segment keeps file-dependent section in link

REF_INCLUDE {.version}