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)