Hi Brian,

 

It is the expected behavior of LTO. The whole project should be built with LTO enabled if any library used is enabled with LTO. We met a similar issue when we tried to optimize one component in TF-M with LTO.

 

IIRC, no pre-built binaries (maybe CMSIS ones) required by TF-M is built with LTO. It should be unnecessary for TF-M to explicitly disable LTO in linker configuration.

 

Please correct me if I misunderstood your case. You link TF-M secure image to those binaries with LTO enabled. Imho, TF-M may be built with LTO enabled then in your case. But it might not be a common case in TF-M as I mentioned above.

 

Best regards,

David

 

From: Quach, Brian via TF-M <tf-m@lists.trustedfirmware.org>
Sent: Wednesday, April 2, 2025 5:11 PM
To: Jackson Cooper-Driver <Jackson.Cooper-Driver@arm.com>; tf-m@lists.trustedfirmware.org; Antonio De Angelis <Antonio.DeAngelis@arm.com>
Subject: [TF-M] Re: Link Time Optimization

 

Hi Jackson,

 

The issue is that some of our libraries which are linked into the secure image have LTO enabled. 

 

Per https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html:

The important thing to keep in mind is that to enable link-time optimizations you need to use the GCC driver to perform the link step. GCC automatically performs link-time optimization if any of the objects involved were compiled with the -flto command-line option. You can always override the automatic decision to do link-time optimization by passing -fno-lto to the link command.

 

So it seems that the -fno-lto flag must be used to explicitly opt out of LTO.

 

It might be wise to add that flag to toolchain_GNUARM.cmake to ensure no one is unknowingly having LTO enabled as you have not analyzed the impact.

 

Regards,
Brian

 

From: Jackson Cooper-Driver <Jackson.Cooper-Driver@arm.com>
Sent: Wednesday, April 2, 2025 1:46 AM
To: tf-m@lists.trustedfirmware.org; Quach, Brian <brian@ti.com>; Antonio De Angelis <Antonio.DeAngelis@arm.com>
Subject: [EXTERNAL] Re: Link Time Optimization

 

Hi Brian, Worth just saying that GCC does not enable any optimizations by default. LTO needs to be explicitly enabled on the command line using -flto - see the GCC docs here - https: //gcc. gnu. org/onlinedocs/gcc/Optimize-Options. html CMake also

ZjQcmQRYFpfptBannerStart

This message was sent from outside of Texas Instruments.

Do not click links or open attachments unless you recognize the source of this email and know the content is safe.

    Report Suspicious    ‌

ZjQcmQRYFpfptBannerEnd

Hi Brian,

 

Worth just saying that GCC does not enable any optimizations by default. LTO needs to be explicitly enabled on the command line using -flto - see the GCC docs here - https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

 

CMake also has a way to enable LTO using a specific CMake flag which you can set - details here - https://stackoverflow.com/questions/31355692/how-do-i-enable-link-time-optimization-lto-with-cmake

But we do not currently do that in TF-M 

 

 

Thanks,

Jackson


From: Antonio De Angelis via TF-M <tf-m@lists.trustedfirmware.org>
Sent: 01 April 2025 22:44
To: tf-m@lists.trustedfirmware.org <tf-m@lists.trustedfirmware.org>; Quach, Brian <brian@ti.com>
Subject: [TF-M] Re: Link Time Optimization

 

Hi Brian,

 

no, TF-M does not use it (on purpose), i.e. if GCC enables it by default, the impact of LTO has not been assessed.

 

Thanks, Antonio


From: Quach, Brian via TF-M <tf-m@lists.trustedfirmware.org>
Sent: Tuesday, April 1, 2025 16:01
To: tf-m@lists.trustedfirmware.org <tf-m@lists.trustedfirmware.org>
Subject: [TF-M] Link Time Optimization

 

Hi, does TF-M use LTO?   I didn’t see any flags to disable it in toolchain_GNUARM.cmake.   I think for GCC, it’s enabled by default if no flag is set. 

 

Regards,

 

Brian Quach

SimpleLink MCU

Texas Instruments Inc.

12500 TI Blvd, MS F-4000

Dallas, TX 75243

214-479-4076