3.3.4. Unused function elimination

Virtual Function Elimination (VFE) is a refinement of unused section elimination to reduce ROM size in images generated from C++ code. This optimization can be used to eliminate unused virtual functions and RTTI objects from your code.

If a function is compiled in its own section then VFE is synonymous with unused section elimination (see Unused section elimination). However, where an input section contains more that one function, it can only be eliminated if all the functions are unused. The linker cannot remove unused functions from within a section.

In the rest of this section, it is assumed that functions are compiled in their own sections.

Unused section elimination efficiently removes unused functions from C code. However, in C++ applications, unused sections and RTTI objects are referenced by pointer tables. This means that the elimination algorithm used by the linker cannot guarantee to remove sections and RTTI objects reliably.

VFE is a collaboration between the ARM compiler and the linker whereby the compiler supplies extra information about unused virtual functions that is then used by the linker. Based on this analysis, the linker is able to remove unused sections reliably. This collaboration also enables the linker to remove RTTI objects.

Note

Assembler source files do not require VFE annotations, provided that they do not reference the C++ libraries. This is because the linker assumes that no virtual function calls are made by object files that do not reference the C++ libraries. Similarly, C source files that are compiled with an old version of armcc can participate in VFE provided that they do not reference the C++ libraries.

VFE operates in four modes:

On

Use the command-line option --vfemode=on to make the linker VFE aware. This is the default mode if you do not specify a VFE option on the command line.

In this mode the linker chooses force or off mode based on the content of object files:

  • Where every object file contains VFE information or does not refer to C++ libraries, the linker assumes force mode and continues with the elimination.

  • If any object file is missing VFE information and refers to a C++ library, for example, where code has been compiled with a previous release of the ARM tools, the linker assumes off mode, and VFE is disabled silently. Choosing off mode to disable VFE in this situation ensures that the linker does not remove a virtual function that is used by an object with no VFE information.

Off

Use the command-line option --vfemode=off to make armlink ignore any extra information supplied by the compiler. In this mode, the final image is the same as that produced by compiling and linking without VFE awareness.

Force

Use the command-line option --vfemode=force to make the linker VFE aware and force the VFE algorithm to be applied. If some of the object files do not contain VFE information, for example, where they have been compiled with a previous release of the ARM tools, the linker continues with the elimination but displays a warning to alert you to possible errors.

Force no RTTI

Use the command-line option --vfemode=force_no_rtti to make the linker VFE aware and force the removal of all RTTI objects. In this mode all virtual functions are retained.

The compiler places the extra information in sections with names beginning .arm_vfe. These sections are not referenced by the rest of the code and so are ignored by the linker when it is not VFE aware. Such sections do not, therefore, increase the size of the final image but they do increase the size of object files produced by the compiler.

Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0206H
Non-Confidential