fix(mbedtls): fix undefined esp_mbedtls_mem_calloc/free at link time

platform.c (compiled into the 'builtin' archive) calls
esp_mbedtls_mem_calloc and esp_mbedtls_mem_free directly by name via
the MBEDTLS_PLATFORM_STD_CALLOC/FREE macros in esp_config.h.
Previously, esp_mem.c was compiled into the 'tfpsacrypto' archive, which
appears after 'builtin' in the link command, causing the linker to fail
with undefined reference errors when 'builtin' was processed first.

Moving esp_mem.c into 'builtin' to assure that the function used by
esp_mbedtls_mem_calloc and esp_mbedtls_mem_free are available when
pltform.c is linked.
This commit is contained in:
Guillaume Souchere
2026-04-09 10:51:21 +02:00
parent 57ad8c89ab
commit e7cf8cd3cb
3 changed files with 15 additions and 5 deletions
+8 -1
View File
@@ -343,7 +343,14 @@ endif()
if(NOT ${IDF_TARGET} STREQUAL "linux")
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_hardware.c")
endif()
target_sources(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/esp_mem.c")
# esp_mem.c defines esp_mbedtls_mem_calloc/free, which platform.c (inside the
# 'builtin' archive) calls via MBEDTLS_PLATFORM_STD_CALLOC/FREE. Compiling
# esp_mem.c directly into 'builtin' ensures the symbols are in the same archive
# as their caller, avoiding any link-order dependency on a separate archive.
# port/include (for esp_mem.h) and the IDF global includes (sdkconfig.h,
# esp_attr.h, esp_heap_caps.h) are both available here via directory-level
# include_directories set up by idf_component_register before add_subdirectory.
target_sources(builtin PRIVATE "${COMPONENT_DIR}/port/esp_mem.c")
if(CONFIG_SOC_AES_SUPPORTED)
target_include_directories(tfpsacrypto PRIVATE "${COMPONENT_DIR}/port/aes/include")