11.3. Building an Application with LTO

11.3.1. Use the -flto Option to Enable LTO

The LTO feature can be enabled using the -flto option on the tiarmclang command-line.

11.3.1.1. Building an LTO-Enabled Application from the Command-Line Interface (CLI)

  • Compiling and Linking an Application from the CLI

    If compiling and linking from a single tiarmclang command, the -flto option can be inserted among the other compiler options. A typical tiarmclang command-line that turns on the LTO feature will look like this:

    %> tiarmclang -mcpu=cortex-m4 -Oz -flto hello.c -o hello.out -Wl,lnk.cmd,-mhello.map
    
  • Compiling and Linking an Application in Separate Steps with tiarmclang

    If compiling and linking in separate steps, the -flto option should be specified on both the tiarmclang compilation and linking commands, like so:

    %> tiarmclang -mcpu=cortex-m4 -Oz -flto -c hello.c
    %> tiarmclang -mcpu=cortex-m4 -Oz -flto hello.o -o hello.out -Wl,-llnk.cmd,-mhello.map
    

11.3.1.2. Building an LTO-Enabled Application in a Code Composer Studio (CCS) Project

A tiarmclang CCS project that has been imported into or created in a workspace can be built with LTO enabled by checking the Select Link-Time Optimization (LTO) (-flto) box in the Build->Arm Compiler->Optimization tab in the project build settings dialog pop-up window. This capability is available starting in CCS 12.0.

For example, given a simple “Hello World!” CCS project as the project in focus in a workspace, you can click on Project->Build Settings to bring up the Properties pop-up window. Assuming that version 2.1.0.LTS or later of the TI Arm Clang Compiler Tools has been selected in the General->Compiler version and other settings besides -flto have been accounted for, then:

  1. Click on Build->Arm Compiler->Optimization

../../_images/ccs12_lto_build_1.PNG
  1. Click on check-box beside Select Link-Time Optimization (LTO) (-flto)

../../_images/ccs12_lto_build_2.PNG
  1. Click on the Apply and Close button

  2. Build your project

The -flto option will be used in both the compile and link steps of the project build.

If you are using a version of CCS prior to 12.0, then you can still enable LTO for the build of your application. Assuming the same “Hello World!” CCS project with all other settings accounted for, you can enable LTO by inserting the -flto option into both the Build->Arm Compiler and Build->Arm Linker tabs in the Project->Build Settings pop-up window as follows:

  1. Click on Build->Arm Compiler and edit the Command-line pattern contents:

Before:

../../_images/legacy_ccs_lto_build_1.PNG

After:

../../_images/legacy_ccs_lto_build_2.PNG
  1. Simimlarly, for the link-step, click on Build->Arm Linker and edit the Command-line pattern contents:

Before:

../../_images/legacy_ccs_lto_build_3.PNG

After:

../../_images/legacy_ccs_lto_build_4.PNG
  1. Click on the Apply and Close button

  2. Build your project