Skip to content

Save 8 to 17 KB of flash on ESP32 boards - #11629

Open
mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:espressif-cxx-unwind-wraps
Open

mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:espressif-cxx-unwind-wraps

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

ESP32 boards no longer carry C++ error handling code that can never run.

Why

It frees flash.

C++ exceptions are already off, but the code to handle them was still linked.

Flash saved (bytes)
Feather ESP32-C6 15,872
Metro ESP32-S3 8,592
Feather ESP32 V2 8,592
Feather ESP32-S2 10,208
QT Py ESP32-C3 17,200
P4 GPIO 16,208
ESP32-C5, C61, H2 devkits 15,632 to 15,824
ESP8684 (C2) devkit 17,168
Feather RP2040 (control) 0
Testing (Ubuntu host, 10 rounds each) before after
Feather ESP32-C6: reset to REPL, nvm survives reset, wifi, soft reset 10/10 10/10
Metro ESP32-S3: same 10/10 10/10
_bleio scan, C6 / S3 30 / 20 devices
Free Python heap, C6 / S3 204,112 / 8,264,928 204,096 / 8,264,928

The other boards were built, not run.

Written with Claude Code, which also ran the tests above. I reviewed the code and this description.

🤖 Generated with Claude Code

CircuitPython never enables CONFIG_COMPILER_CXX_EXCEPTIONS (IDF default
n). In that case IDF's cxx component wraps libgcc's unwinder and
libstdc++'s throw entry points with stubs that abort, so C++ code such
as nvs_flash does not pull in libgcc's unwinder.

CircuitPython lists IDF components by hand and left cxx out, so the
unwinder was linked anyway. The existing -u __cxx_init_dummy and
-u __cxa_guard_dummy flags also matched nothing (ld does not error on
an unresolved -u).

Add cxx to the component list and pass the same --wrap list as
esp-idf/components/cxx/CMakeLists.txt. Linking cxx also brings in
cxx_init.cpp, which sets the libstdc++ emergency exception pool to 0.

Feather ESP32-C6: 15,872 bytes less flash, 160 bytes less static RAM.
Metro ESP32-S3: 8,592 bytes less flash, 32 bytes less static RAM.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant