Skip to content

Commit 7ffef15

Browse files
committed
[nrf fromtree] toolchain: gcc: Add a new LTO_SINGLE_THREADED option for LTO
As described in this issue: zephyrproject-rtos/sdk-ng#1038 `-flto=auto` fails on some (slower) Windows machines due to an issue with the Zephyr SDK's GCC toolchain for Windows. In order to allow users to work around this issue, introduce a new CONFIG_LTO_SINGLE_THREADED option that switches to `-flto=1`, which enforces a single thread when processing LTO. Signed-off-by: Carles Cufi <[email protected]> (cherry picked from commit d0547b6)
1 parent 8c2f434 commit 7ffef15

File tree

7 files changed

+25
-2
lines changed

7 files changed

+25
-2
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,13 @@ compiler_simple_options(simple_options)
311311
toolchain_linker_add_compiler_options(${simple_options})
312312

313313
if(CONFIG_LTO)
314-
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
315-
add_link_options($<TARGET_PROPERTY:linker,lto_arguments>)
314+
if(CONFIG_LTO_SINGLE_THREADED)
315+
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto_st>)
316+
add_link_options($<TARGET_PROPERTY:linker,lto_arguments_st>)
317+
else()
318+
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
319+
add_link_options($<TARGET_PROPERTY:linker,lto_arguments>)
320+
endif()
316321
endif()
317322

318323
if(CONFIG_STD_C23)

Kconfig.zephyr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,14 @@ config LTO
529529
help
530530
This option enables Link Time Optimization.
531531

532+
config LTO_SINGLE_THREADED
533+
bool "Single-threaded LTO"
534+
depends on LTO
535+
help
536+
This option instructs the linker to use a single thread to process
537+
LTO. See the following issue for more info:
538+
https://github.com/zephyrproject-rtos/sdk-ng/issues/1038
539+
532540
config COMPILER_WARNINGS_AS_ERRORS
533541
bool "Treat warnings as errors"
534542
help

cmake/compiler/compiler_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ set_compiler_property(PROPERTY optimization_size_aggressive)
1717

1818
set_compiler_property(PROPERTY optimization_fast)
1919

20+
set_compiler_property(PROPERTY optimization_lto)
21+
set_compiler_property(PROPERTY optimization_lto_st)
22+
2023
#######################################################
2124
# This section covers flags related to warning levels #
2225
#######################################################

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set_compiler_property(PROPERTY optimization_fast -Ofast)
2525

2626
if(CMAKE_C_COMPILER_VERSION GREATER_EQUAL "4.5.0")
2727
set_compiler_property(PROPERTY optimization_lto -flto=auto)
28+
set_compiler_property(PROPERTY optimization_lto_st -flto=1)
2829
set_compiler_property(PROPERTY prohibit_lto -fno-lto)
2930
endif()
3031

cmake/linker/ld/linker_flags.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ endif()
4343
set_property(TARGET linker PROPERTY partial_linking "-r")
4444

4545
set_property(TARGET linker PROPERTY lto_arguments -flto=auto -fno-ipa-sra -ffunction-sections -fdata-sections)
46+
set_property(TARGET linker PROPERTY lto_arguments_st -flto=1 -fno-ipa-sra -ffunction-sections -fdata-sections)
4647

4748
check_set_linker_property(TARGET linker PROPERTY no_relax ${LINKERFLAGPREFIX},--no-relax)
4849

cmake/linker/linker_flags_template.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ set_property(TARGET linker PROPERTY no_relax)
5050
# Linker flag for enabling relaxation of address optimization for jump calls.
5151
set_property(TARGET linker PROPERTY relax)
5252

53+
# Linker flags for Link Time Optimizations (LTO)
54+
set_property(TARGET linker PROPERTY lto_arguments)
55+
set_property(TARGET linker PROPERTY lto_arguments_st)
56+
5357
# Linker flag for defining specs. Defined only by gcc, when gcc is used as
5458
# front-end for ld.
5559
set_compiler_property(PROPERTY specs)

cmake/linker/lld/linker_flags.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif()
1414
set_property(TARGET linker PROPERTY no_position_independent "${LINKERFLAGPREFIX},--no-pie")
1515

1616
set_property(TARGET linker PROPERTY lto_arguments)
17+
set_property(TARGET linker PROPERTY lto_arguments_st)
1718

1819
check_set_linker_property(TARGET linker PROPERTY sort_alignment ${LINKERFLAGPREFIX},--sort-section=alignment)
1920

0 commit comments

Comments
 (0)