Okay to clarify newlib is only the C library right? I'm using the gcc-arm-none-eabi-9-2019-q4 toolchain which it seems it comes with newlib libc but as far as I know I'm not linking to it. Furthermore I'm interesting in std C++11 functionality for portability not just the the C++11 dialect.

About libcxx it seems to be only working partially with my current toolchain (gcc-arm-none-eabi-9-2019-q4):
With minimal testing I'm already getting these problems:
- iostream gives linker errors with locale e.g. "multiple definition of `duplocale'"
- optional.cxx doesn't compile, although disabling it can compile further
- linking with libsupc++ gives linker errors e.g. "std::set_unexpected(void (*)())'"
- GCC9 requires to enable fpermissive CXX flags

Do I have to use another toolchain? (Although NuttX getting started guide is reffering to gcc-arm-none-eabi-9) or do I have to downgrade my NuttX kernel (libcxx hasn't seen any update in 2-3 years maybe that has to do with?)

Many parts of newlib are not compatible with the NuttX C library.  If you link them together, you asking for some nasty surprises down the road.  For example, what is the binary representation of type FILE?  I guarantee the two representations are not compatible.  What if a newlib functions receives a NuttX argument of type FILE (or vise versa)?  I was expect a crash.

Of course, many things will work.  Like string manipulation functions and probably the math library (people use the newlib math library, but that has never been proven to be safe).  The fact that many things from the binary incompatbile newlib work lulls people into believing it is a technically viable solution. It is not.

Certainly if you are mixing incompatible binaries you are creating an unsafe system.  I would not think such a think could ever be flight or safety certifiable.

In order to avoid binary incompatibly, all libraries must be linked with only code from the NuttX C library (and nothing from newlib).  The C++ standard library must be created by compiling it with header files from the NuttX C library.

Currently, the *only* toolchain that does that correctly is the NuttX buildroot toolchain: https://bitbucket.org/nuttx/buildroot/src/master/  It does not contain newlib and imports the NuttX header files when it builds. So it is 100% newlib free.  It is a pure NuttX tools chaing.  The binary that it generates is an arm-nuttx-eabi-gcc toolchain.  Ff you create the C++ standard library using these header files, it is guaranteed to be 100% binary compatible.

Most people ignore this good advice.  I think that they do not grasp the incredible risk that they are taking.

Greg


Reply via email to