feat(esp_common): implement composable error code registration via link-time arrays

Refactor the esp_err_to_name() system to decouple esp_common from
higher-level components. Instead of a monolithic generated table,
each component registers its error codes into a dedicated linker
section (.esp_err_msg_table) via idf_define_esp_err_codes() in its
CMakeLists.txt.

New files:
- tools/err_codes_extract.py: extract ESP_ERR_* defines from headers to CSV
- tools/err_codes_to_c.py: generate C source placing entries into linker section
- tools/err_codes_to_rst.py: generate RST documentation from error codes
- tools/cmake/err_codes.cmake: CMake module providing idf_define_esp_err_codes()
- components/esp_common/include/esp_err_codes.h: esp_err_msg_t typedef
- components/esp_common/src/esp_err_to_name_new.c: new lookup using link-time array
- tools/test_apps/build_system/err_codes_check/: CI test app

Changes:
- Remove all optional component dependencies from esp_common/CMakeLists.txt
- Add .esp_err_msg_table section to all 5 linker scripts
- Register error codes in 18 components via idf_define_esp_err_codes()
- Add new scripts to .gitlab/ci/rules.yml build_check patterns
- use new scripts to generate doc and add CI validation
- Update esp_err.rst to add description of composable code registration
This commit is contained in:
Guillaume Souchere
2026-05-28 09:53:32 +02:00
parent f464b587ef
commit d670774f5c
46 changed files with 1333 additions and 1367 deletions
+24 -4
View File
@@ -831,13 +831,29 @@ macro(project project_name)
COMMAND ${CMAKE_COMMAND} -E touch ${project_elf_src}
VERBATIM)
add_custom_target(_project_elf_src DEPENDS "${project_elf_src}")
# On the Linux (host) target the standard GNU ld processes static archives
# in a single left-to-right pass, which fails when component libraries (or
# their transitive dependencies such as the mbedtls sub-libraries) have
# circular symbol references. Wrap all archives in --start-group /
# --end-group so the linker re-scans until every symbol is resolved.
if(CONFIG_IDF_TARGET_LINUX AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
string(CONCAT _link_exe_template
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> -o <TARGET>"
" -Wl,--start-group <LINK_LIBRARIES> -Wl,--end-group")
set(CMAKE_C_LINK_EXECUTABLE "${_link_exe_template}")
string(REPLACE "<CMAKE_C_COMPILER>" "<CMAKE_CXX_COMPILER>"
_link_exe_template "${_link_exe_template}")
string(REPLACE "<CMAKE_C_LINK_FLAGS>" "<CMAKE_CXX_LINK_FLAGS>"
_link_exe_template "${_link_exe_template}")
set(CMAKE_CXX_LINK_EXECUTABLE "${_link_exe_template}")
unset(_link_exe_template)
endif()
add_executable(${project_elf} "${project_elf_src}")
add_dependencies(${project_elf} _project_elf_src)
if(__PROJECT_GROUP_LINK_COMPONENTS)
target_link_libraries(${project_elf} PRIVATE "-Wl,--start-group")
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
@@ -847,6 +863,10 @@ macro(project project_name)
set(linker_type "GNU")
endif()
if(__PROJECT_GROUP_LINK_COMPONENTS)
target_link_libraries(${project_elf} PRIVATE "-Wl,--start-group")
endif()
if(test_components)
if(linker_type STREQUAL "GNU")
target_link_libraries(${project_elf} PRIVATE "-Wl,--whole-archive")