mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
Merge branch 'fix/lto_function_data_sections' into 'master'
fix(build): keep per-function sections when generating code at LTO link time See merge request espressif/esp-idf!51629
This commit is contained in:
@@ -294,6 +294,15 @@ endif()
|
||||
if(CONFIG_COMPILER_LTO_LINKTIME AND NOT BOOTLOADER_BUILD AND NOT ESP_TEE_BUILD)
|
||||
list(APPEND link_options "-flto=auto")
|
||||
|
||||
# LTO generates code at link time, so the -ffunction-sections/-fdata-sections
|
||||
# applied to compile_options doesn't reach it: the LTRANS recompilation takes
|
||||
# its code generation options from the link command line. Without them the
|
||||
# LTO partition is emitted as a single .text/.data, which defeats
|
||||
# -Wl,--gc-sections (it can only drop whole sections) and keeps unreferenced
|
||||
# functions in the image.
|
||||
list(APPEND link_options "-ffunction-sections"
|
||||
"-fdata-sections")
|
||||
|
||||
if(CONFIG_APP_REPRODUCIBLE_BUILD)
|
||||
# LTO generates code at link time, where the path remapping applied to
|
||||
# compile_options doesn't take effect, so pass it to the linker as well.
|
||||
|
||||
@@ -443,6 +443,14 @@ function(__init_project_configuration)
|
||||
endif()
|
||||
if(CONFIG_COMPILER_LTO_LINKTIME AND set_compiler_lto)
|
||||
list(APPEND link_options "-flto=auto")
|
||||
# LTO generates code at link time, so the -ffunction-sections/-fdata-sections
|
||||
# applied to compile_options doesn't reach it: the LTRANS recompilation takes
|
||||
# its code generation options from the link command line. Without them the
|
||||
# LTO partition is emitted as a single .text/.data, which defeats
|
||||
# -Wl,--gc-sections (it can only drop whole sections) and keeps unreferenced
|
||||
# functions in the image.
|
||||
list(APPEND link_options "-ffunction-sections"
|
||||
"-fdata-sections")
|
||||
else()
|
||||
list(APPEND compile_options "-fno-lto")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user