Comparing Arduino IDE and ESP-IDF build systems

1. Context

While figuring out the ESP32 build system, I currently focus on how the ESP-IDF tool builds projects, and how Arduino IDE builds ESP projects on the other hand.

2. Questions

The ESP-IDF framework has a set of “component libraries”. In the Arduino IDE, they are available as precompiled archives. Comparing both raised a lot of questions to me. I’ll explain in the next paragraphs.

3. The Arduino "component libraries"

The Arduino IDE stores the ESP32 component libraries as archive files here:

~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/lib/

I’m trying to figure out how these precompiled component libraries were built in the first place. Thanks to my previous question (see Where to find the archives source code? - ESP32 Forum) I now know where to find the source code for them. If you have the esp-idf tool installed, the source code can be found here:

~/esp/esp-idf/components/

Compiling this source code into those component libraries is not straightforward. This is what I do:

1. I launch a “Hello World” project with the esp-idf tool.

2. I replace the file '~/esp/hello_world/sdkconfig' with '~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/sdkconfig'. In other words, I try to apply the Arduino configurations onto my “Hello World” project.

3. I build the “Hello World” project with full verbosity to see how the component libraries are built.

Since my “Hello World” project has now the exact same configuration settings as Arduino (thanks to replacing the 'sdkconfig' file), the esp component libraries that appear in my project’s build folder should be the same as those in the '~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/lib/' folder. Is this correct?

If that’s correct, then the three-step-approach described above is sufficient to figure out how the component libraries were built for the Arduino IDE.

4. Linking the "component libraries" with the application code

The Arduino IDE uses its precompiled component libraries totally different from how ESP-IDF uses them in the linking step of the final application .elf file. This is how Arduino does it:

xtensa-esp32-elf-g++ -nostdlib
                     -L<esp-sdk>/lib
                     -L<esp-sdk>/ld
                     -T esp32_out.ld
                     -T esp32.project.ld
                     -T esp32.rom.ld
                     -T esp32.peripherals.ld
                     -T esp32.rom.libgcc.ld
                     -T esp32.rom.spiram_incompatible_fns.ld
                     -u esp_app_desc
                     -u ld_include_panic_highint_hdl
                     -u call_user_start_cpu0
                     -Wl,--gc-sections
                     -Wl,-static
                     -Wl,--undefined=uxTopUsedPriority
                     -u __cxa_guard_dummy
                     -u __cxx_fatal_exception
                     -Wl,--start-group
                     /tmp/arduino_build_852524/sketch/WiFiScan.ino.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/ETH.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFi.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiAP.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiClient.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiGeneric.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiMulti.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiSTA.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiScan.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiServer.cpp.o
                     /tmp/arduino_build_852524/libraries/WiFi/WiFiUdp.cpp.o
                     /tmp/arduino_build_852524/core/core.a
                     -lgcc
                     -lesp_websocket_client
                     -lwpa2
                     -ldetection
                     -lesp_https_server
                     -lwps
                     -lhal
                     -lconsole
                     -lpe
                     -lsoc
                     -lsdmmc
                     -lpthread
                     -llog
                     -lesp_http_client
                     -ljson
                     -lmesh
                     -lesp32-camera
                     -lnet80211
                     -lwpa_supplicant
                     -lc
                     -lmqtt
                     -lcxx
                     -lesp_https_ota
                     -lulp
                     -lefuse
                     -lpp
                     -lmdns
                     -lbt
                     -lwpa
                     -lspiffs
                     -lheap
                     -limage_util
                     -lunity
                     -lrtc
                     -lmbedtls
                     -lface_recognition
                     -lnghttp
                     -ljsmn
                     -lopenssl
                     -lcore
                     -lfatfs
                     -lm
                     -lprotocomm
                     -lsmartconfig
                     -lxtensa-debug-module
                     -ldl
                     -lesp_event
                     -lesp-tls
                     -lfd
                     -lespcoredump
                     -lesp_http_server
                     -lfr
                     -lsmartconfig_ack
                     -lwear_levelling
                     -ltcp_transport
                     -llwip
                     -lphy
                     -lvfs
                     -lcoap
                     -lesp32
                     -llibsodium
                     -lbootloader_support
                     -ldriver
                     -lcoexist
                     -lasio
                     -lod
                     -lmicro-ecc
                     -lesp_ringbuf
                     -ldetection_cat_face
                     -lapp_update
                     -lespnow
                     -lface_detection
                     -lapp_trace
                     -lnewlib
                     -lbtdm_app
                     -lwifi_provisioning
                     -lfreertos
                     -lfreemodbus
                     -lethernet
                     -lnvs_flash
                     -lspi_flash
                     -lc_nano
                     -lexpat
                     -lfb_gfx
                     -lprotobuf-c
                     -lesp_adc_cal
                     -ltcpip_adapter
                     -lstdc++
                     -Wl,--end-group
                     -Wl,-EL
                     -o /tmp/arduino_build_852524/WiFiScan.ino.elf

The precompiled component libraries are sitting in the folder <esp-sdk>/lib (actually in ~/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools/sdk/lib, but I’m using some placeholders here for brevity). This folder is exposed to the linker through the -L<esp-sdk>/lib flag. After listing all the relevant object files of the application, the libraries are then passed to the linker with -l flags. The linker knows where to find them.

This is how the linking happens with the ESP-IDF tool:

xtensa-esp32-elf-g++ -mlongcalls
                     -Wno-frame-address
                     CMakeFiles/hello-world.elf.dir/project_elf_src_esp32.c.obj
                     -o hello-world.elf
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/asio/libasio.a
                     esp-idf/bt/libbt.a
                     esp-idf/cbor/libcbor.a
                     esp-idf/unity/libunity.a
                     esp-idf/cmock/libcmock.a
                     esp-idf/coap/libcoap.a
                     esp-idf/console/libconsole.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/esp_adc_cal/libesp_adc_cal.a
                     esp-idf/esp_hid/libesp_hid.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/protobuf-c/libprotobuf-c.a
                     esp-idf/protocomm/libprotocomm.a
                     esp-idf/mdns/libmdns.a
                     esp-idf/esp_local_ctrl/libesp_local_ctrl.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/esp_websocket_client/libesp_websocket_client.a
                     esp-idf/expat/libexpat.a
                     esp-idf/wear_levelling/libwear_levelling.a
                     esp-idf/fatfs/libfatfs.a
                     esp-idf/freemodbus/libfreemodbus.a
                     esp-idf/jsmn/libjsmn.a
                     esp-idf/json/libjson.a
                     esp-idf/libsodium/liblibsodium.a
                     esp-idf/mqtt/libmqtt.a
                     esp-idf/openssl/libopenssl.a
                     esp-idf/spiffs/libspiffs.a
                     esp-idf/ulp/libulp.a
                     esp-idf/wifi_provisioning/libwifi_provisioning.a
                     esp-idf/main/libmain.a
                     -Wl,--cref -Wl,--Map=/home/kristof/esp/hello_world/build/hello-world.map -Wl,--gc-sections -fno-rtti -fno-lto esp-idf/asio/libasio.a
                     esp-idf/cbor/libcbor.a
                     esp-idf/cmock/libcmock.a
                     esp-idf/unity/libunity.a
                     esp-idf/coap/libcoap.a
                     esp-idf/esp_adc_cal/libesp_adc_cal.a
                     esp-idf/esp_hid/libesp_hid.a
                     esp-idf/esp_local_ctrl/libesp_local_ctrl.a
                     esp-idf/esp_websocket_client/libesp_websocket_client.a
                     esp-idf/expat/libexpat.a
                     esp-idf/fatfs/libfatfs.a
                     esp-idf/wear_levelling/libwear_levelling.a
                     esp-idf/freemodbus/libfreemodbus.a
                     esp-idf/jsmn/libjsmn.a
                     esp-idf/libsodium/liblibsodium.a
                     esp-idf/mqtt/libmqtt.a
                     esp-idf/openssl/libopenssl.a
                     esp-idf/spiffs/libspiffs.a
                     esp-idf/wifi_provisioning/libwifi_provisioning.a
                     esp-idf/protocomm/libprotocomm.a
                     esp-idf/bt/libbt.a
                     -L/home/kristof/esp/esp-idf/components/bt/controller/lib/esp32 -lbtdm_app esp-idf/protobuf-c/libprotobuf-c.a
                     esp-idf/mdns/libmdns.a
                     esp-idf/console/libconsole.a
                     esp-idf/json/libjson.a
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a
                     esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a
                     esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a
                     esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a
                     esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a
                     esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a
                     esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a
                     esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a
                     esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a
                     esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a
                     esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/ulp/libulp.a
                     esp-idf/mbedtls/mbedtls/library/libmbedtls.a
                     esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
                     esp-idf/mbedtls/mbedtls/library/libmbedx509.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcoexist.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcore.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libespnow.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libmesh.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libnet80211.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libpp.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libsmartconfig.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libwapi.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libphy.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/librtc.a
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a
                     esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a
                     esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a
                     esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a
                     esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a
                     esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a
                     esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a
                     esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a
                     esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a
                     esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a
                     esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/ulp/libulp.a
                     esp-idf/mbedtls/mbedtls/library/libmbedtls.a
                     esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
                     esp-idf/mbedtls/mbedtls/library/libmbedx509.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcoexist.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcore.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libespnow.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libmesh.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libnet80211.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libpp.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libsmartconfig.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libwapi.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libphy.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/librtc.a
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a
                     esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a
                     esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a
                     esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a
                     esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a
                     esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a
                     esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a
                     esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a
                     esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a
                     esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a
                     esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/ulp/libulp.a
                     esp-idf/mbedtls/mbedtls/library/libmbedtls.a
                     esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
                     esp-idf/mbedtls/mbedtls/library/libmbedx509.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcoexist.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcore.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libespnow.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libmesh.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libnet80211.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libpp.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libsmartconfig.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libwapi.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libphy.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/librtc.a
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a
                     esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a
                     esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a
                     esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a
                     esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a
                     esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a
                     esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a
                     esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a
                     esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a
                     esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a
                     esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/ulp/libulp.a
                     esp-idf/mbedtls/mbedtls/library/libmbedtls.a
                     esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
                     esp-idf/mbedtls/mbedtls/library/libmbedx509.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcoexist.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcore.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libespnow.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libmesh.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libnet80211.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libpp.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libsmartconfig.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libwapi.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libphy.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/librtc.a
                     esp-idf/mbedtls/libmbedtls.a
                     esp-idf/efuse/libefuse.a
                     esp-idf/app_update/libapp_update.a
                     esp-idf/bootloader_support/libbootloader_support.a
                     esp-idf/esp_ipc/libesp_ipc.a
                     esp-idf/spi_flash/libspi_flash.a
                     esp-idf/nvs_flash/libnvs_flash.a
                     esp-idf/pthread/libpthread.a
                     esp-idf/esp_gdbstub/libesp_gdbstub.a
                     esp-idf/espcoredump/libespcoredump.a
                     esp-idf/esp_system/libesp_system.a
                     esp-idf/esp_rom/libesp_rom.a
                     esp-idf/hal/libhal.a
                     esp-idf/vfs/libvfs.a
                     esp-idf/esp_eth/libesp_eth.a
                     esp-idf/tcpip_adapter/libtcpip_adapter.a
                     esp-idf/esp_netif/libesp_netif.a
                     esp-idf/esp_event/libesp_event.a
                     esp-idf/wpa_supplicant/libwpa_supplicant.a
                     esp-idf/esp_wifi/libesp_wifi.a
                     esp-idf/lwip/liblwip.a
                     esp-idf/log/liblog.a
                     esp-idf/heap/libheap.a
                     esp-idf/soc/libsoc.a
                     esp-idf/esp_hw_support/libesp_hw_support.a
                     esp-idf/esp_pm/libesp_pm.a
                     esp-idf/esp_ringbuf/libesp_ringbuf.a
                     esp-idf/driver/libdriver.a
                     esp-idf/xtensa/libxtensa.a
                     esp-idf/perfmon/libperfmon.a
                     esp-idf/esp32/libesp32.a
                     esp-idf/esp_common/libesp_common.a
                     esp-idf/esp_timer/libesp_timer.a
                     esp-idf/freertos/libfreertos.a
                     esp-idf/newlib/libnewlib.a
                     esp-idf/cxx/libcxx.a
                     esp-idf/app_trace/libapp_trace.a
                     esp-idf/nghttp/libnghttp.a
                     esp-idf/esp-tls/libesp-tls.a
                     esp-idf/tcp_transport/libtcp_transport.a
                     esp-idf/esp_http_client/libesp_http_client.a
                     esp-idf/esp_http_server/libesp_http_server.a
                     esp-idf/esp_https_ota/libesp_https_ota.a
                     esp-idf/sdmmc/libsdmmc.a
                     esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a
                     esp-idf/ulp/libulp.a
                     esp-idf/mbedtls/mbedtls/library/libmbedtls.a
                     esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
                     esp-idf/mbedtls/mbedtls/library/libmbedx509.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcoexist.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libcore.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libespnow.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libmesh.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libnet80211.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libpp.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libsmartconfig.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libwapi.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/libphy.a
                     /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32/librtc.a
                     -Wl,--wrap=mbedtls_mpi_exp_mod
                     -u esp_app_desc
                     -u pthread_include_pthread_impl
                     -u pthread_include_pthread_cond_impl
                     -u pthread_include_pthread_local_storage_impl
                     -u ld_include_panic_highint_hdl
                     -u start_app
                     -u start_app_other_cores
                     -L /home/kristof/esp/esp-idf/components/esp_rom/esp32/ld
                     -T esp32.rom.ld
                     -T esp32.rom.api.ld
                     -T esp32.rom.libgcc.ld
                     -T esp32.rom.newlib-data.ld
                     -T esp32.rom.syscalls.ld
                     -u vfs_include_syscalls_impl
                     -L /home/kristof/esp/esp-idf/components/esp_wifi/lib/esp32
                     /home/kristof/esp/esp-idf/components/xtensa/esp32/libxt_hal.a
                     -L /home/kristof/esp/hello_world/build/esp-idf/esp32
                     -T esp32_out.ld
                     -L /home/kristof/esp/hello_world/build/esp-idf/esp32/ld
                     -T esp32.project.ld
                     -L /home/kristof/esp/esp-idf/components/esp32/ld
                     -T esp32.peripherals.ld
                     -u call_user_start_cpu0
                     -mfix-esp32-psram-cache-issue
                     -mfix-esp32-psram-cache-strategy=memw
                     -Wl,--undefined=uxTopUsedPriority
                     -u app_main
                     -lm esp-idf/newlib/libnewlib.a
                     -u newlib_include_heap_impl
                     -u newlib_include_syscalls_impl
                     -u newlib_include_pthread_impl
                     -lgcc
                     -u __cxa_guard_dummy
                     -lstdc++ esp-idf/pthread/libpthread.a
                     esp-idf/app_trace/libapp_trace.a
                     -lgcov
                     esp-idf/app_trace/libapp_trace.a
                     -lgcov
                     -lc

The approach is a bit different. But the result should be the same: the archive files get passed to the linker, such that they are available to be linked against the application code.

However, what really troubles me is that some component libraries appear twice or more in the ESP-IDF linker call! Take for example the mbedtls library. The Arduino linker call passes this library to the linker just once:

xtensa-esp32-elf-g++
    ...
    -lmbedtls
    ...

And if you look in the Arduino folder where the archive files are, you’ll find just one libmbedtls.a file. Now consider the ESP-IDF linker call, passing the mbedtls library multiple times:

xtensa-esp32-elf-g++
    ...
    esp-idf/mbedtls/libmbedtls.a
    esp-idf/mbedtls/mbedtls/library/libmbedtls.a
    esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
    esp-idf/mbedtls/mbedtls/library/libmbedx509.a
    ...
    esp-idf/mbedtls/libmbedtls.a
    esp-idf/mbedtls/mbedtls/library/libmbedtls.a
    esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
    esp-idf/mbedtls/mbedtls/library/libmbedx509.a
    ...

You see, it not only gets passed multiple times to the linker, but there are even two different files with the name libmbedtls.a. Aside from that, there are also two other archive files that have something to do with this mbedtls library: libmbedcrypto.a and libmbedx509.a.

All of this confuses me. Why isn’t there just a single libmbedtls.a file produced by the ESP-IDF tool?


EDIT:
My colleague Johan explained me that adding the same archive file multiple times to the linker is an old trick to overcome circular dependencies. The Arduino IDE solves this by encapsulating the archive files between -Wl,--start-group and -Wl,--end-group flags. However, the other problem still remains: why are there two different libmbedtls.a files - one at ~/esp/hello_world/build/esp-idf/mbedtls/libmbedtls.a and the other at ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedtls.a?

Also, these two files are certainly not identical, if you look at how they are compiled. This is the compilation of ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedtls.a:

[ 58%] Linking CXX static library libmbedtls.a
cd /home/kristof/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library
xtensa-esp32-elf-ar qc
                    libmbedtls.a
                    CMakeFiles/mbedtls.dir/debug.c.obj
                    CMakeFiles/mbedtls.dir/ssl_cache.c.obj
                    CMakeFiles/mbedtls.dir/ssl_ciphersuites.c.obj
                    CMakeFiles/mbedtls.dir/ssl_cli.c.obj
                    CMakeFiles/mbedtls.dir/ssl_cookie.c.obj
                    CMakeFiles/mbedtls.dir/ssl_srv.c.obj
                    CMakeFiles/mbedtls.dir/ssl_ticket.c.obj
                    CMakeFiles/mbedtls.dir/ssl_tls.c.obj
                    CMakeFiles/mbedtls.dir/__/__/port/mbedtls_debug.c.obj
                    CMakeFiles/mbedtls.dir/__/__/port/net_sockets.c.obj

xtensa-esp32-elf-ranlib libmbedtls.a

and this is the compilation of ~/esp/hello_world/build/esp-idf/mbedtls/libmbedtls.a:

[ 59%] Linking C static library libmbedtls.a
cd /home/kristof/esp/hello_world/build/esp-idf/mbedtls

xtensa-esp32-elf-ar qc
                    libmbedtls.a
                    CMakeFiles/__idf_mbedtls.dir/esp_crt_bundle/esp_crt_bundle.c.obj
                    CMakeFiles/__idf_mbedtls.dir/__/__/x509_crt_bundle.S.obj

xtensa-esp32-elf-ranlib libmbedtls.a

1 Like

@kristof

We do not use “start-group”/“end-group” linker flags as part of our ESP-IDF CMake build systems. Instead, we encourage that components (library archive) specifies its requirement clearly in its build template through “REQUIRES” or “PRIV_REQUIRES” constructs, more on this at: Build System - ESP32 - — ESP-IDF Programming Guide latest documentation

This allows to identify dependencies precisely, rather than creating lot of circular dependencies without noticing this. Similar thread discussing 2 approaches is at c++ - Resolving circular dependencies by linking the same library twice? - Stack Overflow

Coming to next problem which is mbedtls build, this is third party project which has its own CMake build system. So approach here is little different, as described at Build System - ESP32 - — ESP-IDF Programming Guide latest documentation

ESP-IDF build system builds “libmedtls.a” as its component and mbedtls library builds 3 additional archives “libmbedcrypto.a libmbedtls.a libmbedx509.a” per its build template.

If you look at object files within ESP-IDF built “libmbedtls.a” then it only contains couple of port files:

$ size build/esp-idf/mbedtls/libmbedtls.a 
   text	   data	    bss	    dec	    hex	filename
   1635	      0	    324	   1959	    7a7	esp_crt_bundle.c.obj (ex build/esp-idf/mbedtls/libmbedtls.a)
  64212	      0	      0	  64212	   fad4	x509_crt_bundle.S.obj (ex build/esp-idf/mbedtls/libmbedtls.a)

So yes, all 4 libraries would be required during linking step for successful application build.

Hope this information helps here!

Hi @mahavir ,
Thank you very much for your reply. It’s an interesting idea to compare the libraries this way. I just ran the size command on the Arduino-generated libmbedtls.a archive:

# Arduino generated 'libmbedtls.a'
$size libmbedtls.a

   text	   data	    bss	    dec	    hex	filename
   6341	      0	      0	   6341	   18c5	sha1.o (ex libmbedtls.a)
   1872	      0	      0	   1872	    750	x509_csr.o (ex libmbedtls.a)
   9330	      0	      0	   9330	   2472	ssl_cli.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	camellia.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	chachapoly.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	blowfish.o (ex libmbedtls.a)
   3866	      0	      0	   3866	    f1a	x509.o (ex libmbedtls.a)
   1518	      0	      0	   1518	    5ee	ssl_ticket.o (ex libmbedtls.a)
  10510	     28	      0	  10538	   292a	ecp_curves.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	pkcs11.o (ex libmbedtls.a)
   1100	      0	      0	   1100	    44c	pk.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	entropy_poll.o (ex libmbedtls.a)
   2981	      0	      4	   2985	    ba9	cipher.o (ex libmbedtls.a)
  53205	     68	      0	  53273	   d019	certs.o (ex libmbedtls.a)
   3005	    456	      0	   3461	    d85	version_features.o (ex libmbedtls.a)
   4394	      0	      0	   4394	   112a	md5.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	nist_kw.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	ripemd160.o (ex libmbedtls.a)
  12794	      0	      0	  12794	   31fa	rsa.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	hkdf.o (ex libmbedtls.a)
   1152	      0	      0	   1152	    480	md_wrap.o (ex libmbedtls.a)
   3263	      0	      0	   3263	    cbf	dhm.o (ex libmbedtls.a)
   3254	      0	      0	   3254	    cb6	x509_crl.o (ex libmbedtls.a)
   2488	      0	      0	   2488	    9b8	pkwrite.o (ex libmbedtls.a)
   1424	      0	      0	   1424	    590	base64.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	timing.o (ex libmbedtls.a)
   1272	      0	      0	   1272	    4f8	asn1parse.o (ex libmbedtls.a)
  19988	     60	      0	  20048	   4e50	ssl_tls.o (ex libmbedtls.a)
     88	      0	      0	     88	     58	version.o (ex libmbedtls.a)
    695	      0	      0	    695	    2b7	ssl_cache.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	cmac.o (ex libmbedtls.a)
   2033	      0	      0	   2033	    7f1	x509_create.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	md2.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	chacha20.o (ex libmbedtls.a)
   9589	      0	      0	   9589	   2575	ssl_srv.o (ex libmbedtls.a)
  11897	      0	      0	  11897	   2e79	x509_crt.o (ex libmbedtls.a)
   1382	      0	      0	   1382	    566	ecdh.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	aria.o (ex libmbedtls.a)
   4923	      0	      0	   4923	   133b	sha256.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	ecjpake.o (ex libmbedtls.a)
   6147	      0	      0	   6147	   1803	oid.o (ex libmbedtls.a)
   1762	      0	      0	   1762	    6e2	asn1write.o (ex libmbedtls.a)
   2857	      0	      0	   2857	    b29	ecdsa.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	xtea.o (ex libmbedtls.a)
  15180	      0	     64	  15244	   3b8c	ecp.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	aesni.o (ex libmbedtls.a)
   2469	      0	      0	   2469	    9a5	rsa_internal.o (ex libmbedtls.a)
   3322	      0	      0	   3322	    cfa	x509write_crt.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	arc4.o (ex libmbedtls.a)
  15912	      0	      0	  15912	   3e28	bignum.o (ex libmbedtls.a)
   6260	      0	      0	   6260	   1874	pkparse.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	padlock.o (ex libmbedtls.a)
   1802	      0	      0	   1802	    70a	cipher_wrap.o (ex libmbedtls.a)
   1982	      0	      0	   1982	    7be	md.o (ex libmbedtls.a)
   7385	      0	      0	   7385	   1cd9	gcm.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	havege.o (ex libmbedtls.a)
   7159	      0	    320	   7479	   1d37	ssl_ciphersuites.o (ex libmbedtls.a)
   3566	      0	      0	   3566	    dee	aes.o (ex libmbedtls.a)
   2178	      0	      0	   2178	    882	pem.o (ex libmbedtls.a)
    870	      0	      0	    870	    366	ssl_cookie.o (ex libmbedtls.a)
     28	      4	      0	     32	     20	platform_util.o (ex libmbedtls.a)
   2575	      0	      0	   2575	    a0f	ccm.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	poly1305.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	memory_buffer_alloc.o (ex libmbedtls.a)
   2939	      0	      4	   2943	    b7f	hmac_drbg.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	des.o (ex libmbedtls.a)
   1718	      0	      0	   1718	    6b6	x509write_csr.o (ex libmbedtls.a)
     86	      8	      0	     94	     5e	platform.o (ex libmbedtls.a)
   3462	      0	      4	   3466	    d8a	ctr_drbg.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	debug.o (ex libmbedtls.a)
   1668	      0	      0	   1668	    684	pk_wrap.o (ex libmbedtls.a)
   2286	      0	      0	   2286	    8ee	entropy.o (ex libmbedtls.a)
   7613	      0	      0	   7613	   1dbd	sha512.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	md4.o (ex libmbedtls.a)
   1694	      0	      0	   1694	    69e	pkcs12.o (ex libmbedtls.a)
  17160	      0	      0	  17160	   4308	error.o (ex libmbedtls.a)
   2492	      0	      0	   2492	    9bc	pkcs5.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	threading.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	mbedtls_debug.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	esp_sha1.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	esp_sha256.o (ex libmbedtls.a)
   1187	      0	      4	   1191	    4a7	esp_bignum.o (ex libmbedtls.a)
   1695	      0	      0	   1695	    69f	net_sockets.o (ex libmbedtls.a)
     26	      0	      0	     26	     1a	esp_hardware.o (ex libmbedtls.a)
     46	      0	      0	     46	     2e	esp_mem.o (ex libmbedtls.a)
      0	      0	      0	      0	      0	esp_sha512.o (ex libmbedtls.a)

The result for the ESP-IDF generated libmbedtls.a is indeed very different. The one at ~/esp/hello_world/build/esp-idf/mbedtls/libmbedtls.a gives this result:

# ESP-IDF generated 'libmbedtls.a'
$size libmbedtls.a

   text	   data	    bss	    dec	    hex	filename
   1536	      0	    324	   1860	    744	esp_crt_bundle.c.obj (ex libmbedtls.a)
  64212	      0	      0	  64212	   fad4	x509_crt_bundle.S.obj (ex libmbedtls.a)

The one at ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedtls.a gives this result:

# ESP-IDF generated 'libmbedtls.a' (in 'mbedtls/library/' subfolder)
$size libmbedtls.a

   text	   data	    bss	    dec	    hex	filename
      0	      0	      0	      0	      0	debug.c.obj (ex libmbedtls.a)
    707	      0	      0	    707	    2c3	ssl_cache.c.obj (ex libmbedtls.a)
   7189	      0	    320	   7509	   1d55	ssl_ciphersuites.c.obj (ex libmbedtls.a)
   9027	      0	      0	   9027	   2343	ssl_cli.c.obj (ex libmbedtls.a)
    827	      0	      0	    827	    33b	ssl_cookie.c.obj (ex libmbedtls.a)
   9336	      0	      0	   9336	   2478	ssl_srv.c.obj (ex libmbedtls.a)
   1505	      0	      0	   1505	    5e1	ssl_ticket.c.obj (ex libmbedtls.a)
  20452	     60	      0	  20512	   5020	ssl_tls.c.obj (ex libmbedtls.a)
      0	      0	      0	      0	      0	mbedtls_debug.c.obj (ex libmbedtls.a)
   1680	      0	      0	   1680	    690	net_sockets.c.obj (ex libmbedtls.a)

And finally there are also the files ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a:

# ESP-IDF generated 'libmbedcrypto.a' (in 'mbedtls/library/' subfolder)
$size libmbedcrypto.a

   text	   data	    bss	    dec	    hex	filename
   4338	      0	      0	   4338	   10f2	aes.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	aesni.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	arc4.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	aria.c.obj (ex libmbedcrypto.a)
   1217	      0	      0	   1217	    4c1	asn1parse.c.obj (ex libmbedcrypto.a)
   1738	      0	      0	   1738	    6ca	asn1write.c.obj (ex libmbedcrypto.a)
   1454	      0	      0	   1454	    5ae	base64.c.obj (ex libmbedcrypto.a)
  15638	      0	      0	  15638	   3d16	bignum.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	blowfish.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	camellia.c.obj (ex libmbedcrypto.a)
   2536	      0	      0	   2536	    9e8	ccm.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	chacha20.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	chachapoly.c.obj (ex libmbedcrypto.a)
   3016	      0	      4	   3020	    bcc	cipher.c.obj (ex libmbedcrypto.a)
   1994	      0	      0	   1994	    7ca	cipher_wrap.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	cmac.c.obj (ex libmbedcrypto.a)
   3426	      0	      4	   3430	    d66	ctr_drbg.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	des.c.obj (ex libmbedcrypto.a)
   3333	      0	      0	   3333	    d05	dhm.c.obj (ex libmbedcrypto.a)
   1349	      0	      0	   1349	    545	ecdh.c.obj (ex libmbedcrypto.a)
   2779	      0	      0	   2779	    adb	ecdsa.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	ecjpake.c.obj (ex libmbedcrypto.a)
  14965	      0	     64	  15029	   3ab5	ecp.c.obj (ex libmbedcrypto.a)
  10315	     28	      0	  10343	   2867	ecp_curves.c.obj (ex libmbedcrypto.a)
   2307	      0	      0	   2307	    903	entropy.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	entropy_poll.c.obj (ex libmbedcrypto.a)
  17160	      0	      0	  17160	   4308	error.c.obj (ex libmbedcrypto.a)
   7243	      0	      0	   7243	   1c4b	gcm.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	havege.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	hkdf.c.obj (ex libmbedcrypto.a)
   2872	      0	      4	   2876	    b3c	hmac_drbg.c.obj (ex libmbedcrypto.a)
   2013	      0	      0	   2013	    7dd	md.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	md2.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	md4.c.obj (ex libmbedcrypto.a)
   4398	      0	      0	   4398	   112e	md5.c.obj (ex libmbedcrypto.a)
   1152	      0	      0	   1152	    480	md_wrap.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	memory_buffer_alloc.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	nist_kw.c.obj (ex libmbedcrypto.a)
   6187	      0	      0	   6187	   182b	oid.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	padlock.c.obj (ex libmbedcrypto.a)
   2178	      0	      0	   2178	    882	pem.c.obj (ex libmbedcrypto.a)
   1120	      0	      0	   1120	    460	pk.c.obj (ex libmbedcrypto.a)
   1645	      0	      0	   1645	    66d	pk_wrap.c.obj (ex libmbedcrypto.a)
   1694	      0	      0	   1694	    69e	pkcs12.c.obj (ex libmbedcrypto.a)
   2510	      0	      0	   2510	    9ce	pkcs5.c.obj (ex libmbedcrypto.a)
   6166	      0	      0	   6166	   1816	pkparse.c.obj (ex libmbedcrypto.a)
   2372	      0	      0	   2372	    944	pkwrite.c.obj (ex libmbedcrypto.a)
     83	      8	      0	     91	     5b	platform.c.obj (ex libmbedcrypto.a)
     28	      4	      0	     32	     20	platform_util.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	poly1305.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	ripemd160.c.obj (ex libmbedcrypto.a)
  12684	      0	      0	  12684	   318c	rsa.c.obj (ex libmbedcrypto.a)
   2353	      0	      0	   2353	    931	rsa_internal.c.obj (ex libmbedcrypto.a)
    873	      0	      0	    873	    369	sha1.c.obj (ex libmbedcrypto.a)
   1084	      0	      0	   1084	    43c	sha256.c.obj (ex libmbedcrypto.a)
   1506	      0	      0	   1506	    5e2	sha512.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	threading.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	timing.c.obj (ex libmbedcrypto.a)
     87	      0	      0	     87	     57	version.c.obj (ex libmbedcrypto.a)
   3197	    484	      0	   3681	    e61	version_features.c.obj (ex libmbedcrypto.a)
      0	      0	      0	      0	      0	xtea.c.obj (ex libmbedcrypto.a)
     26	      0	      0	     26	     1a	esp_hardware.c.obj (ex libmbedcrypto.a)
     46	      0	      0	     46	     2e	esp_mem.c.obj (ex libmbedcrypto.a)
    169	      0	      0	    169	     a9	esp_timing.c.obj (ex libmbedcrypto.a)
    876	      0	      0	    876	    36c	esp_sha.c.obj (ex libmbedcrypto.a)
   1040	      0	      0	   1040	    410	esp_aes_xts.c.obj (ex libmbedcrypto.a)
    172	      0	      0	    172	     ac	esp_aes_common.c.obj (ex libmbedcrypto.a)
   1835	      8	      0	   1843	    733	esp_aes.c.obj (ex libmbedcrypto.a)
   1005	     16	     13	   1034	    40a	sha.c.obj (ex libmbedcrypto.a)
   1908	      0	      0	   1908	    774	esp_bignum.c.obj (ex libmbedcrypto.a)
   1658	      0	      4	   1662	    67e	bignum.c.obj (ex libmbedcrypto.a)
   5522	      0	      0	   5522	   1592	esp_sha1.c.obj (ex libmbedcrypto.a)
   4049	      0	      0	   4049	    fd1	esp_sha256.c.obj (ex libmbedcrypto.a)
   6288	      0	      0	   6288	   1890	esp_sha512.c.obj (ex libmbedcrypto.a)

and ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedx509.a:

# ESP-IDF generated 'libmbedx509.a' (in 'mbedtls/library/' subfolder)
$size libmbedx509.a

   text	   data	    bss	    dec	    hex	filename
  53205	     68	      0	  53273	   d019	certs.c.obj (ex libmbedx509.a)
      0	      0	      0	      0	      0	pkcs11.c.obj (ex libmbedx509.a)
   3847	      0	      0	   3847	    f07	x509.c.obj (ex libmbedx509.a)
   1955	      0	      0	   1955	    7a3	x509_create.c.obj (ex libmbedx509.a)
   3324	      0	      0	   3324	    cfc	x509_crl.c.obj (ex libmbedx509.a)
  11879	      0	      0	  11879	   2e67	x509_crt.c.obj (ex libmbedx509.a)
   1954	      0	      0	   1954	    7a2	x509_csr.c.obj (ex libmbedx509.a)
   3036	      0	      0	   3036	    bdc	x509write_crt.c.obj (ex libmbedx509.a)
   1452	      0	      0	   1452	    5ac	x509write_csr.c.obj (ex libmbedx509.a)

Comparing the Arduino-generated archive file with the ones from ESP-IDF, it looks like the Arduino archive file libmbedtls.a is essentially a combination of:

  • ~/esp/hello_world/build/esp-idf/mbedtls/libmbedtls.a
  • ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a
  • ~/esp/hello_world/build/esp-idf/mbedtls/mbedtls/library/libmbedx509.a

Thank you for opening the path to this insight!

Kind regards,
Kristof