Linker optimizations
Virtual function elimination
Virtual Function Elimination (VFE) is a linker optimization that removes unneeded virtual functions and dynamic runtime type information.
In order for Virtual Function Elimination to work, all relevant modules must provide information about virtual function table layout, which virtual functions are called, and for which classes dynamic runtime type information is needed. If one or more modules do not provide this information, a warning is generated by the linker and Virtual Function Elimination is not performed.
Danger
If you know that modules that lack such information do not perform any virtual function calls and do not define any virtual function tables, you can use the ‑‑vfe=forced linker option to enable Virtual Function Elimination anyway.
Caution
In the IDE, select Project>Options>Linker>Optimizations>Perform C++ Virtual Function Elimination to enable this optimization.
Currently, tools from IAR provide the information needed for Virtual Function Elimination in a way that the linker can use.
Note
You can disable Virtual Function Elimination entirely by using the ‑‑no_vfe linker option. In this case, no warning will be issued for modules that lack VFE information.
Duplicate section merging
The linker can detect read-only sections with identical contents and keep only one copy of each such section, redirecting all references to any of the duplicate sections to the retained section.
Caution
In the IDE, select Project>Options>Linker>Optimizations>Merge duplicate sections to enable this optimization.
Danger
Use the linker option ‑‑merge_duplicate_sections.
Note
This optimization can cause different functions or constants to have the same address, so if your application depends on the addresses being different, for example, by using the addresses as keys into a table, you should not enable this optimization.
Instruction relaxation
Certain instructions and sequences are tagged by the compiler or assembler as candidates to be removed or transformed at link time, with the detailed knowledge the linker has. One example is when a function call uses an auipc –jalr instruction pair to guarantee 32-bit reach. Because the linker knows how far the destination is, it can often replace the two instructions with a single jal instruction.
To disable instruction relaxation, use the linker option ‑‑disable_relaxation.