ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
throw_stubs.h
Go to the documentation of this file.
1#pragma once
2/*
3 * Inline overrides for std::__throw_* helpers (ESP8266).
4 *
5 * ESP8266 Arduino compiles with -fno-exceptions and ships a libstdc++ whose
6 * std::__throw_* functions already just call abort() -- they never read their
7 * const char* message argument. But the compiler still emits the message load
8 * at every throw site (inside header-instantiated std::string / std::vector
9 * code), so --gc-sections keeps those libstdc++ error strings alive. On
10 * ESP8266 .rodata lives in DRAM, so each one wastes scarce RAM (e.g.
11 * "basic_string::_M_construct null not valid", "basic_string::_M_create",
12 * "cannot create std::vector larger than max_size()", "array::at: ...").
13 *
14 * Providing inline definitions here lets GCC see the message argument is
15 * unused, dead-strip the load, and drop the string entirely -- no LTO needed.
16 * Behavior is identical to today: a bare abort() (the message was never
17 * printed). This header MUST be force-included before <string>, so it is
18 * wired up via build_src_flags "-include ..." in this component's __init__.py;
19 * the native toolchain also force-includes it into the core and libraries.
20 *
21 * Note: this defines functions in namespace std (technically UB). It is safe
22 * here because the definitions match the existing abort() behavior exactly.
23 */
24
25#ifdef __cplusplus
26
27// Empty namespace so the CI namespace check is satisfied; the overrides below
28// must live in namespace std, so they cannot go in the component namespace.
29namespace esphome::esp8266 {} // namespace esphome::esp8266
30
31// NOLINTBEGIN(bugprone-reserved-identifier,bugprone-std-namespace-modification,cert-dcl37-c,cert-dcl51-cpp,cert-dcl58-cpp,readability-identifier-naming)
32namespace std {
33
34__attribute__((__noreturn__)) inline void __throw_logic_error(const char *) { __builtin_abort(); }
35__attribute__((__noreturn__)) inline void __throw_length_error(const char *) { __builtin_abort(); }
36__attribute__((__noreturn__)) inline void __throw_out_of_range(const char *) { __builtin_abort(); }
37__attribute__((__noreturn__)) inline void __throw_out_of_range_fmt(const char *, ...) { __builtin_abort(); }
38
39} // namespace std
40// NOLINTEND(bugprone-reserved-identifier,bugprone-std-namespace-modification,cert-dcl37-c,cert-dcl51-cpp,cert-dcl58-cpp,readability-identifier-naming)
41
42#endif // __cplusplus
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
STL namespace.