libstdc++-v3: stdint.h, exceptions, and notes on hosted

This commit is contained in:
Lephenixnoir 2021-06-13 18:55:04 +02:00
parent 954e3ccd08
commit 9be687a07a
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 13 additions and 5 deletions

View File

@ -20,9 +20,9 @@ An `any` configuration is provided in case GCC is already installed externally,
## Notes on building libstdc++-v3
These are experimental notes on attempts at building the free-standing subset of the C++ standard library implementation bundled with GCC, `libstdc++-v3`. For the official manual, see [libstdc++ info manual, Chapter 2: Setup](https://gcc.gnu.org/onlinedocs/libstdc++/manual/setup.html) (gcc.gnu.org).
These are experimental notes on attempts at building the C++ standard library implementation bundled with GCC, `libstdc++-v3`. For the official manual, see [libstdc++ info manual, Chapter 2: Setup](https://gcc.gnu.org/onlinedocs/libstdc++/manual/setup.html) (gcc.gnu.org).
This is the **free-standing subset** which has basically nothing in it, see [Freestanding and hosted implementations](https://en.cppreference.com/w/cpp/freestanding) (cppreference.com). As a rule of thumb only features that look like extensions of the language are supported in there (RTTI, exceptions, coroutines, etc.) and everything that looks like a library (STL containers, I/O tools, filesystem) you can forget about.
So far, I was only able to build the **free-standing subset** which has basically nothing in it, see [Freestanding and hosted implementations](https://en.cppreference.com/w/cpp/freestanding) (cppreference.com). As a rule of thumb only features that look like extensions of the language are supported in there (RTTI, exceptions, coroutines, etc.) and everything that looks like a library (STL containers, I/O tools, filesystem) you can forget about. This subset does not include familiar features but it is needed nonetheless for C++ programs to work at all.
So how do we go around doing that?
@ -32,15 +32,17 @@ First configure GCC as usual (follow `configure.sh`), but use a separate build f
% export PREFIX="$(pwd)"
% mkdir build-libstdc++
% cd build-libstdc++
% ../gcc-11.1.0/configure --prefix="$PREFIX" --target=sh3eb-elf --with-multilib-list=m3,m4-nofpu --enable-languages=c,c++ --without-headers --with-newlib --program-prefix=sh-elf- --enable-libssp --enable-lto --enable-clocale=generic --enable-libstdcxx-allocator --disable-threads --disable-hosted-libstdcxx --disable-libstdcxx-verbose --enable-cxx-flags="-ffreestanding"
% ../gcc-11.1.0/configure --prefix="$PREFIX" --target=sh3eb-elf --with-multilib-list=m3,m4-nofpu --enable-languages=c,c++ --without-headers --with-newlib --program-prefix=sh-elf- --enable-libssp --enable-lto --enable-clocale=generic --enable-libstdcxx-allocator --disable-threads --disable-hosted-libstdcxx --disable-libstdcxx-verbose --enable-cxx-flags="-ffreestanding -fno-exceptions"
```
* `--enable-clocale=generic`: We want minimal locales and this is certainly the minimalistic option.
* `--enable-libstdcxx-allocator`: `=malloc` might be an option too.
* `--disable-threads`: Obvious.
* `--disable-hosted-libstdcxx`: This builds only the free-standing subset of the library (one thing at a time).
* `--disable-hosted-libstdcxx`: This builds only the free-standing subset of the library. If you're adventurous, remove it.
* `--disable-libstdcxx-verbose`: We don't have a systematic standard error stream anyway.
* `--enable-cxx-flags="-ffreestanding"`: Really everything should be free-standing here. It doesn't apply to conftest programs apparently, which (fail to) link with the default C runtime (`crt1.o` etc), maybe something will need to be done about that in the future.
* `--enable-cxx-flags="-ffreestanding -fno-exceptions"`: Everything should be free-standing since we don't use a standard runtime.
Currently I don't know of a way to completely disable exceptions in a way that linking with libstdc++ does not include all the stack unwinding and RTTI code for exceptions, but it sure starts with `-fno-exceptions` so it can't hurt to have that.
Now build and install that GCC and the libgcc.
@ -60,6 +62,12 @@ For some reason OpenLibm installs its headers in the `include/openlibm` subfolde
% for x in "$SRC"/*.h; do ln -s "$x" "$DST/${x#$SRC/}"; done
```
Also `<stdint.h>` has issues because GCC only redirects to its default `"stdint-gcc.h"` when free-standing, which conftest programs are not, so we have to provide some version of `<stdint.h>`.
```
% echo '#include "stdint-gcc.h"' > ../sh3eb-elf/sys-include/stdint.h
```
After this, come back to the build folder, run the build command for libstdc++-v3, and hope it works out. I recommend not using `-j` as it makes error messages and logs more linear, and the library builds very fast anyway.
```