Dead-Stripping

Normally, the CodeWarrior linker ignores object code that is not referred to by other object code. If the linker detects that an object is not referred to by the rest of the program being linked, the linker will not place that object in its output file. In other words, the linker "dead-strips" objects that are not used.

Dead-stripping ensures the smallest possible output file. Also, dead-stripping relieves you from having to manually exclude unused source code from the compiler and unused object code from the linker.

There are some objects, however, that need to be in the linker's output file even if these objects are not explicitly referred to by other parts of your program. For example, an executable image might contain an interrupt table that the target platform needs, but this interrupt table is not referred to by the rest of the image.

Use the FORCEACTIVE directive in a linker command file to specify to the linker which objects must not be dead-stripped.

FORCEACTIVE example shows an example from a linker command file that tells the linker not to dead-strip an object named InterruptVectorTable .

Listing 1. FORCEACTIVE example
FORCEACTIVE { InterruptVectorTable }

Use FORCEFILES directive to prevent deadstripping entire files. FORCEACTIVE example shows an example from a linker command file that prevents the linker dead-stripping entire files.

Listing 2. FORCEFILES example
FORCEFILES { segfault.o }
Related information
Specifying Link Order in the IDE
Defining the Target's Memory Map
Defining Sections in the Output File
Associating Input Sections With Output Sections
Controlling Alignment
Specifying Memory Area Locations and Sizes
Creating Memory Gaps
Creating Symbols
Linker Command File Syntax
Commands, Directives, and Keywords