Open jenswet opened 2 years ago
@maribu As we discussed I tried to build with the llvm
toolchain, but it didn't change anything.
At least for Alpine, linking against the nano variant of libstdc++ results in no exceptions being supported:
And indeed,
$ DISABLE_MODULE=newlib_nano BOARD=nucleo-f767zi make -C tests/cpp_exception flash test
[...]
text data bss dec hex filename
70312 2512 2488 75312 12630 /home/maribu/Repos/software/RIOT/tests/cpp_exception/bin/nucleo-f767zi/tests_cpp_exception.elf
[...]
Help: Press s to start test, r to print it is ready
START
main(): This is RIOT! (Version: 2022.01-devel-1612-gf7dd0-tests/cpp11_exceptions)
************ C++ exception test ***********
Exceptions enabled
Exception catched
******************************************
I'm pulling the current version of riot/riotbuild
to confirm this behavior for non-Alpine systems. But it looks like -fno-exceptions
has to be added when using newlib_nano
.
It would also be sensible to prominently document that adding DISABLE_MODULE += newlib_nano
would enable exceptions. It is also worth pointing out that the non-nano variant buys in a lot of unrelated bloat (such as even more insanely bloated stdio than for newlib_nano
) that likely nobody wants. I think most C++ developers would profit from a nano but with exceptions version of newlib
.
OK, with riot/riotbuild
there are no exceptions even with DISABLE_MODULE=newlib_nano
. Would be nice to know if the Arch Linux toolchain is similar to Alpine in this regard.
I was also trying to give picolibc
a try, but that doesn't seem to work at all with C++. (Generally speaking, picolibc
is the better and more active C lib and RIOT is very likely to switch there, when the remaining issues are solved. That might also be chance to get C++ support right even without buying in bloat.)
Description
The exception handling is undefined in RIOT.
Some modules and unit tests use exceptions, e.g. the
riot::thread
implementation from thecpp11_compat
module and the according unit test.Steps to reproduce the issue
I've created a unit test to demonstrate the current undefined behavior: https://github.com/jenswet/RIOT/commit/7940cbed0509182eb9f78f57abcc9c7b5aad2de0
Expected results
All boards should give the following result:
Actual results
The native board does as expected:
The
nucleo-f767zi
does the following (with bothgnu
andllvm
toolchain):With the default compiler flags there is no
-fno-exceotions
.When adding
-fno-exceotions
manually and therefore disabling exceptions the test wouldn't even compile:Exact the same behavior can be verified on
esp32-wroom-32
:The devices are powered off instead of catching the exception.
Arduino has defined behabior, when trying to compile code that uses exceptions an error occurs
error: exception handling disabled, use -fexceptions to enable
.I didn't try the other platforms because of missing hardware.
I don't want to discuss whether exceptions are useful for embedded development or not. But the behavior should be consistent. Either they should work or they should be disabled. When they do not work, they should not be used in any module imho.
Versions
It doesn't matter whether I build locally:
or with the latest
riot/riotbuild
.