You copied the Doc URL to your clipboard.

About link-time code generation

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 files with --ltcg to instruct the linker to perform code generation.

Both armcc and armlink have a --ltcg command-line option to enable LTCG.

Note

The LTCG feature is deprecated. As an alternative ARM recommends you use the --multifile compiler option.

Considerations when using LTCG

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 --ltcg.

  • 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:

    --entry=symbol

    Any input section containing an entry point is not removed. For example, where an object is built without --ltcg.

    Note

    The linker option --entry=object(symbol) is not supported when using LTCG.

Example

The following example shows a typical use of LTCG:

  1. Create ELF object files one.o and two.o with --ltcg:

    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.

  2. Link them using the command:

    armlink --ltcg one.o two.o -o ltcg_image.axf

The linker:

  1. Combines all the immediate code together, losing the link to original object file names.

  2. Performs code generation for the intermediate code.

  3. Creates the output image.

About the intermediate object files generated by link-time code generation

An intermediate ELF object file generated by link-time code generation (LTCG) includes a section called .il, This section is marked with the flags SHF_EXECINSTR and SHF_ALLOC.

Using the intermediate object file one.o from the example, you can use the fromelf command to view these sections, for example:

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)
...
====================================
...

See also

Reference

Linker Reference:

Compiler Reference:

Using the fromelf Image Converter:

Was this page helpful? Yes No