You copied the Doc URL to your clipboard.

Enabling link time optimization

To enable link time optimization:

  1. At compilation time, use the armclang option -flto to produce bitcode files suitable for link time optimization.

  2. At link time, use the armlink option --lto to enable link time optimization for the specified bitcode files.

    Note

    armclang automatically passes the --lto option to armlink if the -flto option is used without the -c option.

Example 1: Optimizing all source files

The following example performs link time optimization across all source files:

armclang --target=arm-arm-none-eabi -march=armv8-a -flto src1.c src2.c src3.c -o output.axf

This example does the following:

  1. armclang compiles the C source files src1.c, src2.c, and src3.c to the bitcode files src1.o, src2.o, and src3.o.
  2. armclang automatically invokes armlink with the --lto option.
  3. armlink passes the bitcode files src1.o, src2.o, and src3.o to the link time optimizer to produce a single optimized ELF object file.
  4. armlink creates the executable output.axf from the ELF object file.

Example 2: Optimizing a subset of source files

The following example performs link time optimization for a subset of source files.

armclang --target=arm-arm-none-eabi -march=armv8-a -c src1.c -o src1.o
armclang --target=arm-arm-none-eabi -march=armv8-a -c -flto src2.c -o src2.bc
armclang --target=arm-arm-none-eabi -march=armv8-a -c -flto src3.c -o src3.bc
armlink --lto src1.o src2.bc src3.bc -o output.axf

This example does the following:

  1. armclang compiles the C source file src1.c to the ELF object file src1.o.
  2. armclang compiles the C source files src2.c and src3.c to the bitcode files src2.bc and src3.bc.
  3. armlink passes the bitcode files src2.bc and src3.bc to the link time optimizer to produce a single optimized ELF object file.
  4. armlink combines the ELF object file src1.o with the object file produced by the link time optimizer to create the executable output.axf.

Related information