From df6505567ca4a7b5f8c81aa059c7c8ffe39edc90 Mon Sep 17 00:00:00 2001 From: xuxin19 Date: Thu, 23 Oct 2025 17:08:45 +0800 Subject: [PATCH] elf(bugfix):fix elf compile link error when enable LTO fix compilation errors when enabling the LTO linker Signed-off-by: xuxin19 --- arch/arm/src/cmake/elf.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake index 57deeba4de3..48735ec85f8 100644 --- a/arch/arm/src/cmake/elf.cmake +++ b/arch/arm/src/cmake/elf.cmake @@ -38,6 +38,12 @@ nuttx_mod_link_options(-r) nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic) -nuttx_elf_link_options_ifdef(CONFIG_DEBUG_OPT_UNUSED_SECTIONS --gc-sections) +if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS) + if("${CMAKE_LD}" MATCHES "gcc$") + nuttx_elf_link_options(-Wl,--gc-sections) + else() + nuttx_elf_link_options(--gc-sections) + endif() +endif() nuttx_elf_link_options(-e __start)