That’s a great post! I have also tried to experiment with Clang few months ago to solve the problem related to iostream
C++ STL header.
The problem is that if one would like to include iostream
or sstream
to implement e.g. nice streaming to a logger, or to some other peripheral, using operator<<
for example, then the binary size increases so much, that it will not fit into Flash memory.
This is really annoying, because I can’t simply use std::ostringstream
, to reuse easy string conversion, and I need to add quite a lot of boilerplate to be able to convert various types to string, using e.g. std::to_string
.
As I researched, I have found out that it is caused by the standard library bundled with GCC. After iostream
is included some static objects are instantiated, even though they are not used at all.
In this post it is explained that the STL from ARM Toolchain is used. Do you know whether the use of the lld
or the -Oz
flag resolves the problem related to too big size of the binary?
When I try even a simple program, which had main()
and used std::ostringstream
to stringify some numbers, and was compiled for a ARM Cortex M CPU (with e.g. 256 kB of Flash), the Flash area was overflown.
I hope that this: https://interrupt.memfault.com/blog/arm-cortexm-with-llvm-clang#compiling-libclang_rtbuiltinsa-for-arm-cortex-m
also resolves the problem.
Normally I would try it on my own, but currently I don’t have a set up to try it out.