The linker is very good at deadstripping unused code and data. Sometimes, however, symbols need to be kept in the output file even if they are never directly referenced. Interrupt handlers, for example, are usually linked at special addresses, without any explicit jumps to transfer control to these places.
Closure blocks provide a way to make symbols immune from deadstripping. The closure is transitive, meaning that symbols referenced by the symbol being closed are also forced into closure, as are any symbols referenced by those symbols, and so on.
The two types of closure blocks available are:
Use FORCE_ACTIVE to include a symbol into the link that would not be otherwise included. An example is shown in the following listing.
FORCE_ACTIVE {break_handler, interrupt_handler, my_function}
Use KEEP_SECTION when you want to keep a section (usually a user-defined section) in the link. The following listing shows an example.
KEEP_SECTION {.interrupt1, .interrupt2}
A variant is REF_INCLUDE. It keeps a section in the link, but only if the file where it is coming from is referenced. This is very useful to include version numbers. The following listing shows an example of this.
REF_INCLUDE {.version}