From 6a878eb0bf1ecb43f8303533dc09ed4df6216b0b Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 20 Feb 2026 15:41:44 +0100 Subject: [PATCH] fix(cmakev2): add --cref with MAPFILE_TARGET and remove global -Wl,--cref When MAPFILE_TARGET is used in idf_build_executable, add the linker --cref option so the cross-reference table is written to the map file instead of stdout. Remove the global -Wl,--cref from default link options in project.cmake so cref is only applied where a map file is requested. --- tools/cmakev2/build.cmake | 2 ++ tools/cmakev2/project.cmake | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 75516401064..8084e9095b8 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -597,6 +597,8 @@ function(idf_build_executable executable) if(ARG_MAPFILE_TARGET AND "${linker_type}" STREQUAL "GNU") set(mapfile "${CMAKE_BINARY_DIR}/${ARG_NAME}.map") target_link_options(${executable} PRIVATE "LINKER:--Map=${mapfile}") + # Add cross-reference table to the map file + target_link_options(${executable} PRIVATE "LINKER:--cref") add_custom_command( OUTPUT "${mapfile}" DEPENDS ${executable} diff --git a/tools/cmakev2/project.cmake b/tools/cmakev2/project.cmake index fed486e1575..93212660f1c 100644 --- a/tools/cmakev2/project.cmake +++ b/tools/cmakev2/project.cmake @@ -419,8 +419,6 @@ function(__init_project_configuration) if("${linker_type}" STREQUAL "GNU") set(target_upper "${idf_target}") string(TOUPPER ${target_upper} target_upper) - # Add cross-reference table to the map file - list(APPEND link_options "-Wl,--cref") # Add this symbol as a hint for esp_idf_size to guess the target name list(APPEND link_options "-Wl,--defsym=IDF_TARGET_${target_upper}=0") # Check if linker supports --no-warn-rwx-segments