From b47155a70bbb17c091c0c52198040ea4541f34e7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 21 Nov 2022 13:06:17 +0100 Subject: [PATCH 1/2] cmake: fix the map file not generated when compiling with Clang When compiling for a chip target with Clang, CMAKE_C_COMPILER_ID="Clang" but the linker is still a GNU linker. Therefore we can still generate the map file. --- tools/cmake/project.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index d4ca3d70f0..5722c606b5 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -512,6 +512,15 @@ macro(project project_name) list(REMOVE_ITEM build_components ${test_components}) endif() + if(CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + # Compiling for the host, and the host is macOS, so the linker is Darwin LD. + # Note, when adding support for Clang and LLD based toolchain this check will + # need to be modified. + set(linker_type "Darwin") + else() + set(linker_type "GNU") + endif() + foreach(build_component ${build_components}) __component_get_target(build_component_target ${build_component}) __component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE) @@ -534,7 +543,7 @@ macro(project project_name) endforeach() - if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + if(linker_type STREQUAL "GNU") set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") set(idf_target "${IDF_TARGET}") string(TOUPPER ${idf_target} idf_target) From 7a298f98ae9f8f8824730c34f1ba9d5cdc3d80dd Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 21 Nov 2022 13:08:05 +0100 Subject: [PATCH 2/2] cmake: fix the linker type check for --whole-archive option Checking that the host is macOS is not sufficient here, since the linker is still a GNU linker when cross-compiling for a chip. Instead, use the linker_type variable introduced in the previous commit. --- tools/cmake/project.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 5722c606b5..49b75bc77d 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -525,17 +525,17 @@ macro(project project_name) __component_get_target(build_component_target ${build_component}) __component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE) if(whole_archive) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(STATUS "Component ${build_component} will be linked with -Wl,-force_load") - target_link_libraries(${project_elf} PRIVATE - "-Wl,-force_load" - ${build_component}) - else() + if(linker_type STREQUAL "GNU") message(STATUS "Component ${build_component} will be linked with -Wl,--whole-archive") target_link_libraries(${project_elf} PRIVATE "-Wl,--whole-archive" ${build_component} "-Wl,--no-whole-archive") + elseif(linker_type STREQUAL "Darwin") + message(STATUS "Component ${build_component} will be linked with -Wl,-force_load") + target_link_libraries(${project_elf} PRIVATE + "-Wl,-force_load" + ${build_component}) endif() else() target_link_libraries(${project_elf} PRIVATE ${build_component})