I've recently tried out building my own cross-compiler toolchain with current gcc 7, just to compare the result with the 4.7.3 toolchain. Just run setup.sh, at some point you will need to type in a cvs password. I didn't need any patches (but I didn't use KOS with this toolchain, but my own from-scratch-code). I used gcc-6 and g++-6 to compile.
I heard there are some bugs in more modern gcc versions, but the self-tests seemed to be fine, so I can't comment on that.
I got it working like this:
setup.sh
Code: Select all
#!/bin/sh
# This script will pull the current binutils and gcc sources,
# put them in a combined source tree and then build a toolchain.
# See https://gcc.gnu.org/wiki/Building_Cross_Toolchains_with_gcc
set -e
FRAMEWORK_DIR="$PWD/$(dirname "$0")/.."
TOOLCHAIN_DIR="$FRAMEWORK_DIR/toolchain"
TMP_DIR="/tmp/dc_toolchain_build"
CORE_COUNT="$(getconf _NPROCESSORS_ONLN)"
rm -fr "$TMP_DIR"
mkdir -p "$TMP_DIR" "$TMP_DIR/build" "$TMP_DIR/combined"
echo "Cloning GCC."
cd "$TMP_DIR"
svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc
cd gcc
contrib/gcc_update --touch
echo "Cloning binutils, newlib, gdb."
cd "$TMP_DIR"
echo "Type 'anoncvs' as password, please."
cvs -d :pserver:anoncvs@sourceware.org:/cvs/src login
cvs -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils newlib
# gdb left out
cd gcc
contrib/gcc_update
echo "Creating combined tree."
cd "$TMP_DIR/src" && find . -print | cpio -pdlm ../combined
cd "$TMP_DIR/gcc" && find . -print | cpio -pdlmu ../combined
cd "$TMP_DIR/build"
CFLAGS="-Wno-error=misleading-indentation -Wno-error=format -Wno-error=shift-negative-value -Wno-error=unused-value -Wno-error=missing-prototypes -Wno-error=pointer-arith -Wno-error=parentheses -include $TOOLCHAIN_DIR/gcc_fix.h" ../combined/configure --target=sh-elf "--prefix=$TOOLCHAIN_DIR" --with-newlib --disable-gdbtk --enable-languages=c --disable-multilib --with-endian=little --enable-threads=single --disable-libssp --disable-tls --with-cpu=m4-single-only --disable-libsanitizer --disable-libquadmath --disable-libgomp --disable-libmpx --disable-decimal-float --disable-libatomic --disable-libstdcxx --disable-libvtv --disable-coverage --disable-nls --disable-shared "--with-native-system-header-dir=$FRAMEWORK_DIR/include/akumu/stl"
make "-j$CORE_COUNT"
rm -fr "$TMP_DIR"
gcc_fix.h (put in same directory)
Code: Select all
#pragma once
#define PARAMS(ARGS) ARGS
#define VPARAMS(ARGS) ARGS
#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
#define VA_CLOSE(AP) } va_end(AP); }
#define VA_FIXEDARG(AP, T, N) struct Qdmy
Code: Select all
$ sh-elf-gcc -o raytrace.elf main.o -L/Users/bogglez/local/lib -ml -m4-single-only -O3 -ffast-math -funsafe-loop-optimizations -fipa-pta -fipa-cp -funroll-loops -fvariable-expansion-in-unroller -fsingle-precision-constant -funswitch-loops -fbranch-target-load-optimize -Wall -Wextra -pedantic -Werror -Wno-error=unused-const-variable -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wunsafe-loop-optimizations -nostartfiles -Wl,-Ttext=0x8c010000 -lakumu # akumu = my framework's static library
sh-elf-strip raytrace.elf
$ ls -lh raytrace*
-rwxr-xr-x 1 bogglez staff 32K Aug 30 02:01 raytrace_gcc47.elf
-rwxr-xr-x 1 bogglez staff 26K Aug 30 13:02 raytrace_gcc7.elf
$ lxdream -e raytrace_gcc7.elf
Trace: 1011705
Shade: 22117068
Intersect: 26031918
Shadow: 29224192
Total: 91460726
Trace: 993862
Shade: 22102705
Intersect: 25916106
Shadow: 29480790
Total: 91484812
Trace: 963132
Shade: 21855903
Intersect: 25656342
Shadow: 29354450
Total: 90667118
$ lxdream -e raytrace_gcc47.elf
Trace: 1102600
Shade: 23353099
Intersect: 23766953
Shadow: 28702894
Total: 92711191
Trace: 1097773
Shade: 23353758
Intersect: 23674772
Shadow: 28938676
Total: 92746488
Trace: 1072858
Shade: 23092831
Intersect: 23464817
Shadow: 28808008
Total: 91941804