From b64fb09e6c688fcb94877048e99dbc2173d24c3b Mon Sep 17 00:00:00 2001 From: xuxin19 Date: Tue, 16 Jul 2024 15:50:13 +0800 Subject: [PATCH] cmake:bugfix fix CMake LTO build block it was wrong in https://github.com/apache/nuttx/pull/12423/files#r1618852245 EXTRA_FLAGS is useful in LTO for pass option tu lto linker Signed-off-by: xuxin19 --- CMakeLists.txt | 4 ++-- libs/libc/assert/CMakeLists.txt | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2effa4c918..5d960036f07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -642,8 +642,8 @@ if(NOT CONFIG_ARCH_SIM) # TODO: nostart/nodefault not applicable to nuttx toolchain target_link_libraries( - nuttx PRIVATE -T${ldscript} -Wl,--start-group ${nuttx_libs} - ${nuttx_extra_libs} -Wl,--end-group) + nuttx PRIVATE ${NUTTX_EXTRA_FLAGS} -T${ldscript} -Wl,--start-group + ${nuttx_libs} ${nuttx_extra_libs} -Wl,--end-group) # generate binary outputs in different formats (.bin, .hex, etc) nuttx_generate_outputs(nuttx) diff --git a/libs/libc/assert/CMakeLists.txt b/libs/libc/assert/CMakeLists.txt index 09c4b50b220..e2b2f9a0346 100644 --- a/libs/libc/assert/CMakeLists.txt +++ b/libs/libc/assert/CMakeLists.txt @@ -24,7 +24,10 @@ if(CONFIG_STACK_CANARIES) list(APPEND SRCS lib_stackchk.c) endif() -set_source_files_properties(lib_assert.c PROPERTIES COMPILE_FLAGS -fno-lto) -set_source_files_properties(lib_stackchk.c PROPERTIES COMPILE_FLAGS -fno-lto) - +if(CONFIG_ARCH_TOOLCHAIN_GNU AND NOT CONFIG_LTO_NONE) + set_source_files_properties(lib_assert.c DIRECTORY .. PROPERTIES COMPILE_FLAGS + -fno-lto) + set_source_files_properties(lib_stackchk.c DIRECTORY .. + PROPERTIES COMPILE_FLAGS -fno-lto) +endif() target_sources(c PRIVATE ${SRCS})