|
fiber
|
fiber_sys_stubs is an optional object library that can be linked into embedded projects to eliminate unnecessary system-level functionality such as file I/O, heap management glue, and exit-related infrastructure — all of which are irrelevant in bare-metal environments.
These wrappers disable dynamic and OS-linked behavior from libc and libstdc++ by redirecting specific system functions via the linker --wrap option. The result is a dramatic reduction in binary size (commonly 50–90%), especially in projects using exceptions, static objects, or any part of the standard library.
In your main CMakeLists.txt, enable the wrappers via an option:
The fiber_sys_stubs links in sys_stubs together with wrapper functions and tells the liker to use the wrappers instead of the originals if they are hard symbols, and just defines normally if it is a weak symbol.
Specifically the following have been defined/wrapped:
std::terminate_handler __terminate_handler__wrap_atexitEven if your code never calls them directly, the C++ runtime does, especially when:
throw, std::terminate(), or global/static objectsstderr or exit()By providing __wrap_* versions of these functions and overriding them with stubs, you:
| Scenario | Binary Size (Flash) |
|---|---|
| Default (newlib, stdlibc++) | ~70–90kB |
With fiber_sys_stubs enabled | ~18–24kB |
Real-world savings depend on how many standard features are used (e.g., std::string, exceptions, RTTI).
fiber_sys_stubs is the easiest and safest way to:
It's opt-in, and safe to leave off in non-embedded builds.