| |||
| Home > Using the Basic Linker Functionality > Optimizations and modifications > Unused virtual function elimination | |||
Unused virtual function elimination (VFE) is a refinement of unused section elimination to reduce ROM size in images generated from C++ code. This optimization can also be used to eliminate both unused virtual functions and RTTI objects from your code.
As described in Controlling image contents,
VFE awareness is controlled by linker option --vfemode=.mode
If you do not specify a VFE option on the command line, default
mode is assumed, that is, --vfemode=on.
Unused section elimination efficiently removes unused functions from C code. However, in C++ applications, unused virtual functions and RTTI objects are referenced by pointer tables. This means that the unused section elimination algorithm used by the linker cannot guarantee to remove unused virtual functions 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 virtual functions reliably. This collaboration also enables the linker to remove RTTI objects.
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 were 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:
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.
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.
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.
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.
To stop the compiler producing VFE information, use the compiler
option --no_vfe. However, the recommended way to
switch off VFE is with the linker option --vfemode=off.