From 9901fc3058fbdba2443c9634a24586c3f506dbda Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 16 Nov 2021 00:04:36 +0100 Subject: [PATCH] cmake: don't pass --gc-sections to macOS linker, use -dead_strip When building for "linux" (~POSIX) target on macOS, the system linker is normally used. MacOS linker doesn't recognise --gc-sections, but has a -dead_strip flag which is equivalent. --- CMakeLists.txt | 6 ++++++ tools/cmake/build.cmake | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b86ac6027..ec4e2bcc66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,12 @@ endif() list(APPEND link_options "-fno-lto") +if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND link_options "-Wl,-dead_strip") +else() + list(APPEND link_options "-Wl,--gc-sections") +endif() + # Placing jump tables in flash would cause issues with code that required # to be placed in IRAM list(APPEND compile_options "-fno-jump-tables") diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 78b95f8d45..51fd0d40c4 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -111,13 +111,10 @@ function(__build_set_default_build_specifications) list(APPEND cxx_compile_options "-std=gnu++11") - list(APPEND link_options "-Wl,--gc-sections") - idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) - idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND) endfunction() #