Link-time code generation (LTCG) enables
cross source-file optimization by delaying code generation until
the link stage. This can significantly reduce code size. To enable
LTCG, compile your source with
-c --ltcg to create
objects in an intermediate format. You must then link these object
--ltcg to instruct the linker to perform
Both armcc and armlink have
--ltcg command-line option to enable LTCG.
The LTCG feature is deprecated. As an alternative ARM recommends
you use the
--multifile compiler option.
Be aware of the following when using LTCG:
If no input objects are compiled with
--ltcg, the final object is the same as that produced without LTCG.
Debug information is not preserved in any object files compiled with
--ltcg. However, debug information is still preserved for any object files that are not compiled with
You cannot use specific object file names in scatter files because LTCG causes a temporary object file to be created and used for linking. If you are using a scatter file, then you must match files using the wildcard
*. Otherwise no match is made on the temporary file.
If there is more than one entry point in the input object files provided to the linker, the linker clears all entry points. Therefore, you must specify an entry point on the linker command-line with:
Any input section containing an entry point is not removed. For example, where an object is built without
The linker option
--entry=object(is not supported when using LTCG.
The following example shows a typical use of LTCG:
Create ELF object files
armcc -c --ltcg one.c -o one.o
armcc -c --ltcg two.c -o two.o
The compiler generates intermediate code into the object files.
Link them using the command:
armlink --ltcg one.o two.o -o ltcg_image.axf
Combines all the immediate code together, losing the link to original object file names.
Performs code generation for the intermediate code.
Creates the output image.
An intermediate ELF object file generated by link-time
code generation (LTCG) includes a section called
This section is marked with the flags
Using the intermediate object file
the example, you can use the fromelf command to view these sections,
fromelf --text -v one.o ... ==================================== ** Section #1 Name : .il Type : SHT_PROGBITS (0x00000001) Flags : SHF_ALLOC + SHF_EXECINSTR (0x00000006) ... Link : SHN_UNDEF ... ==================================== ** Section #3 Name : .rel.il Type : SHT_REL (0x00000009) Flags : None (0x00000000) ... Link : Section 2 (.symtab) Info : Section 1 (.il) ... ==================================== ...