From 19d69b61eb03bd6229dfed0a7c8895a3dfdaeb7b Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Tue, 2 Jun 2026 10:13:30 +0200 Subject: [PATCH] fix(cmakev2): wrap library archives with --start-group/--end-group Attach the flags as the first and last entries of the library's INTERFACE_LINK_LIBRARIES so the linker re-scans archives until all symbols resolve. --- tools/cmakev2/build.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 06c441a5db6..15ed609b487 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -361,11 +361,25 @@ function(idf_build_library library) # Include the requested components and link their interface targets to the # library. + # + # On the GNU linker, bracket the component interface list with + # --start-group/--end-group so the linker re-scans archives until all + # symbols resolve. Required when the archive defining a __wrap_* + # implementation is encountered after the archive consuming the wrapped + # symbol on the link line; without group iteration the wrap symbol is + # unresolved. + idf_build_get_property(linker_type LINKER_TYPE) + if("${linker_type}" STREQUAL "GNU") + target_link_libraries("${library}" INTERFACE "-Wl,--start-group") + endif() foreach(component_name IN LISTS ARG_COMPONENTS) idf_component_include("${component_name}") idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE) target_link_libraries("${library}" INTERFACE "${component_interface}") endforeach() + if("${linker_type}" STREQUAL "GNU") + target_link_libraries("${library}" INTERFACE "-Wl,--end-group") + endif() # Process optional requirements in DEFERRED mode only (no-op in IMMEDIATE or when unset). idf_build_get_property(opt_req_mode IDF_COMPONENT_OPTIONAL_REQUIRES_MODE)