https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68606
Bug ID: 68606
Summary: Reduce or disable the static emergency pool for C++
exceptions
Product: gcc
Version: 4.9.3
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: rdiezmail-gcc at yahoo dot de
Target Milestone: ---
I am writing embedded firmware in C++ for small ARM Cortex-M3 microcontrollers
running on a 'bare metal' environment. One of the CPUs has just 16 KiB of SRAM.
Nevertheless, I have found that the only way to report sensible error messages
is by using C++ exceptions. And this is working fine, even with such tight
resources.
When you have 16 KiB SRAM, you do look carefully where your memory is going. It
took me while to realise that libstdc++ was reserving full 2 KiB for some
undocumented emergency memory pool in connection with C++ exceptions.
Acceptance of C++ exceptions has been slow over the years, not least due to
implementation deficiencies. In order to fix this one, I would like to see that
memory pool documented, and an option to reduce or disable it.
Embedded systems tend to be designed to never use all available memory. In many
such systems, a failing malloc() can only be caused by a bug, and if it does
happen, the system will panic and automatically reboot.
In my project, I have disabled the pool with this patch:
https://github.com/rdiez/JtagDue/blob/master/Toolchain/GccDisableCppExceptionEmergencyBuffer.patch