C++ Exceptions for Smaller Firmware
Talkat CppCon 2024 · on Tuesday, 2024-09-17· at 10:30· Adams A, 6700 North Gaylord Rockies Boulevard·
summary
Steps to enable C++ exceptions on ARM, flip -fno-exceptions to -fexceptions and provide a low‑level allocator, then override __cxa_allocate_exception and the terminate hook. RTTI need not bloat everything; only thrown types stay in the binary. Replacing vendors’ allocators with a preallocated pool avoids heap growth. Measured results claim a jump from ~150 kB to ~13 kB after tweaks and an empirical crossover ≈550 checked calls where exceptions beat result-style checks. Built an Exception Insight tool to analyze binaries and simulate which throws reach main.
AI-written summary · about
chapters (26)
- 0:00Introduction
- 1:11Embedded C++ constraints
- 3:39Misconceptions about exceptions
- 5:02Output pin errors
- 8:12I2C fallible interfaces
- 10:21std::expected for errors
- 12:26Student feedback on APIs
- 14:32Why students prefer exceptions
- 15:35Exceptions on ARM MCUs
- 16:59Binary size explosion
- 17:41Override terminate handler
- 19:27No dynamic allocation for exceptions
- 20:30Runtime type information and exceptions
- 23:00Size comparison exceptions vs results
- 26:28Cost analysis error handling
- 29:58How exceptions work
- 37:19Exception unwinding
- 44:01Language data area ABI
- 55:13Space cost analysis
- 1:00:31Cost vs return types
- 1:03:44Distributed vs centralized errors
- 1:08:44Exceptions for smaller binaries
- 1:10:52Exceptions as code compression
- 1:12:37Limitations and reliability
- 1:14:04Exception Insights tool
- 1:17:33Q&A
related talks
01h 00mUsing Coroutines to Implement C++ Exceptions for Freestanding Environments
01h 04mException-Safe Code, Part III
01h 38mEmbedded & C++
06mThrowing Exceptions for Fun and Profit
55mC++ on small micro controllers
06mMy least favorite C++ feature
57mDeeply Embedded C++
01h 02mEmbedded Friendly C++: Features That Make a Difference
