buildsystem: Add an option to enable LTO
This commit adds option to enable Link Time Optimization. Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
This commit is contained in:
parent
3799b93689
commit
26c8776c70
|
@ -213,6 +213,11 @@ endif()
|
||||||
# Apply the final optimization flag(s)
|
# Apply the final optimization flag(s)
|
||||||
zephyr_compile_options(${OPTIMIZATION_FLAG})
|
zephyr_compile_options(${OPTIMIZATION_FLAG})
|
||||||
|
|
||||||
|
if(CONFIG_LTO)
|
||||||
|
add_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
|
||||||
|
add_link_options($<TARGET_PROPERTY:linker,lto_arguments>)
|
||||||
|
endif()
|
||||||
|
|
||||||
# @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig
|
# @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig
|
||||||
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,required>>)
|
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,required>>)
|
||||||
|
|
||||||
|
@ -805,6 +810,10 @@ target_include_directories(${OFFSETS_LIB} PRIVATE
|
||||||
kernel/include
|
kernel/include
|
||||||
${ARCH_DIR}/${ARCH}/include
|
${ARCH_DIR}/${ARCH}/include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Make sure that LTO will never be enabled when compiling offsets.c
|
||||||
|
set_source_files_properties(${OFFSETS_C_PATH} PROPERTIES COMPILE_OPTIONS $<TARGET_PROPERTY:compiler,prohibit_lto>)
|
||||||
|
|
||||||
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
|
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
|
||||||
add_dependencies(zephyr_interface
|
add_dependencies(zephyr_interface
|
||||||
${SYSCALL_LIST_H_TARGET}
|
${SYSCALL_LIST_H_TARGET}
|
||||||
|
|
|
@ -428,6 +428,13 @@ config NO_OPTIMIZATIONS
|
||||||
default stack sizes in order to avoid stack overflows.
|
default stack sizes in order to avoid stack overflows.
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
config LTO
|
||||||
|
bool "Link Time Optimization [EXPERIMENTAL]"
|
||||||
|
depends on !(GEN_ISR_TABLES || GEN_IRQ_VECTOR_TABLE) || ISR_TABLES_LOCAL_DECLARATION
|
||||||
|
select EXPERIMENTAL
|
||||||
|
help
|
||||||
|
This option enables Link Time Optimization.
|
||||||
|
|
||||||
config COMPILER_WARNINGS_AS_ERRORS
|
config COMPILER_WARNINGS_AS_ERRORS
|
||||||
bool "Treat warnings as errors"
|
bool "Treat warnings as errors"
|
||||||
help
|
help
|
||||||
|
|
|
@ -5,8 +5,13 @@
|
||||||
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
find_program(CMAKE_AS ${CROSS_COMPILE}as PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_AS ${CROSS_COMPILE}as PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
if(CONFIG_LTO)
|
||||||
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_AR ${CROSS_COMPILE}gcc-ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
find_program(CMAKE_RANLIB ${CROSS_COMPILE}gcc-ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
else()
|
||||||
|
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
endif()
|
||||||
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
find_program(CMAKE_STRIP ${CROSS_COMPILE}strip PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
find_program(CMAKE_STRIP ${CROSS_COMPILE}strip PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||||
|
|
|
@ -21,6 +21,9 @@ endif()
|
||||||
set_compiler_property(PROPERTY optimization_speed -O2)
|
set_compiler_property(PROPERTY optimization_speed -O2)
|
||||||
set_compiler_property(PROPERTY optimization_size -Os)
|
set_compiler_property(PROPERTY optimization_size -Os)
|
||||||
|
|
||||||
|
set_compiler_property(PROPERTY optimization_lto -flto)
|
||||||
|
set_compiler_property(PROPERTY prohibit_lto -fno-lto)
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
# This section covers flags related to warning levels #
|
# This section covers flags related to warning levels #
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
|
@ -12,6 +12,8 @@ endif()
|
||||||
|
|
||||||
set_property(TARGET linker PROPERTY partial_linking "-r")
|
set_property(TARGET linker PROPERTY partial_linking "-r")
|
||||||
|
|
||||||
|
set_property(TARGET linker PROPERTY lto_arguments -flto -fno-ipa-sra -ffunction-sections -fdata-sections)
|
||||||
|
|
||||||
# Some linker flags might not be purely ld specific, but a combination of
|
# Some linker flags might not be purely ld specific, but a combination of
|
||||||
# linker and compiler, such as:
|
# linker and compiler, such as:
|
||||||
# --coverage for clang
|
# --coverage for clang
|
||||||
|
|
Loading…
Reference in a new issue