Build GCC/Binutils toolchain in tree. (#1)

Adds a x86_64-pc-acadia target triple.

Co-authored-by: Drew Galbraith <dgalbraith33@gmail.com>
Reviewed-on: #1
This commit is contained in:
drew 2023-06-15 18:39:14 -04:00
parent b8b6576b7f
commit 82b1a5c4db
6 changed files with 6346 additions and 1 deletions

View File

@ -1,2 +1,7 @@
#! /bin/bash #! /bin/bash
cmake -B builddbg/ -G Ninja -D CMAKE_CXX_COMPILER=x86_64-elf-gcc -D CMAKE_ASM-ATT_COMPILER=x86_64-elf-gcc -D CMAKE_AR=`which x86_64-elf-ar` -D CMAKE_BUILD_TYPE=Debug
CWD="$(pwd)"
BIN=$CWD/toolchain/local/bin
GCC=$BIN/x86_64-pc-acadia-gcc
AR=$BIN/x86_64-pc-acadia-ar
cmake -B builddbg/ -G Ninja -D CMAKE_CXX_COMPILER=${GCC} -D CMAKE_ASM-ATT_COMPILER=${GCC} -D CMAKE_AR=${AR} -D CMAKE_BUILD_TYPE=Debug

99
scripts/build_toolchain.sh Executable file
View File

@ -0,0 +1,99 @@
#!/bin/bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo $DIR
ARCH="x86_64"
TARGET="$ARCH-pc-acadia"
TOOLCHAIN="$DIR/../toolchain"
PREFIX="$TOOLCHAIN/local"
BUILD="$DIR/../builddbg"
SYSROOT="$DIR/../sysroot"
BINUTILS_VERSION="2.40"
BINUTILS_NAME="binutils-$BINUTILS_VERSION"
BINUTILS_PKG="${BINUTILS_NAME}.tar.xz"
BINUTILS_BASE_URL="https://ftp.gnu.org/gnu/binutils"
GCC_VERSION="13.1.0"
GCC_NAME="gcc-$GCC_VERSION"
GCC_PKG="${GCC_NAME}.tar.xz"
GCC_BASE_URL="https://ftp.gnu.org/gnu/gcc"
mkdir -p "$TOOLCHAIN/srcs"
pushd "$TOOLCHAIN/srcs"
# TODO: Check md5sum
if [ ! -e "$BINUTILS_PKG" ]; then
curl -LO "$BINUTILS_BASE_URL/$BINUTILS_PKG"
fi
if [ ! -d "$BINUTILS_NAME" ]; then
tar -xJf ${BINUTILS_PKG}
pushd $BINUTILS_NAME
# Set up a baseline to make it easier to create patches in the future.
git init
git add .
git commit -m "base"
patch -p1 <$TOOLCHAIN/patches/binutils/00-first.patch
popd
fi
if [ ! -e "$GCC_PKG" ]; then
curl -LO "$GCC_BASE_URL/$GCC_NAME/$GCC_PKG"
fi
if [ ! -d "$GCC_NAME" ]; then
tar -xJf $GCC_PKG
pushd $GCC_NAME
# Set up a baseline to make it easier to create patches in the future.
git init
git add .
git commit -m "base"
patch -p1 <$TOOLCHAIN/patches/gcc/00-first.patch
patch -p1 <$TOOLCHAIN/patches/gcc/01-libstdc++.patch
popd
fi
popd
mkdir -p "$TOOLCHAIN/build"
pushd "$TOOLCHAIN/build"
rm -rf binutils
mkdir -p binutils
pushd binutils
# skip building documentation
export ac_cv_prog_MAKEINFO=true
"$TOOLCHAIN"/srcs/$BINUTILS_NAME/configure \
--prefix=$PREFIX \
--target="$TARGET" \
--with-sysroot="$SYSROOT" \
--enable-shared \
--disable-nls
make MAKEINFO=true -j 8
make install MAKEINFO=true -j 8
popd
rm -rf gcc
mkdir -p gcc
pushd gcc
$TOOLCHAIN/srcs/$GCC_NAME/configure \
--prefix=$PREFIX \
--target=$TARGET \
--with-sysroot=$SYSROOT \
--with-newlib \
--disable-nls \
--enable-languages=c,c++
make -j 8 all-gcc
make -j 8 all-target-libgcc
make -j 8 install-gcc install-target-libgcc
popd
popd

3
toolchain/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
local/
srcs/

View File

@ -0,0 +1,111 @@
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 1b0111fd..16dc49bf 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -238,6 +238,11 @@ esac
case "${targ}" in
# START OF targmatch.h
#ifdef BFD64
+ x86_64-*-acadia*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
aarch64-*-darwin*)
targ_defvec=aarch64_mach_o_vec
targ_selvecs="arm_mach_o_vec mach_o_le_vec mach_o_be_vec mach_o_fat_vec"
diff --git a/config.sub b/config.sub
index dba16e84..d4b2e9d2 100755
--- a/config.sub
+++ b/config.sub
@@ -1723,7 +1723,7 @@ case $os in
# Now accept the basic system types.
# The portable systems comes first.
# Each alternative MUST end in a * to match a version number.
- gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
+ gnu* | acadia* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
| *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
| sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 765ba736..b8d99f65 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -263,6 +263,7 @@ case ${generic_target} in
i386-*-nto-qnx*) fmt=elf ;;
i386-*-*nt*) fmt=coff em=pe ;;
i386-*-rdos*) fmt=elf ;;
+ i386-*-acadia*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
ia16-*-elf*) fmt=elf ;;
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 12b2c3c4..66ff535a 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -454,6 +454,7 @@ ALL_64_EMULATION_SOURCES = \
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
+ eelf_x86_64_acadia.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
@@ -946,6 +947,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_acadia.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 3d5685d6..20cd5d88 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -954,6 +954,7 @@ ALL_64_EMULATION_SOURCES = \
eelf64tilegx_be.c \
eelf_mipsel_haiku.c \
eelf_x86_64.c \
+ eelf_x86_64_acadia.c \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
@@ -1462,6 +1463,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_s390.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_acadia.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Po@am__quote@
@@ -2619,7 +2621,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64tilegx_be.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_mipsel_haiku.Pc@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_acadia.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
diff --git a/ld/configure.tgt b/ld/configure.tgt
index de04a44b..b1f3f26b 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -991,6 +991,9 @@ vax-*-linux-*) targ_emul=elf32vax
;;
visium-*-elf) targ_emul=elf32visium
;;
+x86_64-*-acadia*) targ_emul=elf_x86_64_acadia
+ target_extra_emuls="elf_x86_64"
+ ;;
x86_64-*-rdos*) targ_emul=elf64rdos
;;
x86_64-*-cloudabi*) targ_emul=elf_x86_64_cloudabi
diff --git a/ld/emulparams/elf_x86_64_acadia.sh b/ld/emulparams/elf_x86_64_acadia.sh
new file mode 100644
index 00000000..59e7df71
--- /dev/null
+++ b/ld/emulparams/elf_x86_64_acadia.sh
@@ -0,0 +1 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh

View File

@ -0,0 +1,143 @@
diff --git a/config.sub b/config.sub
index 38f3d037a..a6298ccb7 100755
--- a/config.sub
+++ b/config.sub
@@ -203,6 +203,10 @@ case $1 in
# Convert single-component short-hands not valid as part of
# multi-component configurations.
case $field1 in
+ acadia)
+ basic_machine=x86_64-pc
+ os=acadia
+ ;;
386bsd)
basic_machine=i386-pc
basic_os=bsd
@@ -1749,7 +1753,7 @@ case $os in
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
- | fiwix* )
+ | fiwix* | acadia* )
;;
# This one is extra strict with allowed versions
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
index df90720b7..ae12e48d1 100755
--- a/fixincludes/mkfixinc.sh
+++ b/fixincludes/mkfixinc.sh
@@ -11,6 +11,7 @@ target=fixinc.sh
# Check for special fix rules for particular targets
case $machine in
+ *-*-acadia* | \
i?86-*-cygwin* | \
i?86-*-mingw32* | \
x86_64-*-mingw32* | \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6fd159448..e2fb4b52c 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -690,6 +690,12 @@ x86_cpus="generic intel"
# Common parts for widely ported systems.
case ${target} in
+*-*-acadia*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ use_gcc_stdint=provide
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1126,6 +1132,9 @@ case ${target} in
esac
case ${target} in
+x86_64-*-acadia*)
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h acadia.h"
+ ;;
aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*)
tm_file="${tm_file} elfos.h newlib-stdint.h"
tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-elf-raw.h"
diff --git a/gcc/config/acadia.h b/gcc/config/acadia.h
new file mode 100644
index 000000000..a5f58313d
--- /dev/null
+++ b/gcc/config/acadia.h
@@ -0,0 +1,25 @@
+#undef TARGET_ACADIA
+#define TARGET_ACADIA 1
+
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "crt0.o%s crti.o%s crtbegin.o%s"
+
+/* Files that are linked after user code. */
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "crtend.o%s crtn.o%s"
+
+/* Additional predefined macros. */
+#undef TARGET_ACADIA_CPP_BUILTINS
+#define TARGET_ACADIA_CPP_BUILTINS() \
+ do { \
+ builtin_define("__acadia__"); \
+ builtin_define("__unix__"); \
+ builtin_assert("system=acadia"); \
+ builtin_assert("system=unix"); \
+ builtin_assert("system=posix"); \
+ } while (0);
diff --git a/gcc/config/i386/t-i386 b/gcc/config/i386/t-i386
index b417c7f17..a30a64488 100644
--- a/gcc/config/i386/t-i386
+++ b/gcc/config/i386/t-i386
@@ -50,7 +50,11 @@ i386-options.o: $(srcdir)/config/i386/i386-options.cc
$(COMPILE) $<
$(POSTCOMPILE)
-i386-builtins.o: $(srcdir)/config/i386/i386-builtins.cc
+i386-common.o: $(srcdir)/common/config/i386/i386-common.cc
+ $(COMPILE) $<
+ $(POSTCOMPILE)
+
+i386-builtins.o: $(srcdir)/config/i386/i386-builtins.cc
$(COMPILE) $<
$(POSTCOMPILE)
diff --git a/libgcc/config.host b/libgcc/config.host
index b9975de90..bd766dfa0 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -368,6 +368,10 @@ i[34567]86-*-cygwin* | x86_64-*-cygwin*)
esac
case ${host} in
+x86_64-*-acadia*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o"
+ tmake_file="$tmake_file i386/t-i386 i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
aarch64*-*-elf | aarch64*-*-rtems*)
extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o"
extra_parts="$extra_parts crtfastmath.o"
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index b3269cb88..0d2c7b53c 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -9,6 +9,12 @@ case "${host}" in
# This is a freestanding configuration; there is nothing to do here.
;;
+ *-acadia*)
+ GLIBCXX_CHECK_COMPILER_FEATURES
+ GLIBCXX_CHECK_LINKER_FEATURES
+ GLIBCXX_CHECK_MATH_SUPPORT
+ GLIBCXX_CHECK_STDLIB_SUPPORT
+ ;;
avr*-*-*)
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)

File diff suppressed because it is too large Load Diff