Meta-repository providing an SH3/SH4 build of GCC for the fxSDK.
Go to file
Lephenixnoir 9f33074c10
libstdc++-v3: some progress
2021-06-13 17:12:45 +02:00
.gitignore add a :noclean configuration to leave the build folder 2021-05-04 20:05:58 +02:00
README.md libstdc++-v3: some progress 2021-06-13 17:12:45 +02:00
build.sh build: use gmake on OpenBSD 2021-03-18 14:25:27 +01:00
configure.sh remove build folder when deciding to skip build, take 2 2021-03-23 15:33:07 +01:00
giteapc-config-any.make add an `any` configuration that uses existing GCC installs 2021-01-14 19:14:12 +01:00
giteapc-config-noclean.make add a :noclean configuration to leave the build folder 2021-05-04 20:05:58 +02:00
giteapc.make bump to 11.1.0 2021-05-04 20:06:33 +02:00
install.sh add a :noclean configuration to leave the build folder 2021-05-04 20:05:58 +02:00
uninstall.sh split off binutils into a separate repository 2021-01-02 00:13:11 +01:00
util.sh explicitly link previously-built binutils to GCC 2021-01-02 22:48:31 +01:00

README.md

Automatic sh-elf-gcc installer

This script can be used to automatically compile and install a GCC cross-compiler targeting SH3 and SH4 calculators. The normal use is with GiteaPC:

% giteapc install Lephenixnoir/sh-elf-gcc

You can also install manually. First install sh-elf-binutils, then run the GiteaPC Makefile with a manually-specified install prefix:

% make -f giteapc.make configure build install PREFIX=$HOME/.local

An any configuration is provided in case GCC is already installed externally, to have this package installed without rebuilding it.

% giteapc install Lephenixnoir/sh-elf-gcc:any

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 (gcc.gnu.org).

This is the free-standing subset which has basically nothing in it, see Freestanding and hosted implementations (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 how do we go around doing that?

First configure GCC as usual (follow configure.sh), but use a separate build folder. Since this is experimental the files are likely to stay here longer while debugging and you don't want them gone during a GCC upgrade. There are a couple of additional flags to care about, mainly described here.

% 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"
  • --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-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.

Now build and install that GCC and the libgcc.

% make -j$(nproc) all-gcc all-target-libgcc
% make -j$(nproc) install-strip-gcc install-strip-target-libgcc

Next step is to install OpenLibm and fxlibc since we're certainly not going to build the C++ standard library without the C standard library.

For some reason OpenLibm installs its headers in the include/openlibm subfolder, but then includes them as if they were in include, so we have to add a path. Normally either the projet provides that path, or gint does it through its CMake find module. Here we can symlink to the sh3eb-elf/sys-include folder in this repo's root folder (or include but it's already symlinked to the compiler's install folder and we don't really want to override that).

% SRC="$(sh-elf-gcc -print-file-name=include/openlibm)"
% DST="../sh3eb-elf/sys-include"
% mkdir -p "$DST"
% for x in "$SRC"/*.h; do ln -s "$x" "$DST/${x#$SRC/}"; done

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.

% make all-target-libstdc++-v3

Since this will likely fail, check out sh3eb-elf/libstdc++-v3/config.log for configure errors, or other log files if you make it past the configuration step. config.log has many details on programs that failed to compile; not all failures to build are fatal for the configuration step, but some are.

Current problems

Hard limits:

  • <stdio.h> is not complete yet.

Suspected problems:

  • The conftest programs are built without -ffreestanding, which means autoconf cannot really link stuff. This is probably not too much of a problem, because it's cross-compiled anyway so there's nothing to do with a linked program, but who knows.

  • autoconf compiles conftest programs as if on a fully-featured dynamic OS, which is nowhere near true (eg. it builds with -shared-libgcc).