mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(build): support LTO in the build system v2 (cmakev2)
Mirror the link-time optimization support into the cmakev2 build system so that both build systems behave identically. - project.cmake (__init_project_configuration): emit -flto=auto as a link option when CONFIG_COMPILER_LTO_LINKTIME is set, except for bootloader and ESP-TEE builds, otherwise keep -fno-lto. - build.cmake (idf_build_library): when CONFIG_COMPILER_LTO_COMPILETIME is set, compile each linked component with -flto=auto unless it has linker fragments, is placed by another component's fragment (see tools/cmake/lto.cmake), has opted out via NO_LTO, or is not a static library. - project.cmake: when CONFIG_APP_REPRODUCIBLE_BUILD is also enabled, apply the same three flags as the legacy build system to keep LTO output reproducible: pass the prefix-map options to the linker (so link-time code generation remaps DW_AT_comp_dir), add -save-temps (stable LTRANS object names instead of random $TMPDIR paths in the .map), and pin -frandom-seed (byte-identical LTO GIMPLE bytecode). See the commit message of "feat(build): add options to enable link-time optimization (LTO)" for the full analysis. The gcc-ar / gcc-ranlib selection and the NO_LTO component property are shared with the legacy build system through tools/cmake/toolchain.cmake and the common component registration code, so no cmakev2-specific changes are needed there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d20a986999
commit
493a770d40
@@ -92,6 +92,10 @@ idf_build_set_property(IDF_COMPONENT_OPTIONAL_REQUIRES_MODE DEFERRED)
|
||||
# (CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_*) set below, not the app-level
|
||||
# CONFIG_COMPILER_OPTIMIZATION_* defaults.
|
||||
idf_build_set_property(SET_COMPILER_OPTIMIZATION NO)
|
||||
# The bootloader relies on linker-script section placement matched by object
|
||||
# file name, which LTO does not preserve, so it must never be compiled or linked
|
||||
# with LTO regardless of the application's CONFIG_COMPILER_LTO_* options.
|
||||
idf_build_set_property(SET_COMPILER_LTO NO)
|
||||
|
||||
# Perform internal IDF project initialisation
|
||||
idf_project_init()
|
||||
|
||||
Reference in New Issue
Block a user