From e7dd2f1e547f895a5e3e0c9507b846984971d544 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 3 Mar 2024 20:17:22 -0500 Subject: build: Use Hyra specific toolchain Created patches for binutils and GCC tailored to Hyra Signed-off-by: Ian Moffett --- Makefile.in | 11 +++- builddeps/binutils.patch | 99 ++++++++++++++++++++++++++++++ builddeps/gcc.patch | 157 +++++++++++++++++++++++++++++++++++++++++++++++ tools/cross.sh | 26 ++++++-- 4 files changed, 286 insertions(+), 7 deletions(-) create mode 100644 builddeps/binutils.patch create mode 100644 builddeps/gcc.patch diff --git a/Makefile.in b/Makefile.in index df99dc0..8b098c6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -33,14 +33,19 @@ override KERNEL_DEFINES = -DHYRA_VERSION="\"$(HYRA_VERSION)\""\ $(SPECTRE_FLAGS)\ $(SERIAL_DEBUG_FLAGS) override KERNEL_CFLAGS = @KERNEL_CFLAGS@ $(KERNEL_DEFINES) -override KERNEL_LDFLAGS = -nostdlib -zmax-page-size=0x1000 -static -Tconf/link-$(ARCH).ld +override KERNEL_LDFLAGS = -nostdlib -znoexecstack -zmax-page-size=0x1000 -static -Tconf/link-$(ARCH).ld override QEMU_FLAGS = @QEMU_FLAGS@ ###################### # Binutils stuff ###################### -override CC = $(shell pwd)/cross/bin/$(ARCH)-elf-gcc -override LD = $(shell pwd)/cross/bin/$(ARCH)-elf-ld +ifeq ($(ARCH), amd64) + override CC = $(shell pwd)/cross/bin/x86_64-hyra-gcc + override LD = $(shell pwd)/cross/bin/x86_64-hyra-ld +else + override CC = $(shell pwd)/cross/bin/$(ARCH)-hyra-gcc + override LD = $(shell pwd)/cross/bin/$(ARCH)-hyra-ld +endif override AS = $(CC) ########################## diff --git a/builddeps/binutils.patch b/builddeps/binutils.patch new file mode 100644 index 0000000..728d82f --- /dev/null +++ b/builddeps/binutils.patch @@ -0,0 +1,99 @@ +diff -ruN binutils-2.42-copy/bfd/config.bfd binutils-2.42/bfd/config.bfd +--- binutils-2.42-copy/bfd/config.bfd 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/bfd/config.bfd 2024-03-03 11:27:01.508232956 -0500 +@@ -665,6 +665,11 @@ + targ_selvecs= + targ64_selvecs=x86_64_elf64_vec + ;; ++ i[3-7]86-*-hyra*) ++ targ_defvec=i386_elf32_vec ++ targ_selvecs= ++ targ64_selvecs=x86_64_elf64_vec ++ ;; + #ifdef BFD64 + x86_64-*-cloudabi*) + targ_defvec=x86_64_elf64_cloudabi_vec +@@ -729,6 +734,11 @@ + targ_defvec=x86_64_elf64_vec + targ_selvecs=i386_elf32_vec + want64=true ++ ;; ++ x86_64-*-hyra*) ++ targ_defvec=x86_64_elf64_vec ++ targ_selvecs=i386_elf32_vec ++ want64=true + ;; + x86_64-*-gnu*) + targ_defvec=x86_64_elf64_vec +diff -ruN binutils-2.42-copy/config.sub binutils-2.42/config.sub +--- binutils-2.42-copy/config.sub 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/config.sub 2024-03-03 11:27:01.508232956 -0500 +@@ -1766,7 +1766,7 @@ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ +- | fiwix* | mlibc* | cos* | mbr* ) ++ | fiwix* | mlibc* | cos* | mbr* | hyra* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) +diff -ruN binutils-2.42-copy/gas/configure.tgt binutils-2.42/gas/configure.tgt +--- binutils-2.42-copy/gas/configure.tgt 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/gas/configure.tgt 2024-03-03 11:27:01.508232956 -0500 +@@ -229,6 +229,7 @@ + i386-*-beos*) fmt=elf ;; + i386-*-elfiamcu) fmt=elf arch=iamcu ;; + i386-*-elf*) fmt=elf ;; ++ i386-*-hyra*) fmt=elf em=gnu ;; + i386-*-fuchsia*) fmt=elf ;; + i386-*-haiku*) fmt=elf em=haiku ;; + i386-*-genode*) fmt=elf ;; +diff -ruN binutils-2.42-copy/gprofng/libcollector/configure.ac binutils-2.42/gprofng/libcollector/configure.ac +--- binutils-2.42-copy/gprofng/libcollector/configure.ac 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/gprofng/libcollector/configure.ac 2024-03-03 11:27:01.508232956 -0500 +@@ -18,7 +18,7 @@ + + m4_include([../../bfd/version.m4]) + AC_INIT([gprofng], BFD_VERSION) +-AC_CONFIG_MACRO_DIRS([../../config ../..]) ++#AC_CONFIG_MACRO_DIRS([../../config ../..]) + AC_CONFIG_AUX_DIR(../..) + AC_CANONICAL_TARGET + AM_INIT_AUTOMAKE +diff -ruN binutils-2.42-copy/ld/configure.tgt binutils-2.42/ld/configure.tgt +--- binutils-2.42-copy/ld/configure.tgt 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/ld/configure.tgt 2024-03-03 11:29:12.677328228 -0500 +@@ -384,6 +384,10 @@ + i[3-7]86-*-redox*) targ_emul=elf_i386 + targ_extra_emuls=elf_x86_64 + ;; ++i[3-7]86-*-hyra*) ++ targ_emul=elf_i386 ++ targ_extra_emuls=elf_x86_64 ++ ;; + i[3-7]86-*-solaris2*) targ_emul=elf_i386_sol2 + targ_extra_emuls="elf_i386_ldso elf_i386 elf_iamcu elf_x86_64_sol2 elf_x86_64" + targ_extra_libpath=$targ_extra_emuls +@@ -1023,6 +1027,10 @@ + x86_64-*-redox*) targ_emul=elf_x86_64 + targ_extra_emuls=elf_i386 + ;; ++x86_64-*-hyra*) ++ targ_emul=elf_x86_64 ++ targ_extra_emuls=elf_i386 ++ ;; + x86_64-*-solaris2*) targ_emul=elf_x86_64_sol2 + targ_extra_emuls="elf_x86_64 elf_i386_sol2 elf_i386_ldso elf_i386 elf_iamcu" + targ_extra_libpath=$targ_extra_emuls +diff -ruN binutils-2.42-copy/libiberty/configure.ac binutils-2.42/libiberty/configure.ac +--- binutils-2.42-copy/libiberty/configure.ac 2024-01-28 19:00:00.000000000 -0500 ++++ binutils-2.42/libiberty/configure.ac 2024-03-03 11:27:01.508232956 -0500 +@@ -37,7 +37,7 @@ + libiberty_topdir="${srcdir}/.." + fi + AC_SUBST(libiberty_topdir) +-AC_CONFIG_AUX_DIR($libiberty_topdir) ++AC_CONFIG_AUX_DIR([.]) + + dnl Very limited version of automake's enable-maintainer-mode + diff --git a/builddeps/gcc.patch b/builddeps/gcc.patch new file mode 100644 index 0000000..d01c442 --- /dev/null +++ b/builddeps/gcc.patch @@ -0,0 +1,157 @@ +diff -ruN gcc-13.2.0-copy/config.sub gcc-13.2.0/config.sub +--- gcc-13.2.0-copy/config.sub 2024-03-03 11:35:31.049089458 -0500 ++++ gcc-13.2.0/config.sub 2024-03-03 11:43:08.078903300 -0500 +@@ -1749,7 +1749,7 @@ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ +- | fiwix* ) ++ | fiwix* | hyra* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) +diff -ruN gcc-13.2.0-copy/fixincludes/mkfixinc.sh gcc-13.2.0/fixincludes/mkfixinc.sh +--- gcc-13.2.0-copy/fixincludes/mkfixinc.sh 2024-03-03 11:35:30.112403110 -0500 ++++ gcc-13.2.0/fixincludes/mkfixinc.sh 2024-03-03 11:43:52.212764492 -0500 +@@ -20,6 +20,8 @@ + powerpcle-*-eabisim* | \ + powerpcle-*-eabi* | \ + *-*-vxworks7* | \ ++ *-hyra* | \ ++ *-*-hyra* | \ + *-musl* ) + # IF there is no include fixing, + # THEN create a no-op fixer and exit +diff -ruN gcc-13.2.0-copy/gcc/config/hyra.h gcc-13.2.0/gcc/config/hyra.h +--- gcc-13.2.0-copy/gcc/config/hyra.h 1969-12-31 19:00:00.000000000 -0500 ++++ gcc-13.2.0/gcc/config/hyra.h 2024-03-03 11:45:20.143810858 -0500 +@@ -0,0 +1,29 @@ ++#undef TARGET_HYRA ++#define TARGET_HYRA 1 ++ ++#undef LIB_SPEC ++#define LIB_SPEC "-lc" ++ ++#undef STARTFILE_SPEC ++#define STARTFILE_SPEC "%{!shared:crt0.o%s} crti.o%s %{shared:crtbeginS.o%s;:crtbegin.o%s}" ++ ++#undef ENDFILE_SPEC ++#define ENDFILE_SPEC "%{shared:crtendS.o%s;:crtend.o%s} crtn.o%s" ++ ++#define GNU_USER_LINK_EMULATION32 "elf_i386" ++#define GNU_USER_LINK_EMULATION64 "elf_x86_64" ++#define GNU_USER_LINK_EMULATIONX32 "elf32_x86_64" ++ ++#define GNU_USER_DYNAMIC_LINKER32 "/usr/lib/ld_i386.so" ++#define GNU_USER_DYNAMIC_LINKER64 "/usr/lib/ld.so" ++#define GNU_USER_DYNAMIC_LINKERX32 "/usr/lib/ld32.so" ++ ++#undef TARGET_OS_CPP_BUILTINS ++#define TARGET_OS_CPP_BUILTINS() \ ++ do { \ ++ builtin_define ("__hyra__"); \ ++ builtin_define ("__unix__"); \ ++ builtin_assert ("system=hyra"); \ ++ builtin_assert ("system=unix"); \ ++ builtin_assert ("system=posix"); \ ++ } while (0); +diff -ruN gcc-13.2.0-copy/gcc/config.gcc gcc-13.2.0/gcc/config.gcc +--- gcc-13.2.0-copy/gcc/config.gcc 2024-03-03 11:35:31.552433364 -0500 ++++ gcc-13.2.0/gcc/config.gcc 2024-03-03 11:47:40.945471968 -0500 +@@ -843,6 +843,15 @@ + *-*-fuchsia*) + native_system_header_dir=/include + ;; ++*-*-hyra*) ++ extra_options="$extra_options gnu-user.opt" ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ use_gcc_stdint=wrap ++ tmake_file="${tmake_file} t-slibgcc" ++ thread_file='posix' ++ ;; + *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-uclinuxfdpiceabi) + extra_options="$extra_options gnu-user.opt" + gas=yes +@@ -2218,6 +2227,9 @@ + tmake_file="${tmake_file} i386/t-x86_64-elf" + tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h fuchsia.h" + ;; ++x86_64-*-hyra*) ++ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h gnu-user.h glibc-stdint.h i386/x86-64.h i386/gnu-user-common.h i386/gnu-user64.h hyra.h" ++ ;; + ia64*-*-elf*) + tm_file="${tm_file} elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h" + tmake_file="ia64/t-ia64" +diff -ruN gcc-13.2.0-copy/libgcc/config.host gcc-13.2.0/libgcc/config.host +--- gcc-13.2.0-copy/libgcc/config.host 2024-03-03 11:35:30.195738195 -0500 ++++ gcc-13.2.0/libgcc/config.host 2024-03-03 11:49:47.703619260 -0500 +@@ -281,6 +281,11 @@ + tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-fuchsia" + extra_parts="crtbegin.o crtend.o" + ;; ++*-*-hyra*) ++ extra_parts="$extra_parts crtbegin.o crtbeginS.o crtend.o crtendS.o" ++ tmake_file="$tmake_file t-crtstuff-pic" ++ tmake_file="$tmake_file t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver t-libgcc-pic" ++ ;; + *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-uclinuxfdpiceabi) + tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver t-linux" + extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o" +@@ -715,6 +720,10 @@ + x86_64-*-fuchsia*) + tmake_file="$tmake_file t-libgcc-pic" + ;; ++x86_64-*-hyra*) ++ extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" ++ tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" ++ ;; + i[34567]86-*-dragonfly*) + tmake_file="${tmake_file} i386/t-dragonfly i386/t-crtstuff" + md_unwind_header=i386/dragonfly-unwind.h +diff -ruN gcc-13.2.0-copy/libgcc/configure.ac gcc-13.2.0/libgcc/configure.ac +--- gcc-13.2.0-copy/libgcc/configure.ac 2024-03-03 11:35:30.195738195 -0500 ++++ gcc-13.2.0/libgcc/configure.ac 2024-03-03 11:50:05.950497937 -0500 +@@ -46,7 +46,7 @@ + libgcc_topdir="${srcdir}/.." + fi + AC_SUBST(libgcc_topdir) +-AC_CONFIG_AUX_DIR($libgcc_topdir) ++AC_CONFIG_AUX_DIR([.]) + AC_CONFIG_HEADER(auto-target.h:config.in) + + AC_ARG_ENABLE(shared, +diff -ruN gcc-13.2.0-copy/libiberty/configure.ac gcc-13.2.0/libiberty/configure.ac +--- gcc-13.2.0-copy/libiberty/configure.ac 2024-03-03 11:35:35.829189807 -0500 ++++ gcc-13.2.0/libiberty/configure.ac 2024-03-03 11:50:29.010765475 -0500 +@@ -37,7 +37,7 @@ + libiberty_topdir="${srcdir}/.." + fi + AC_SUBST(libiberty_topdir) +-AC_CONFIG_AUX_DIR($libiberty_topdir) ++AC_CONFIG_AUX_DIR([.]) + + dnl Very limited version of automake's enable-maintainer-mode + +diff -ruN gcc-13.2.0-copy/libstdc++-v3/crossconfig.m4 gcc-13.2.0/libstdc++-v3/crossconfig.m4 +--- gcc-13.2.0-copy/libstdc++-v3/crossconfig.m4 2024-03-03 11:35:30.979087987 -0500 ++++ gcc-13.2.0/libstdc++-v3/crossconfig.m4 2024-03-03 11:51:42.994954128 -0500 +@@ -140,6 +140,17 @@ + SECTION_FLAGS='-ffunction-sections -fdata-sections' + AC_SUBST(SECTION_FLAGS) + ;; ++*-hyra*) ++ GLIBCXX_CHECK_COMPILER_FEATURES ++ GLIBCXX_CHECK_LINKER_FEATURES ++ GLIBCXX_CHECK_MATH_SUPPORT ++ GLIBCXX_CHECK_STDLIB_SUPPORT ++ AC_DEFINE(_GLIBCXX_USE_DEV_RANDOM) ++ AC_DEFINE(_GLIBCXX_USE_RANDOM_TR1) ++ GCC_CHECK_TLS ++ AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) ++ AC_CHECK_FUNCS(timespec_get) ++ ;; + + *-hpux*) + SECTION_FLAGS='-ffunction-sections -fdata-sections' diff --git a/tools/cross.sh b/tools/cross.sh index 9fc037c..5a0784a 100644 --- a/tools/cross.sh +++ b/tools/cross.sh @@ -35,7 +35,13 @@ set -e -TARGET="$1-elf" +if [ "$1" == "amd64" ] +then + TARGET="x86_64-hyra" +else + TARGET="$1-elf" +fi + BINUTILS_VERSION=2.42 GCC_VERSION=13.2.0 BINUTILS_NAME="binutils-$BINUTILS_VERSION" @@ -101,8 +107,14 @@ rm -rf build-gcc build-binutils # Binutils build clear -echo "Configuring $BINUTILS_NAME..." mkdir build-binutils + +echo "Applying binutils patch" +cp -r $BINUTILS_NAME $BINUTILS_NAME-copy +patch -s -p0 < ../../builddeps/binutils.patch +rm -rf $BINUTILS_NAME-copy + +echo "Configuring $BINUTILS_NAME..." cd build-binutils ../$BINUTILS_NAME/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror --enable-targets=all echo "Building $BINUTILS_NAME..." @@ -118,11 +130,17 @@ clear echo "Downloading prerequisites for $GCC_NAME..." cd $GCC_NAME contrib/download_prerequisites -echo "Configuring $GCC_NAME..." cd .. + +echo "Applying GCC patch" +cp -r $GCC_NAME $GCC_NAME-copy +patch -s -p0 < ../../builddeps/gcc.patch +rm -rf $GCC_NAME-copy + +echo "Configuring $GCC_NAME..." mkdir build-gcc cd build-gcc -../$GCC_NAME/configure --target="$TARGET" --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers +../$GCC_NAME/configure --target="$TARGET" --with-sysroot=/ --prefix="$PREFIX" --disable-nls --enable-languages=c --disable-multilib echo "Building all-gcc..." $MAKE all-gcc -j"$CORES" echo "Building all-target-libgcc..." -- cgit v1.2.3