Skip to content

Commit b20687d

Browse files
projectgusdpgeorge
authored andcommitted
esp32: Fix link failure due to link library order.
When a wrapped symbol is provided in its own file, it's possible for the linker to skip that file entirely and not return to it depending on the order of libraries passed on the linker command line. This is because these wrapped symbols create linker cycles (libmain_espXX depends on liblwip but liblwip now also depends on libmain for the wrapped functions in lwip_patch.c, for example.) Linker failure for symbols in lwip_patch.c was reproducible if mDNS was disabled in the board configuration. This commit adds an explicit undefined symbol for each file, to ensure the linker will add the wrapped objects on its first pass. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 2bee8e1 commit b20687d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

ports/esp32/esp32_common.cmake

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,19 @@ target_include_directories(${MICROPY_TARGET} PUBLIC
242242
target_link_libraries(${MICROPY_TARGET} micropy_extmod_btree)
243243
target_link_libraries(${MICROPY_TARGET} usermod)
244244

245-
# Enable the panic handler wrapper
246-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND)
247-
248-
# Patch LWIP memory pool allocators (see lwip_patch.c)
249-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_malloc" APPEND)
250-
idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=memp_free" APPEND)
245+
# Extra linker options
246+
# (when wrap symbols are in standalone files, --undefined ensures
247+
# the linker doesn't skip that file.)
248+
target_link_options(${MICROPY_TARGET} PUBLIC
249+
# Patch LWIP memory pool allocators (see lwip_patch.c)
250+
-Wl,--undefined=memp_malloc
251+
-Wl,--wrap=memp_malloc
252+
-Wl,--wrap=memp_free
253+
254+
# Enable the panic handler wrapper
255+
-Wl,--undefined=esp_panic_handler
256+
-Wl,--wrap=esp_panic_handler
257+
)
251258

252259
# Collect all of the include directories and compile definitions for the IDF components,
253260
# including those added by the IDF Component Manager via idf_components.yaml.

0 commit comments

Comments
 (0)