6.2.1 Enabling link time optimization

You must enable link time optimization in both armclang and armlink.

To enable link time optimization:

  1. At compilation time, use the armclang option -flto to produce ELF files suitable for link time optimization. These ELF files contain bitcode in a .llvmbc section.

  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 ELF files src1.o, src2.o, and src3.o. These ELF files contain bitcode.
  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.o
armclang --target=arm-arm-none-eabi -march=armv8-a -c -flto src3.c -o src3.o
armlink --lto src1.o src2.o src3.o -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 ELF files src2.o and src3.o. These ELF files contain bitcode.
  3. armlink passes the bitcode files src2.o and src3.o 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.
Non-ConfidentialPDF file icon PDF versionDUI0773J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.