buildsystem: Enable LTO also for the application

It turns out that currently LTO is enabled only for the kernel.
This commit updates it to enable it for the whole application
and adds additional LTO exclusions required for the standard
C libraries to build and link properly.

Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
This commit is contained in:
Radoslaw Koppel 2024-02-27 13:17:37 +01:00 committed by Carles Cufí
parent 46484da502
commit 118f1592ff
3 changed files with 7 additions and 1 deletions

View File

@ -214,7 +214,7 @@ endif()
zephyr_compile_options(${OPTIMIZATION_FLAG})
if(CONFIG_LTO)
add_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
add_link_options($<TARGET_PROPERTY:linker,lto_arguments>)
endif()

View File

@ -3,6 +3,9 @@
zephyr_library()
zephyr_library_sources(libc-hooks.c)
# Do not allow LTO when compiling libc-hooks.c file
set_source_files_properties(libc-hooks.c PROPERTIES COMPILE_OPTIONS $<TARGET_PROPERTY:compiler,prohibit_lto>)
# Zephyr normally uses -ffreestanding, which with current GNU toolchains
# means that the flag macros used by newlib 3.x <inttypes.h> to signal
# support for PRI.64 macros are not present. To make them available we

View File

@ -3,6 +3,9 @@
zephyr_library()
zephyr_library_sources(libc-hooks.c)
# Do not allow LTO when compiling libc-hooks.c file
set_source_files_properties(libc-hooks.c PROPERTIES COMPILE_OPTIONS $<TARGET_PROPERTY:compiler,prohibit_lto>)
# define __LINUX_ERRNO_EXTENSIONS__ so we get errno defines like -ESHUTDOWN
# used by the network stack
zephyr_compile_definitions(__LINUX_ERRNO_EXTENSIONS__)