diff --git a/continuous-build.sh b/continuous-build.sh index b29c9af..bc660c0 100755 --- a/continuous-build.sh +++ b/continuous-build.sh @@ -6,11 +6,19 @@ set -e +cd `dirname $0` +cd .. +export JEHANNE=`pwd` +REPONAME=`basename $JEHANNE` +export JEHANNE_TOOLCHAIN=`dirname $JEHANNE` +export JEHANNE_TOOLCHAIN="$JEHANNE_TOOLCHAIN/$REPONAME.TOOLCHAIN" +CROSS_TOOLCHAIN=$JEHANNE_TOOLCHAIN/cross/posix + function finish { if [ "$TRAVIS_BUILD_DIR" != "" ]; then # ensure that we preserve the toolchain on broken build/test - if [ -f "$JEHANNE/hacking/cross/toolchain/bin/x86_64-jehanne-gcc" ]; then - mv $JEHANNE/hacking/cross/toolchain/* $JEHANNE/tmp/toolchain/ + if [ -f "$CROSS_TOOLCHAIN/bin/x86_64-jehanne-gcc" ]; then + mv $CROSS_TOOLCHAIN/* $JEHANNE/tmp/toolchain/ fi fi (cd $JEHANNE/hacking; git clean -xdf disk-setup/; git checkout disk-setup/syslinux.cfg) @@ -18,17 +26,14 @@ function finish { trap finish EXIT if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then - cd `dirname $0` - cd .. - export JEHANNE=`pwd` - CROSS_TOOLCHAIN=$JEHANNE/hacking/cross/toolchain + export PATH="$JEHANNE/hacking/bin:$PATH" export PATH="$CROSS_TOOLCHAIN/bin:$PATH" export ARCH=amd64 # since our cross compiler is inside the system root, we need this too # as it can't find it's own headers - export CPATH=$CROSS_TOOLCHAIN/lib/gcc/x86_64-jehanne/4.9.4/include:$CROSS_TOOLCHAIN/lib/gcc/x86_64-jehanne/4.9.4/include-fixed + export CPATH=$CROSS_TOOLCHAIN/lib/gcc/x86_64-jehanne/9.2.0/include:$CROSS_TOOLCHAIN/lib/gcc/x86_64-jehanne/9.2.0/include-fixed git clean -xdf arch/ sys/ qa/ usr/ if [ ! -f "$JEHANNE/hacking/bin/ufs" ]; then diff --git a/cross/init.sh b/cross/init.sh index 6291a4c..62646fb 100755 --- a/cross/init.sh +++ b/cross/init.sh @@ -2,7 +2,7 @@ # This file is part of Jehanne. # -# Copyright (C) 2016 Giacomo Tesio +# Copyright (C) 2016-2019 Giacomo Tesio # # Jehanne is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,198 +21,104 @@ if [ "$JEHANNE" = "" ]; then exit 1 fi -# setup Jehanne's headers -usyscalls header $JEHANNE/sys/src/sysconf.json > $JEHANNE/arch/amd64/include/syscalls.h +WORKING_DIR="$JEHANNE_TOOLCHAIN" +CROSS_DIR="$JEHANNE/hacking/cross" +LOG="$WORKING_DIR/cross.build.log" -# -# WELLCOME TO HELL ! ! ! -# - -# If you want to understand _WHY_ Jehanne exists, you should try to -# create a GCC crosscompiler in Debian without requiring root access or Tex. -# And this despite the extreme quality of Debian GNU/Linux! - -# To create a Jehanne version of GCC, we need specific OUTDATED versions -# of Autotools that won't compile easily in a modern Linux distro. - -echo -n please wait. -( - # Inside parentheses, and therefore a subshell . . . - while [ 1 ] # Endless loop. - do - echo -n "." - sleep 3 - done -) & -dotter=$! -date > cross-toolchain.build.log +export LD_PRELOAD= function failOnError { # $1 -> exit status on a previous command # $2 -> task description if [ $1 -ne 0 ]; then - kill $dotter - wait $dotter 2>/dev/null - echo "ERROR $2" echo echo BUILD LOG: echo - cat cross-toolchain.build.log + cat $LOG exit $1 fi } -# fetch all sources -(cd src && fetch) >> cross-toolchain.build.log 2>&1 -failOnError $? "fetching sources" - -# build m4 1.4.14 -# - workaround a bug in lib/stdio.in.h, see http://lists.gnu.org/archive/html/bug-m4/2012-08/msg00008.html -# - workaround a bug in src/m4.h, see https://bugs.archlinux.org/task/19829 -# both bugs exists thanks to changes in external code -if [ ! -f tmp/bin/m4 ]; then -( - cd src/m4 && - sed -i '/_GL_WARN_ON_USE (gets/d' lib/stdio.in.h && - ( grep -q '#include ' src/m4.h || sed -i 's:.*\#include .*:&\n#include :g' src/m4.h ) && - ./configure --prefix=$JEHANNE/hacking/cross/tmp && - make && make install -) >> cross-toolchain.build.log 2>&1 -failOnError $? "building m4" -fi -# build autoconf 2.64 -# - hack git-version-gen to avoid the -dirty flag in version on make -# - autoreconf -# - disable doc build -# - disable man build -if [ ! -f tmp/bin/autoconf ]; then -( - cd src/autoconf && - cp ../../patch/autoconf/build-aux/git-version-gen build-aux/git-version-gen && - autoreconf && - ./configure --prefix=$JEHANNE/hacking/cross/tmp && - cp ../../patch/MakeNothing.in ../autoconf/doc/Makefile.in && - cp ../../patch/MakeNothing.in ../autoconf/man/Makefile.in && - make && make install -) >> cross-toolchain.build.log 2>&1 -failOnError $? "building autoconf" -fi -# build automake 1.11.1 -# - autoreconf to avoid conflicts with installed automake -# - automake; configure; make (that will fail) and then automake again -# to workaround this hell -# - disable doc build -# - disable disable tests build -if [ ! -f tmp/bin/automake ]; then -( - cd src/automake && - echo > doc/Makefile.am && - touch NEWS AUTHORS && autoreconf -i && - automake && - (./configure --prefix=$JEHANNE/hacking/cross/tmp && make; automake) && - ./configure --prefix=$JEHANNE/hacking/cross/tmp && - cp ../../patch/MakeNothing.in doc/Makefile.in && - cp ../../patch/MakeNothing.in tests/Makefile.in && - make && make install -) >> cross-toolchain.build.log 2>&1 -failOnError $? "building automake" -fi -# build libtool 2.4 -if [ ! -f tmp/bin/libtool ]; then -( - cd src/libtool && - ./configure --prefix=$JEHANNE/hacking/cross/tmp && - make && make install -) >> cross-toolchain.build.log 2>&1 -failOnError $? "building libtool" -fi - -# FINALLY! We have our OUTDATED autotools in tmp/bin -export PATH=$JEHANNE/hacking/cross/tmp/bin:$PATH -export CROSS_DIR=$JEHANNE/hacking/cross -if [ "$BUILD_DIRS_ROOT" = "" ]; then - export BUILD_DIRS_ROOT=$JEHANNE/hacking/cross/src -fi -if [ ! -d $BUILD_DIRS_ROOT ]; then - mkdir $BUILD_DIRS_ROOT -fi - function dynpatch { - # $1 -> path from cross/src + # $1 -> path from $WORKING_DIR/src # $2 -> string to search - ( cd $JEHANNE/hacking/cross/src && + ( cd $WORKING_DIR/src && grep -q jehanne $1 || - sed -n -i -e "/$2/r ../patch/$1" -e '1x' -e '2,${x;p}' -e '${x;p}' $1 + sed -n -i -e "/$2/r $CROSS_DIR/patch/$1" -e '1x' -e '2,${x;p}' -e '${x;p}' $1 ) } + +# setup Jehanne's headers +usyscalls header $JEHANNE/sys/src/sysconf.json > $JEHANNE/arch/amd64/include/syscalls.h + +mkdir -p $WORKING_DIR +date > $LOG + +# verify libtool is installed +libtool --version >> $LOG +failOnError $? "libtool installation check" + + +cp -fpr $JEHANNE/hacking/cross/src $WORKING_DIR +cd $WORKING_DIR/src +fetch >> $LOG +failOnError $? "fetching sources" + +mkdir -p $WORKING_DIR/build +rm -f $JEHANNE/hacking/bin/makeinfo +ln -s `which true` $JEHANNE/hacking/bin/makeinfo # don't depend on texinfo +mkdir -p $WORKING_DIR/cross + # Patch and build binutils -if [ "$BINUTILS_BUILD_DIR" = "" ]; then - export BINUTILS_BUILD_DIR=$BUILD_DIRS_ROOT/build-binutils -fi -if [ ! -d $BINUTILS_BUILD_DIR ]; then - mkdir $BINUTILS_BUILD_DIR -fi -if [ ! -f toolchain/bin/x86_64-jehanne-ar ]; then -( +echo -n Building binutils... +export BINUTILS_BUILD_DIR=$WORKING_DIR/build/binutils +mkdir -p $BINUTILS_BUILD_DIR + +( ( grep -q jehanne $WORKING_DIR/src/binutils/config.sub || ( + cd $WORKING_DIR && sed -i '/jehanne/b; /ELF_TARGET_ID/,/elf_backend_can_gc_sections/s/0x200000/0x1000 \/\/ jehanne hack/g' src/binutils/bfd/elf64-x86-64.c && - sed -i '/jehanne/b; s/| -tirtos/| -tirtos* | -jehanne/g' src/binutils/config.sub && + sed -i '/jehanne/b; s/| midnightbsd\*/| midnightbsd* | jehanne*/g' src/binutils/config.sub && dynpatch 'binutils/bfd/config.bfd' '\# END OF targmatch.h' && - dynpatch 'binutils/gas/configure.tgt' ' i860-\*-\*)' && - ( grep -q jehanne src/binutils/ld/configure.tgt || patch -p1 < patch/binutils/ld/configure.tgt ) && - cp patch/binutils/ld/emulparams/elf_x86_64_jehanne.sh src/binutils/ld/emulparams/ && - cp patch/binutils/ld/emulparams/elf_i386_jehanne.sh src/binutils/ld/emulparams/ && + dynpatch 'binutils/gas/configure.tgt' ' i386-\*-darwin\*)' && + ( grep -q jehanne src/binutils/ld/configure.tgt || patch -p1 < $CROSS_DIR/patch/binutils/ld/configure.tgt ) && + cp $CROSS_DIR/patch/binutils/ld/emulparams/elf_x86_64_jehanne.sh src/binutils/ld/emulparams/ && + cp $CROSS_DIR/patch/binutils/ld/emulparams/elf_i386_jehanne.sh src/binutils/ld/emulparams/ && dynpatch 'binutils/ld/Makefile.am' 'eelf_x86_64.c: ' && (grep 'eelf_i386_jehanne.c \\' src/binutils/ld/Makefile.am || sed -i 's/.*ALL_EMULATION_SOURCES = \\.*/&\n\teelf_i386_jehanne.c \\/' src/binutils/ld/Makefile.am) && (grep 'eelf_x86_64_jehanne.c \\' src/binutils/ld/Makefile.am || sed -i 's/.*ALL_64_EMULATION_SOURCES = \\.*/&\n\teelf_x86_64_jehanne.c \\/' src/binutils/ld/Makefile.am) && - cd src/binutils/ld && automake && cd ../ && + cd src/binutils/ld && automake-1.15 && cd ../ + ) ) && cd $BINUTILS_BUILD_DIR && - $CROSS_DIR/src/binutils/configure --prefix=$JEHANNE/hacking/cross/toolchain --with-sysroot=$JEHANNE --target=x86_64-jehanne --enable-interwork --enable-multilib --disable-nls --disable-werror && - cp $CROSS_DIR/patch/MakeNothing.in $CROSS_DIR/src/binutils/bfd/doc/Makefile && - cp $CROSS_DIR/patch/MakeNothing.in $CROSS_DIR/src/binutils/bfd/po/Makefile && - cp $CROSS_DIR/patch/MakeNothing.in $CROSS_DIR/src/binutils/gas/doc/Makefile && - cp $CROSS_DIR/patch/MakeNothing.in $CROSS_DIR/src/binutils/binutils/doc/Makefile && - make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true && - make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true install -) >> cross-toolchain.build.log 2>&1 -failOnError $? "building binutils" -fi + $WORKING_DIR/src/binutils/configure --target=x86_64-jehanne --prefix=/posix --with-sysroot=$JEHANNE --target=x86_64-jehanne --enable-interwork --enable-multilib --enable-newlib-long-time_t --disable-nls --disable-werror && + cp $CROSS_DIR/patch/MakeNothing.in $WORKING_DIR/src/binutils/bfd/doc/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $WORKING_DIR/src/binutils/bfd/po/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $WORKING_DIR/src/binutils/gas/doc/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $WORKING_DIR/src/binutils/binutils/doc/Makefile.in && + make && + make DESTDIR=$WORKING_DIR/cross install +) >> $LOG 2>&1 +failOnError $? "Building binutils" +echo done. +echo -n Building gcc... | tee -a $LOG # Patch and build gcc -if [ "$GCC_BUILD_DIR" = "" ]; then - export GCC_BUILD_DIR=$BUILD_DIRS_ROOT/build-gcc -fi -if [ ! -d $GCC_BUILD_DIR ]; then - mkdir $GCC_BUILD_DIR -fi +export GCC_BUILD_DIR=$WORKING_DIR/build/gcc +mkdir -p $GCC_BUILD_DIR + ( - pwd && - ( grep -q jehanne src/gcc/gcc/config.gcc || patch -p1 < patch/gcc/gcc/config.gcc ) && + cd $WORKING_DIR && + ( grep -q jehanne src/gcc/gcc/config.gcc || patch -p1 < $CROSS_DIR/patch/gcc.patch ) && + cp $CROSS_DIR/patch/gcc/gcc/config/* src/gcc/gcc/config && + sed -i 's/ftp/https/g' src/gcc/contrib/download_prerequisites && cd src && - cp ../patch/gcc/contrib/download_prerequisites gcc/contrib/download_prerequisites && ( cd gcc && ./contrib/download_prerequisites ) && - dynpatch 'gcc/config.sub' '-none)' && - cp ../patch/gcc/gcc/config/jehanne.h gcc/gcc/config && - dynpatch 'gcc/libstdc++-v3/crossconfig.m4' ' \*)' && - cd gcc/libstdc++-v3 && autoconf -i && cd ../../ && - ( pwd && grep -q jehanne gcc/libgcc/config.host || - sed -i -f ../patch/gcc/libgcc/config.host.sed gcc/libgcc/config.host - ) && - dynpatch 'gcc/fixincludes/mkfixinc.sh' 'i\?86-\*-cygwin\*' && + ( cd gcc/libstdc++-v3 && autoconf -i ) && cd $GCC_BUILD_DIR && - $CROSS_DIR/src/gcc/configure --target=x86_64-jehanne --prefix=$JEHANNE/hacking/cross/toolchain --with-sysroot=$JEHANNE --enable-languages=c,c++ && - make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true all-gcc all-target-libgcc && - make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true install-gcc install-target-libgcc -# && -# make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true all-target-libstdc++-v3 && -# make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true install-target-libstdc++-v3 -) >> cross-toolchain.build.log 2>&1 + $WORKING_DIR/src/gcc/configure --target=x86_64-jehanne --prefix=/posix --with-sysroot=$JEHANNE --enable-languages=c,c++ --without-isl --disable-nls && + make CFLAGS_FOR_TARGET="-I$JEHANNE/sys/include/apw" all-gcc all-target-libgcc && + make DESTDIR=$WORKING_DIR/cross install-gcc install-target-libgcc +) >> $LOG 2>&1 failOnError $? "building gcc" - -# add sh -ln -sf /bin/bash $JEHANNE/hacking/cross/toolchain/bin/x86_64-jehanne-sh - -kill $dotter -wait $dotter 2>/dev/null -echo "done." +echo done. diff --git a/cross/patch/MakeNothing.in b/cross/patch/MakeNothing.in index 5f28461..025d5ca 100644 --- a/cross/patch/MakeNothing.in +++ b/cross/patch/MakeNothing.in @@ -1,3 +1,5 @@ +info: + echo "make info does nothing HERE" all: echo "make all does nothing HERE" install: diff --git a/cross/patch/autoconf/build-aux/git-version-gen b/cross/patch/autoconf/build-aux/git-version-gen deleted file mode 100755 index 26bab70..0000000 --- a/cross/patch/autoconf/build-aux/git-version-gen +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo "2.64" | tr -d '\012' diff --git a/cross/patch/binutils/ld/configure.tgt b/cross/patch/binutils/ld/configure.tgt index a87ce56..27ef033 100644 --- a/cross/patch/binutils/ld/configure.tgt +++ b/cross/patch/binutils/ld/configure.tgt @@ -1,18 +1,18 @@ diff --git a/src/binutils/ld/configure.tgt b/src/binutils/ld/configure.tgt -index 6b6bbf2..29b5f30 100644 +index fad8b2e..ba3ddc9 100644 --- a/src/binutils/ld/configure.tgt +++ b/src/binutils/ld/configure.tgt -@@ -383,6 +383,9 @@ x86_64-*-nacl*) targ_emul=elf32_x86_64_nacl - targ_extra_libpath=$targ_extra_emuls +@@ -370,6 +370,9 @@ targ_extra_emuls="elf_i386_nacl elf_x86_64_nacl armelf_nacl armelfb_nacl" + targ_extra_libpath=$targ_extra_emuls tdir_elf_i386_nacl=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` ;; +x86_64*-jehanne*) targ_emul=elf_x86_64_jehanne + targ_extra_emuls="elf_i386_jehanne elf_x86_64 elf_i386" + ;; - i860-*-coff) targ_emul=coff_i860 ;; - i860-stardent-sysv4* | i860-stardent-elf*) - targ_emul=elf32_i860 -@@ -852,6 +855,10 @@ ia64-*-aix*) + ia16-*-elf*) targ_emul=elf_i386 targ_extra_emuls=i386msdos ;; + ia64-*-elf*) targ_emul=elf64_ia64 ;; + ia64-*-freebsd* | ia64-*-kfreebsd*-gnu) +@@ -806,6 +809,10 @@ ia64-*-aix*) NATIVE_LIB_DIRS='/usr/local/lib /usr/lib/ia64l64 /lib /usr/lib' ;; diff --git a/cross/patch/gcc.patch b/cross/patch/gcc.patch new file mode 100644 index 0000000..3c0fcd1 --- /dev/null +++ b/cross/patch/gcc.patch @@ -0,0 +1,89 @@ +diff --git a/src/gcc/gcc/config.gcc b/src/gcc/gcc/config.gcc +index ddd3b8f..702aa59 100644 +--- a/src/gcc/gcc/config.gcc ++++ b/src/gcc/gcc/config.gcc +@@ -947,6 +947,17 @@ case ${target} in + tmake_file="$tmake_file vms/t-vmsnative" + fi + ;; ++*-*-jehanne*) ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ extra_options="$extra_options jehanne.opt" ++ case $target in ++ x86_64-*) ++ native_system_header_dir="/arch/amd64/include" ++ ;; ++ esac ++ ;; + *-*-vxworks*) + tmake_file=t-vxworks + xm_defines=POSIX +@@ -1635,6 +1647,9 @@ i[34567]86-*-elfiamcu) + i[34567]86-*-elf*) + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h" + ;; ++x86_64-*-jehanne*) ++ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h jehanne.h" ++ ;; + x86_64-*-elf*) + tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h" + ;; +diff --git a/src/gcc/config.sub b/src/gcc/config.sub +index 75bb6a3..1905540 100755 +--- a/src/gcc/config.sub ++++ b/src/gcc/config.sub +@@ -1363,7 +1363,7 @@ case $os in + | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ + | skyos* | haiku* | rdos* | toppers* | drops* | es* \ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ +- | midnightbsd* | amdhsa* | unleashed* | emscripten*) ++ | jehanne* | midnightbsd* | amdhsa* | unleashed* | emscripten*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + qnx*) +diff --git a/src/gcc/fixincludes/mkfixinc.sh b/src/gcc/fixincludes/mkfixinc.sh +index 0f96486..9f0ee74 100755 +--- a/src/gcc/fixincludes/mkfixinc.sh ++++ b/src/gcc/fixincludes/mkfixinc.sh +@@ -14,6 +14,7 @@ case $machine in + i?86-*-cygwin* | \ + i?86-*-mingw32* | \ + x86_64-*-mingw32* | \ ++ *-jehanne* | \ + powerpc-*-eabisim* | \ + powerpc-*-eabi* | \ + powerpc-*-rtems* | \ +diff --git a/src/gcc/libgcc/config.host b/src/gcc/libgcc/config.host +index 91abc84..a994e3a 100644 +--- a/src/gcc/libgcc/config.host ++++ b/src/gcc/libgcc/config.host +@@ -1414,6 +1414,10 @@ nvptx-*) + tmake_file="$tmake_file nvptx/t-nvptx" + extra_parts="crt0.o" + ;; ++x86_64-*-jehanne*) ++ extra_parts="$extra_parts crtbegin.o crtend.o" ++ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" ++ ;; + *) + echo "*** Configuration ${host} not supported" 1>&2 + exit 1 +diff --git a/src/gcc/libstdc++-v3/crossconfig.m4 b/src/gcc/libstdc++-v3/crossconfig.m4 +index 344eec0..cc6eafe 100644 +--- a/src/gcc/libstdc++-v3/crossconfig.m4 ++++ b/src/gcc/libstdc++-v3/crossconfig.m4 +@@ -186,6 +186,12 @@ case "${host}" in + ;; + esac + ;; ++ *-jehanne*) ++ GLIBCXX_CHECK_COMPILER_FEATURES ++ GLIBCXX_CHECK_LINKER_FEATURES ++ GLIBCXX_CHECK_MATH_SUPPORT ++ GLIBCXX_CHECK_STDLIB_SUPPORT ++ ;; + *-linux* | *-uclinux* | *-gnu* | *-kfreebsd*-gnu | *-cygwin* | *-solaris*) + GLIBCXX_CHECK_COMPILER_FEATURES + GLIBCXX_CHECK_LINKER_FEATURES diff --git a/cross/patch/gcc/config.sub b/cross/patch/gcc/config.sub deleted file mode 100644 index 9555a9b..0000000 --- a/cross/patch/gcc/config.sub +++ /dev/null @@ -1,3 +0,0 @@ - -jehanne*) - os=-jehanne - ;; diff --git a/cross/patch/gcc/contrib/download_prerequisites b/cross/patch/gcc/contrib/download_prerequisites deleted file mode 100644 index 932dc36..0000000 --- a/cross/patch/gcc/contrib/download_prerequisites +++ /dev/null @@ -1,71 +0,0 @@ -#! /bin/sh - -# Download some prerequisites needed by gcc. -# Run this from the top level of the gcc source tree and the gcc -# build will do the right thing. -# -# (C) 2010 Free Software Foundation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see http://www.gnu.org/licenses/. - -# If you want to build GCC with the Graphite loop optimizations, -# set GRAPHITE_LOOP_OPT=yes to download optional prerequisties -# ISL Library and CLooG. -GRAPHITE_LOOP_OPT=yes - -if [ ! -e gcc/BASE-VER ] ; then - echo "You must run this script in the top level GCC source directory." - exit 1 -fi - -# Necessary to build GCC. -MPFR=mpfr-2.4.2 -GMP=gmp-4.3.2 -MPC=mpc-0.8.1 - -if [ ! -d $MPFR ]; then - wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1 - tar xjf $MPFR.tar.bz2 || exit 1 - ln -sf $MPFR mpfr || exit 1 -fi - -if [ ! -d $GMP ]; then - wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1 - tar xjf $GMP.tar.bz2 || exit 1 - ln -sf $GMP gmp || exit 1 -fi - -if [ ! -d $MPC ]; then - wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1 - tar xzf $MPC.tar.gz || exit 1 - ln -sf $MPC mpc || exit 1 -fi - -# Necessary to build GCC with the Graphite loop optimizations. -if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then - ISL=isl-0.12.2 - CLOOG=cloog-0.18.1 - - if [ ! -d $ISL ]; then - wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1 - tar xjf $ISL.tar.bz2 || exit 1 - ln -sf $ISL isl || exit 1 - fi - - if [ ! -d $CLOOG ]; then - wget http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/$CLOOG.tar.gz || exit 1 - tar xzf $CLOOG.tar.gz || exit 1 - ln -sf $CLOOG cloog || exit 1 - fi -fi diff --git a/cross/patch/gcc/fixincludes/mkfixinc.sh b/cross/patch/gcc/fixincludes/mkfixinc.sh deleted file mode 100644 index dc0e343..0000000 --- a/cross/patch/gcc/fixincludes/mkfixinc.sh +++ /dev/null @@ -1 +0,0 @@ - *-jehanne* | \ diff --git a/cross/patch/gcc/gcc/config.gcc b/cross/patch/gcc/gcc/config.gcc deleted file mode 100644 index 0ee95ab..0000000 --- a/cross/patch/gcc/gcc/config.gcc +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/src/gcc/gcc/config.gcc b/src/gcc/gcc/config.gcc -index f02ddbd..e5ebfe0 100644 ---- a/src/gcc/gcc/config.gcc -+++ b/src/gcc/gcc/config.gcc -@@ -862,6 +862,16 @@ case ${target} in - tmake_file="$tmake_file vms/t-vmsnative" - fi - ;; -+*-*-jehanne*) -+ gas=yes -+ gnu_ld=yes -+ default_use_cxa_atexit=yes -+ case $target in -+ x86_64-*) -+ native_system_header_dir="/arch/amd64/include" -+ ;; -+ esac -+ ;; - *-*-vxworks*) - tmake_file=t-vxworks - xm_defines=POSIX -@@ -1347,6 +1357,9 @@ x86_64-*-darwin*) - i[34567]86-*-elf*) - tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h" - ;; -+x86_64-*-jehanne*) -+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h jehanne.h" -+ ;; - x86_64-*-elf*) - tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h" - ;; diff --git a/cross/patch/gcc/gcc/config/jehanne.h b/cross/patch/gcc/gcc/config/jehanne.h index 1977cfb..aa81591 100644 --- a/cross/patch/gcc/gcc/config/jehanne.h +++ b/cross/patch/gcc/gcc/config/jehanne.h @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2016 Giacomo Tesio + * Copyright (C) 2016-2020 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,46 +19,144 @@ #undef TARGET_JEHANNE #define TARGET_JEHANNE 1 -/* Default arguments you want when running x86_64-jehanne-gcc */ -#undef LIB_SPEC -#define LIB_SPEC "-lc" - -#undef STANDARD_STARTFILE_PREFIX -#define STANDARD_STARTFILE_PREFIX "/arch/amd64/lib/" - -#undef MD_STARTFILE_PREFIX -#define MD_STARTFILE_PREFIX "/arch/amd64/lib/" - -#undef GPLUSPLUS_INCLUDE_DIR -#define GPLUSPLUS_INCLUDE_DIR "/posix/g++" - -#undef GCC_INCLUDE_DIR -#define GCC_INCLUDE_DIR "/posix/gcc" +/* In Jehanne, GCC has to be able to build two different kind of programs + * - native, directly repending on Jehanne's development environment + * - posix, based on the mainstream standards + * + * LibPOSIX exists to enable, together with a standard library + * (newlib, so far) the cooperation of these two worlds. + * + * By default, GCC will compile POSIX software looking for standard + * libraries and includes in /posix subfolders. + * However, the new option `-9` will enable the compilation of + * native programs by REMOVING the POSIX stuffs from the various Specs. + */ /* Architecture specific header (u.h) goes here (from config.gcc) */ #define ARCH_INCLUDE_DIR NATIVE_SYSTEM_HEADER_DIR -/* The default include dir is /sys/include but... */ #define PORTABLE_INCLUDE_DIR "/sys/include" -#define POSIX_INCLUDE_DIR "/posix/include" +/* INCLUDE_DEFAULTS is used by gcc/cppdefault.c + * The struct is defined in gcc/cppdefault.h + * + * struct default_include + * { + * const char *const fname; // The name of the directory. + * const char *const component; // The component containing the directory + * (see update_path in prefix.c) + * const char cplusplus; // Only look here if we're compiling C++. + * const char cxx_aware; // Includes in this directory don't need to + * be wrapped in extern "C" when compiling + * C++. + * const char add_sysroot; // FNAME should be prefixed by + * cpp_SYSROOT. + * const char multilib; // FNAME should have appended + * - the multilib path specified with -imultilib + * when set to 1, + * - the multiarch path specified with + * -imultiarch, when set to 2. + * }; + * + * Since C++ assumes a POSIX environment, we include all of the POSIX + * headers but with `cplusplus = 1`, to not mess native C compilation + * that have to react to the `-9` option. + */ + +/* C++ : only define values for INCLUDE_DEFAULTS */ +#ifdef GPLUSPLUS_INCLUDE_DIR +# define JEHANNE_ID_GPLUSPLUS { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, +#else +# define JEHANNE_ID_GPLUSPLUS +#endif +#ifdef GPLUSPLUS_TOOL_INCLUDE_DIR +# define JEHANNE_ID_GPLUSPLUS_TOOL { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, +#else +# define JEHANNE_ID_GPLUSPLUS_TOOL +#endif +#ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR +# define JEHANNE_ID_GPLUSPLUS_BACKWARD { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, +#else +# define JEHANNE_ID_GPLUSPLUS_BACKWARD +#endif + +/* GCC's private headers. */ +#ifdef GCC_INCLUDE_DIR +# define JEHANNE_ID_GCC { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, +#else +# define JEHANNE_ID_GCC +#endif + +#ifdef PREFIX_INCLUDE_DIR +# define JEHANNE_ID_PREFIX { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 }, +#else +# define JEHANNE_ID_PREFIX +#endif + +#if defined (CROSS_INCLUDE_DIR) && defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT) +# define JEHANNE_ID_CROSS { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, +#else +# define JEHANNE_ID_CROSS +#endif + +/* Binutils headers. */ +#ifdef TOOL_INCLUDE_DIR +# define JEHANNE_ID_TOOL { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 }, +#else +# define JEHANNE_ID_TOOL +#endif + +#define JEHANNE_POSIX_INCLUDE_DIR "/posix/include" +#define JEHANNE_ID_POSIX { JEHANNE_POSIX_INCLUDE_DIR, 0, 0, 0, 1, 0 }, + +#ifdef CROSS_DIRECTORY_STRUCTURE +# define JEHANNE_POSIX_LIB_DIR "%:getenv(JEHANNE /posix/lib)" +#else +# define JEHANNE_POSIX_LIB_DIR "/posix/lib" +#endif -/* ...we have to wrap libc.h and stdio.h with basic POSIX headers */ -#define BASIC_POSIX_INCLUDE_DIR "/sys/include/apw" #undef INCLUDE_DEFAULTS -#define INCLUDE_DEFAULTS \ - { \ - { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 1, 0 }, \ - { GCC_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ - { POSIX_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ - { BASIC_POSIX_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ - { ARCH_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ - { PORTABLE_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ - { ".", 0, 0, 0, 1, 0 }, \ - { 0, 0, 0, 0, 0, 0 } \ +#define INCLUDE_DEFAULTS \ + { \ + JEHANNE_ID_GPLUSPLUS \ + JEHANNE_ID_GPLUSPLUS_TOOL \ + JEHANNE_ID_GPLUSPLUS_BACKWARD \ + JEHANNE_ID_GCC \ + JEHANNE_ID_POSIX \ + JEHANNE_ID_PREFIX \ + JEHANNE_ID_CROSS \ + JEHANNE_ID_TOOL \ + { PORTABLE_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ + { ARCH_INCLUDE_DIR, 0, 0, 0, 1, 0 }, \ + { 0, 0, 0, 0, 0, 0 } \ } +#undef EXTRA_SPECS +#define EXTRA_SPECS \ + { "posixly_lib", "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}} -lposix" }, + + +/* These Specs reacts `-9` option by removing POSIX stuff */ +//#undef CPP_SPEC +//#define CPP_SPEC "%{!9:%(posixly_isystems)}" + +/* Since -nostdinc++ doesn't exclude C headers but we have cheated + * marking them as C++ headers, we need to add them back when + * this option is provided + */ +//#undef CPLUSPLUS_CPP_SPEC +//#define CPLUSPLUS_CPP_SPEC "%{nostdinc++:%(posixly_isystems)}" +//#define CPLUSPLUS_CPP_SPEC "" + +#undef LINK_SPEC +#define LINK_SPEC "%{!9:-L" JEHANNE_POSIX_LIB_DIR "}" + +#undef LIB_SPEC +#define LIB_SPEC "%{!9:%(posixly_lib)} -ljehanne" + +#define DRIVER_SELF_SPECS "%{9:-fno-builtin -fno-omit-frame-pointer -fplan9-extensions -fvar-tracking -fvar-tracking-assignments}" + /* Files that are linked before user code. The %s tells gcc to look for these files in the library directory. */ #undef STARTFILE_SPEC @@ -67,11 +165,13 @@ /* Files that are linked after user code. */ #undef ENDFILE_SPEC #define ENDFILE_SPEC "crtend.o%s crtn.o%s" - -/* Don't automatically add extern "C" { } around header files. */ -#undef NO_IMPLICIT_EXTERN_C -#define NO_IMPLICIT_EXTERN_C 1 +/* In Jehanne start files will be in /arch/amd64/lib, nearby libjehanne.a + */ +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/arch/amd64/lib/" + + /* Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67132 */ #undef WCHAR_TYPE #define WCHAR_TYPE "unsigned int" diff --git a/cross/patch/gcc/gcc/config/jehanne.opt b/cross/patch/gcc/gcc/config/jehanne.opt new file mode 100644 index 0000000..26fe302 --- /dev/null +++ b/cross/patch/gcc/gcc/config/jehanne.opt @@ -0,0 +1,25 @@ +; Jehanne options. + +; This file is part of Jehanne. +; +; Copyright (C) 2016-2020 Giacomo Tesio +; +; Jehanne is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, version 2 of the License. +; +; Jehanne is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with Jehanne. If not, see . + +; Please try to keep this file in ASCII collating order. + +9 +C Driver RejectNegative +Do not lookup for POSIX includes and libraries in /posix + +; This comment is to ensure we retain the blank line above. diff --git a/cross/patch/gcc/libgcc/config.host b/cross/patch/gcc/libgcc/config.host deleted file mode 100644 index 390276f..0000000 --- a/cross/patch/gcc/libgcc/config.host +++ /dev/null @@ -1,4 +0,0 @@ -x86_64-*-jehanne*) - extra_parts="$extra_parts crtbegin.o crtend.o" - tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic" - ;; diff --git a/cross/patch/gcc/libgcc/config.host.sed b/cross/patch/gcc/libgcc/config.host.sed deleted file mode 100644 index 6854d52..0000000 --- a/cross/patch/gcc/libgcc/config.host.sed +++ /dev/null @@ -1,3 +0,0 @@ -/enable_execute_stack=enable-execute-stack-empty.c;/,/Configuration ${host} not supported/{ - /^case ${host} in$/r ../patch/gcc/libgcc/config.host -} diff --git a/cross/patch/gcc/libstdc++-v3/crossconfig.m4 b/cross/patch/gcc/libstdc++-v3/crossconfig.m4 deleted file mode 100644 index a74ca37..0000000 --- a/cross/patch/gcc/libstdc++-v3/crossconfig.m4 +++ /dev/null @@ -1,6 +0,0 @@ - *-jehanne*) - GLIBCXX_CHECK_COMPILER_FEATURES - GLIBCXX_CHECK_LINKER_FEATURES - GLIBCXX_CHECK_MATH_SUPPORT - GLIBCXX_CHECK_STDLIB_SUPPORT - ;; diff --git a/cross/patch/libgmp.patch b/cross/patch/libgmp.patch new file mode 100644 index 0000000..7a33851 --- /dev/null +++ b/cross/patch/libgmp.patch @@ -0,0 +1,11 @@ +diff -Naru ../orig/configfsf.sub ./configfsf.sub +--- ../orig/configfsf.sub 2018-11-26 11:59:08.897396848 +0100 ++++ ./configfsf.sub 2018-11-26 12:20:10.079672849 +0100 +@@ -1399,6 +1399,7 @@ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ ++ | -jehanne* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; diff --git a/cross/patch/libmpc.patch b/cross/patch/libmpc.patch new file mode 100644 index 0000000..b207673 --- /dev/null +++ b/cross/patch/libmpc.patch @@ -0,0 +1,11 @@ +diff -Naru ../orig/config.sub ./config.sub +--- ../orig/config.sub 2018-11-27 00:30:59.807843647 +0100 ++++ ./config.sub 2018-11-27 00:32:49.224841688 +0100 +@@ -1393,6 +1393,7 @@ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ ++ | -jehanne* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; diff --git a/cross/patch/libmpfr.patch b/cross/patch/libmpfr.patch new file mode 100644 index 0000000..74f3e61 --- /dev/null +++ b/cross/patch/libmpfr.patch @@ -0,0 +1,11 @@ +diff -Naru ../orig/config.sub ./config.sub +--- ../orig/config.sub 2018-11-26 14:23:59.224388851 +0100 ++++ ./config.sub 2018-11-26 14:24:55.300412850 +0100 +@@ -1416,6 +1416,7 @@ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \ ++ | -jehanne* \ + | -onefs* | -tirtos* | -phoenix* | -fuchsia* | -redox*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; diff --git a/cross/pkgs/build.json b/cross/pkgs/build.json index dc009b1..eee6a5b 100644 --- a/cross/pkgs/build.json +++ b/cross/pkgs/build.json @@ -1,8 +1,12 @@ { "CrossCompiledPackages": { + "Env": [ + "CROSS_PKGS_BUILD=1" + ], "Pre": [ "./newlib/build.sh", - "./mksh/build.sh" + "./mksh/build.sh", + "./gcc/build.sh" ] } } diff --git a/cross/pkgs/gcc/.gitignore b/cross/pkgs/gcc/.gitignore new file mode 100644 index 0000000..c55869c --- /dev/null +++ b/cross/pkgs/gcc/.gitignore @@ -0,0 +1,3 @@ +src/ +!src/fetch.json +out/ diff --git a/cross/pkgs/gcc/build.sh b/cross/pkgs/gcc/build.sh new file mode 100755 index 0000000..58c6aef --- /dev/null +++ b/cross/pkgs/gcc/build.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +CROSS_DIR="$JEHANNE/hacking/cross" +LOG="$CROSS_DIR/pkgs/gcc/native-toolchain.build.log" + +if [ "$CROSS_PKGS_BUILD" = "1" ]; then +if [ -d $JEHANNE/pkgs/gcc/9.2.0/ ]; then + + echo "Skip cross compilation of GCC to not slowdown whole system build." + echo "GCC was already detected at $JEHANNE/pkgs/gcc/9.2.0/" + echo + echo "If you really want to cross compile GCC, run" + echo + echo " $CROSS_DIR/pkgs/gcc/build.sh" + echo + exit + +fi +fi + +echo "Cross compiling GCC and dependencies" + +JEHANNE_TOOLCHAIN=$JEHANNE_TOOLCHAIN + +export LD_PRELOAD= + +OPATH=$PATH +export PATH="$CROSS_DIR/wrappers:$PATH" + +function failOnError { + # $1 -> exit status on a previous command + # $2 -> task description + if [ $1 -ne 0 ]; then + echo "ERROR $2" + echo + echo BUILD LOG: + echo + cat $LOG + exit $1 + fi +} + +date > $LOG + +# mock makeinfo (to avoid it as a dependency) +rm -f $JEHANNE/hacking/bin/makeinfo +ln -s `which echo` $JEHANNE/hacking/bin/makeinfo + +# verify libtool is installed +libtool --version >> /dev/null +failOnError $? "libtool installation check" + +(cd $JEHANNE_TOOLCHAIN/src && fetch) >> $LOG +failOnError $? "fetching sources" + + + +echo -n Building libstdc++-v3... | tee -a $LOG +# libstdc++-v3 is part of GCC but must be built after newlib. +( + export GCC_BUILD_DIR=$JEHANNE_TOOLCHAIN/build/gcc && + mkdir -p $GCC_BUILD_DIR && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/isl-0.18.tar.bz2 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/isl-0.18 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/isl && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/gmp-6.1.0.tar.bz2 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/gmp-6.1.0 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/gmp && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpfr-3.1.4.tar.bz2 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpfr-3.1.4 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpfr && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpc-1.0.3.tar.gz && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpc-1.0.3 && + rm -fr $JEHANNE_TOOLCHAIN/src/gcc/mpc && + cd $GCC_BUILD_DIR && + mkdir -p $GCC_BUILD_DIR/x86_64-jehanne/libstdc++-v3 && + cd $GCC_BUILD_DIR/x86_64-jehanne/libstdc++-v3 && + rm -f config.cache && + $JEHANNE_TOOLCHAIN/src/gcc/libstdc++-v3/configure \ + --srcdir=$JEHANNE_TOOLCHAIN/src/gcc/libstdc++-v3 \ + --cache-file=./config.cache \ + --enable-multilib --with-cross-host=x86_64-pc-linux-gnu \ + --prefix=/posix --with-sysroot=/ --with-build-sysroot=$JEHANNE \ + --enable-languages=c,c++,lto --program-transform-name='s&^&x86_64-jehanne-&' \ + --disable-option-checking --with-target-subdir=x86_64-jehanne \ + --build=x86_64-pc-linux-gnu --host=x86_64-jehanne --target=x86_64-jehanne && + make && + make DESTDIR=$JEHANNE/pkgs/libstdc++-v3/9.2.0/ install +) >> $LOG 2>&1 +failOnError $? "building libstdc++-v3" +echo done. + +export PATH=$OPATH + +# Copy to /posix (to emulate bind during cross compilation) +cp -pfr $JEHANNE/pkgs/libstdc++-v3/9.2.0/posix/* $JEHANNE_TOOLCHAIN/cross/posix +cp -pfr $JEHANNE/pkgs/libstdc++-v3/9.2.0/posix/x86_64-jehanne/* $JEHANNE/posix +find $JEHANNE/posix/|grep '\.la$'|xargs rm + +echo -n Building libgmp... | tee -a $LOG +( + cd $JEHANNE_TOOLCHAIN/src/libgmp && + ( grep -q jehanne configfsf.sub || patch -p0 < $CROSS_DIR/patch/libgmp.patch ) && + ./configure --host=x86_64-jehanne --disable-shared --prefix=/posix --with-sysroot=$JEHANNE && + make && + make DESTDIR=$JEHANNE/pkgs/libgmp/6.1.2/ install && + libtool --mode=finish $JEHANNE/posix/lib +) >> $LOG 2>&1 +failOnError $? "Building libgmp" +echo done. + +# Copy to /posix (to emulate bind during cross compilation) +cp -pfr $JEHANNE/pkgs/libgmp/6.1.2/posix/* $JEHANNE/posix +rm $JEHANNE/posix/lib/*.la + +echo -n Building libmpfr... | tee -a $LOG +( + cd $JEHANNE_TOOLCHAIN/src/libmpfr && + ( grep -q jehanne config.sub || patch -p0 < $CROSS_DIR/patch/libmpfr.patch ) && + ./configure --host=x86_64-jehanne --disable-shared --prefix=/posix --with-sysroot=$JEHANNE --with-gmp=$JEHANNE/posix/ && + cp $CROSS_DIR/patch/MakeNothing.in doc/Makefile.in && + make && + make DESTDIR=$JEHANNE/pkgs/libmpfr/4.0.1/ install && + libtool --mode=finish $JEHANNE/posix/lib +) >> $LOG 2>&1 +failOnError $? "Building libmpfr" +echo done. + +# Copy to /posix (to emulate bind during cross compilation) +cp -pfr $JEHANNE/pkgs/libmpfr/4.0.1/posix/* $JEHANNE/posix +rm $JEHANNE/posix/lib/*.la + +echo -n Building libmpc... | tee -a $LOG +( + cd $JEHANNE_TOOLCHAIN/src/libmpc && + ( grep -q jehanne config.sub || ( chmod u+w config.sub && + patch -p0 < $CROSS_DIR/patch/libmpc.patch && + chmod u-w config.sub ) ) && + ./configure --host=x86_64-jehanne --disable-shared --prefix=/posix --with-sysroot=$JEHANNE --with-gmp=$JEHANNE/posix/ --with-mpfr=$JEHANNE/posix/ && + cp $CROSS_DIR/patch/MakeNothing.in doc/Makefile.in && + make && + make DESTDIR=$JEHANNE/pkgs/libmpc/1.1.0/ install && + libtool --mode=finish $JEHANNE/posix/lib +) >> $LOG 2>&1 +failOnError $? "Building libmpc" +echo done. + +# Copy to /posix (to emulate bind during cross compilation) +cp -pfr $JEHANNE/pkgs/libmpc/1.1.0/posix/* $JEHANNE/posix +rm $JEHANNE/posix/lib/*.la + +echo -n Building binutils... | tee -a $LOG + + +# Patch and build binutils +if [ "$BINUTILS_BUILD_DIR" = "" ]; then + export BINUTILS_BUILD_DIR=$JEHANNE_TOOLCHAIN/build/binutils-native +fi +if [ ! -d $BINUTILS_BUILD_DIR ]; then + mkdir $BINUTILS_BUILD_DIR +fi +( + export LIBS="-L$JEHANNE/posix/lib -L$JEHANNE/arch/amd64/lib -lmpc -lmpfr -lgmp" && + export CC_FOR_BUILD='CPATH="" LIBS="" gcc' && + mkdir -p $BINUTILS_BUILD_DIR && cd $BINUTILS_BUILD_DIR && + $JEHANNE_TOOLCHAIN/src/binutils/configure --host=x86_64-jehanne --with-sysroot=/ --with-build-sysroot=$JEHANNE --prefix=/posix --with-gmp=$JEHANNE/posix/ --with-mpfr=$JEHANNE/posix/ --with-mpc=$JEHANNE/posix/ --enable-interwork --enable-multilib --enable-newlib-long-time_t --disable-nls --disable-werror && + cp $CROSS_DIR/patch/MakeNothing.in $JEHANNE_TOOLCHAIN/src/binutils/bfd/doc/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $JEHANNE_TOOLCHAIN/src/binutils/bfd/po/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $JEHANNE_TOOLCHAIN/src/binutils/gas/doc/Makefile.in && + cp $CROSS_DIR/patch/MakeNothing.in $JEHANNE_TOOLCHAIN/src/binutils/binutils/doc/Makefile.in && + make && + make DESTDIR=$JEHANNE/pkgs/binutils/2.33.1/ install +) >> $LOG 2>&1 +failOnError $? "Building binutils" + +echo done. + +# Copy to /posix (to emulate bind during cross compilation) +cp -pfr $JEHANNE/pkgs/binutils/2.33.1/posix/* $JEHANNE/posix +rm $JEHANNE/posix/lib/*.la + +echo -n "Building gcc (and libgcc)..." | tee -a $LOG +( + export GCC_BUILD_DIR=$JEHANNE_TOOLCHAIN/build/gcc-native && + mkdir -p $GCC_BUILD_DIR && + cd $GCC_BUILD_DIR && + $JEHANNE_TOOLCHAIN/src/gcc/configure \ + --build=x86_64-pc-linux-gnu --host=x86_64-jehanne --target=x86_64-jehanne \ + --enable-languages=c,c++ \ + --prefix=/posix --with-sysroot=/ --with-build-sysroot=$JEHANNE \ + --without-isl --with-gmp=$JEHANNE/posix --with-mpfr=$JEHANNE/posix --with-mpc=$JEHANNE/posix \ + --disable-multiarch --disable-multilib \ + --disable-shared --disable-threads --disable-tls \ + --disable-libgomp --disable-werror --disable-nls && + make all-target-libgcc && + make DESTDIR=$JEHANNE/pkgs/gcc/9.2.0/ install-target-libgcc && + make all-gcc && + make DESTDIR=$JEHANNE/pkgs/gcc/9.2.0/ install-gcc && + echo +) >> $LOG 2>&1 +failOnError $? "building gcc" + +cp -pfr $JEHANNE/pkgs/gcc/9.2.0/posix/* $JEHANNE/posix + +echo "done." diff --git a/cross/pkgs/gcc/src/fetch.json b/cross/pkgs/gcc/src/fetch.json new file mode 100644 index 0000000..6ea8069 --- /dev/null +++ b/cross/pkgs/gcc/src/fetch.json @@ -0,0 +1,53 @@ +{ + "libgmp" : { + "Upstream":"https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2", + "Digest": { + "sha256":"5275bb04f4863a13516b2f39392ac5e272f5e1bb8057b18aec1c9b79d73d8fb2" + }, + "Compress":"bzip2", + "RemovePrefix": true, + "Exclude": [ + ] + }, + "libmpfr" : { + "Upstream":"https://www.mpfr.org/mpfr-4.0.1/mpfr-4.0.1.tar.bz2", + "Digest": { + "sha256":"a4d97610ba8579d380b384b225187c250ef88cfe1d5e7226b89519374209b86b" + }, + "Compress":"bzip2", + "RemovePrefix": true, + "Exclude": [ + ] + }, + "libmpc" : { + "Upstream":"https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz", + "Digest": { + "sha256":"6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e" + }, + "Compress":"gzip", + "RemovePrefix": true, + "Exclude": [ + ] + }, + "binutils": { + "Upstream":"http://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2", + "Digest": { + "sha256":"0cb4843da15a65a953907c96bad658283f3c4419d6bcc56bf2789db16306adb2" + }, + "Compress":"bzip2", + "RemovePrefix": true, + "Exclude": [ + ] + }, + "gcc": { + "Upstream":"https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz", + "Digest": { + "sha256":"a931a750d6feadacbeecb321d73925cd5ebb6dfa7eff0802984af3aef63759f4" + }, + "Compress":"gzip", + "RemovePrefix": true, + "Exclude": [ + ] + } + +} diff --git a/cross/pkgs/mksh/build.sh b/cross/pkgs/mksh/build.sh index b7539bd..068d153 100755 --- a/cross/pkgs/mksh/build.sh +++ b/cross/pkgs/mksh/build.sh @@ -27,9 +27,10 @@ export MKSH=$CROSS_DIR/pkgs/mksh/ export MKSH_SRC=$MKSH/src/ export MKSH_BUILD=$MKSH/out/ export MKSHRC_PATH='~/lib/mkshrc' -export LIBS="$JEHANNE/arch/$ARCH/lib/newlib/libc.a $JEHANNE/arch/$ARCH/lib/newlib/libm.a $JEHANNE/arch/$ARCH/lib/newlib/libg.a -lposix -lc" -export CPPFLAGS="-I$JEHANNE/sys/posix/newlib/ '-DMKSHRC_PATH=\"$MKSHRC_PATH\"' '-DARCH=\"$ARCH\"'" +export LIBS=" -lm -lg" +export CPPFLAGS="'-DMKSHRC_PATH=\"$MKSHRC_PATH\"' '-DARCH=\"$ARCH\"'" +export PATH="$JEHANNE/hacking/cross/wrappers:$PATH" export LD_PRELOAD= echo -n Building mksh. diff --git a/cross/pkgs/mksh/src b/cross/pkgs/mksh/src index dddf369..4e2ce81 160000 --- a/cross/pkgs/mksh/src +++ b/cross/pkgs/mksh/src @@ -1 +1 @@ -Subproject commit dddf3694e9566a7e304c3c91e8fc5cd5900d551f +Subproject commit 4e2ce8120cfed998cb5e77fa56d91b94c5a08822 diff --git a/cross/pkgs/newlib/build.sh b/cross/pkgs/newlib/build.sh index 5a90bb7..f0abc18 100755 --- a/cross/pkgs/newlib/build.sh +++ b/cross/pkgs/newlib/build.sh @@ -21,10 +21,6 @@ if [ "$JEHANNE" = "" ]; then exit 1 fi -# To create a Jehanne version of newlib, we need specific OUTDATED versions -# of Autotools that won't compile easily in a modern Linux distro. -export PATH=$JEHANNE/hacking/cross/tmp/bin:$PATH - export CROSS_DIR=$JEHANNE/hacking/cross export NEWLIB=$CROSS_DIR/pkgs/newlib/ export NEWLIB_SRC=$NEWLIB/src/ @@ -63,15 +59,25 @@ function failOnError { fi } +function mergeLibPOSIX { + TARGET_LIB=$1 +# echo "Merging $JEHANNE/arch/$ARCH/lib/libposix.a into $TARGET_LIB." && + +# x86_64-jehanne-ar -M <> $NEWLIB/newlib.build.log 2>&1 failOnError $? "building newlib" + + +# emultate bind for the cross compiler +mkdir -p $JEHANNE/posix +cp -fr $JEHANNE/pkgs/newlib/x86_64-jehanne/* $JEHANNE/posix + kill $dotter wait $dotter 2>/dev/null diff --git a/cross/pkgs/newlib/src b/cross/pkgs/newlib/src index bba2bd9..ded03c7 160000 --- a/cross/pkgs/newlib/src +++ b/cross/pkgs/newlib/src @@ -1 +1 @@ -Subproject commit bba2bd97b3ba0deb6e16f5fbdea6b1126c0f6452 +Subproject commit ded03c70bfd4d7d61cf5c0f051797affcda6fa05 diff --git a/cross/src/.gitignore b/cross/src/.gitignore deleted file mode 100644 index e3300fa..0000000 --- a/cross/src/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -gcc -binutils -autoconf -automake -libtool -m4 -build-* diff --git a/cross/src/fetch.json b/cross/src/fetch.json index 5e93a19..6ea8069 100644 --- a/cross/src/fetch.json +++ b/cross/src/fetch.json @@ -1,38 +1,28 @@ { - "autoconf" : { - "Upstream":"https://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.bz2", + "libgmp" : { + "Upstream":"https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2", "Digest": { - "sha256":"872f4cadf12e7e7c8a2414e047fdff26b517c7f1a977d72433c124d0d3acaa85" + "sha256":"5275bb04f4863a13516b2f39392ac5e272f5e1bb8057b18aec1c9b79d73d8fb2" }, "Compress":"bzip2", "RemovePrefix": true, "Exclude": [ ] }, - "m4": { - "Upstream":"https://ftp.gnu.org/gnu/m4/m4-1.4.14.tar.bz2", + "libmpfr" : { + "Upstream":"https://www.mpfr.org/mpfr-4.0.1/mpfr-4.0.1.tar.bz2", "Digest": { - "sha256":"0885ffa93256353a96b1cf0bcbc4d639ed09953b687e6cc412c4048e656f4dd2" + "sha256":"a4d97610ba8579d380b384b225187c250ef88cfe1d5e7226b89519374209b86b" }, "Compress":"bzip2", "RemovePrefix": true, "Exclude": [ ] }, - "automake": { - "Upstream":"https://ftp.gnu.org/gnu/automake/automake-1.11.1.tar.bz2", + "libmpc" : { + "Upstream":"https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz", "Digest": { - "sha256":"5b159d3c0e0a1f87de71b68bcb9f1a1c49e9e71749c9b723f17e2e1e0295c7ae" - }, - "Compress":"bzip2", - "RemovePrefix": true, - "Exclude": [ - ] - }, - "libtool": { - "Upstream":"https://ftp.gnu.org/gnu/libtool/libtool-2.4.tar.gz", - "Digest": { - "sha256":"13df57ab63a94e196c5d6e95d64e53262834fe780d5e82c28f177f9f71ddf62e" + "sha256":"6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e" }, "Compress":"gzip", "RemovePrefix": true, @@ -40,9 +30,9 @@ ] }, "binutils": { - "Upstream":"https://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2", + "Upstream":"http://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2", "Digest": { - "sha256":"c2ace41809542f5237afc7e3b8f32bb92bc7bc53c6232a84463c423b0714ecd9" + "sha256":"0cb4843da15a65a953907c96bad658283f3c4419d6bcc56bf2789db16306adb2" }, "Compress":"bzip2", "RemovePrefix": true, @@ -50,13 +40,14 @@ ] }, "gcc": { - "Upstream":"https://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.bz2", + "Upstream":"https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz", "Digest": { - "sha256":"6c11d292cd01b294f9f84c9a59c230d80e9e4a47e5c6355f046bb36d4f358092" + "sha256":"a931a750d6feadacbeecb321d73925cd5ebb6dfa7eff0802984af3aef63759f4" }, - "Compress":"bzip2", + "Compress":"gzip", "RemovePrefix": true, "Exclude": [ ] } + } diff --git a/cross/wrappers/x86_64-jehanne-g++ b/cross/wrappers/x86_64-jehanne-g++ new file mode 100755 index 0000000..56044c8 --- /dev/null +++ b/cross/wrappers/x86_64-jehanne-g++ @@ -0,0 +1,27 @@ +#!/bin/sh + +ARGS="$@" + +REPONAME=`basename $JEHANNE` +WORKING_DIR=`dirname $JEHANNE` +WORKING_DIR="$WORKING_DIR/$REPONAME.TOOLCHAIN" + +if [ -z "$WRAPPER_LOG" ]; then + WRAPPER_LOG="$WORKING_DIR/wrappers.log" +fi +echo >> $WRAPPER_LOG +echo >> $WRAPPER_LOG + +if echo $ARGS|grep -e '\.cpp\b' -e '\b\-o\b' -e ' -o ' > /dev/null; then + TOINCLUDE="-isystem$JEHANNE/posix/x86_64-jehanne/include/c++/9.2.0/ -isystem$JEHANNE/posix/x86_64-jehanne/include/c++/9.2.0/x86_64-jehanne -isystem$JEHANNE/posix/x86_64-jehanne/include/c++/9.2.0/backward -isystem$JEHANNE_TOOLCHAIN/cross/posix/lib/gcc/x86_64-jehanne/9.2.0/include -isystem$JEHANNE/posix/include" + TOLINK="-L$JEHANNE/posix/lib -lstdc++ -lm -lc" + date --rfc-3339="ns" |tee -a $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-g++ "$@" $TOINCLUDE $TOLINK >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-g++ "$@" $TOINCLUDE $TOLINK +else + date --rfc-3339="ns" >> $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-g++ "$@" >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-g++ "$@" +fi diff --git a/cross/wrappers/x86_64-jehanne-gcc b/cross/wrappers/x86_64-jehanne-gcc new file mode 100755 index 0000000..fdc1cd0 --- /dev/null +++ b/cross/wrappers/x86_64-jehanne-gcc @@ -0,0 +1,27 @@ +#!/bin/sh + +ARGS="$@" + +REPONAME=`basename $JEHANNE` +WORKING_DIR=`dirname $JEHANNE` +WORKING_DIR="$WORKING_DIR/$REPONAME.TOOLCHAIN" + +if [ -z "$WRAPPER_LOG" ]; then + WRAPPER_LOG="$WORKING_DIR/wrappers.log" +fi +echo >> $WRAPPER_LOG +echo >> $WRAPPER_LOG + +if echo $ARGS|grep -e '\.c\b' -e '\b\-o\b' -e ' -o ' > /dev/null; then + TOINCLUDE="-isystem$JEHANNE_TOOLCHAIN/cross/posix/lib/gcc/x86_64-jehanne/9.2.0/include -isystem$JEHANNE/posix/include" + TOLINK="-L$JEHANNE/posix/lib -lc" + date --rfc-3339="ns" |tee -a $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-gcc "$@" $TOINCLUDE $TOLINK >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-gcc "$@" $TOINCLUDE $TOLINK +else + date --rfc-3339="ns" >> $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-gcc "$@" >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-gcc "$@" +fi diff --git a/cross/wrappers/x86_64-jehanne-ld b/cross/wrappers/x86_64-jehanne-ld new file mode 100755 index 0000000..d3c50fb --- /dev/null +++ b/cross/wrappers/x86_64-jehanne-ld @@ -0,0 +1,26 @@ +#!/bin/sh + +ARGS="$@" + +REPONAME=`basename $JEHANNE` +WORKING_DIR=`dirname $JEHANNE` +WORKING_DIR="$WORKING_DIR/$REPONAME.TOOLCHAIN" + +if [ -z "$WRAPPER_LOG" ]; then + WRAPPER_LOG="$WORKING_DIR/wrappers.log" +fi +echo >> $WRAPPER_LOG +echo >> $WRAPPER_LOG + +if echo $ARGS|grep -e '\b\-o\b' -e ' -o ' > /dev/null; then + TOLINK="-L$JEHANNE/posix/lib -lc" + date --rfc-3339="ns" |tee -a $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-ld "$@" $TOLINK >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-ld "$@" $TOLINK +else + date --rfc-3339="ns" >> $WRAPPER_LOG + export >> $WRAPPER_LOG +echo $WORKING_DIR/cross/posix/bin/x86_64-jehanne-ld "$@" >> $WRAPPER_LOG +exec $WORKING_DIR/cross/posix/bin/x86_64-jehanne-ld "$@" +fi diff --git a/cross/x86_64-jehanne-pkg-config b/cross/x86_64-jehanne-pkg-config new file mode 100755 index 0000000..6e17814 --- /dev/null +++ b/cross/x86_64-jehanne-pkg-config @@ -0,0 +1,15 @@ +#!/bin/sh + +# from https://wiki.osdev.org/Cross-Porting_Software + +# Fill these in appropriately: +export PKG_CONFIG_SYSROOT_DIR=$JEHANNE +export PKG_CONFIG_LIBDIR=$JEHANNE/posix + +# TODO: If it works this should probably just be set to the empty string. +export PKG_CONFIG_PATH=$PKG_CONFIG_LIBDIR + +# Use --static here if your OS only has static linking. +# TODO: Perhaps it's a bug in the libraries if their pkg-config files +# doesn't record that only static libraries were built. +exec pkg-config --static "$@" diff --git a/devshell.sh b/devshell.sh index 703f04d..4dc54fa 100755 --- a/devshell.sh +++ b/devshell.sh @@ -5,9 +5,14 @@ # Copyright (C) 2016-2017 Giacomo Tesio export JEHANNE=`git rev-parse --show-toplevel` +REPONAME=`basename $JEHANNE` +JEHANNE_TOOLCHAIN=`dirname $JEHANNE` +JEHANNE_TOOLCHAIN="$JEHANNE_TOOLCHAIN/$REPONAME.TOOLCHAIN" +export JEHANNE_TOOLCHAIN + export PATH="$JEHANNE/hacking/bin:$PATH" -export PATH="$JEHANNE/hacking/cross/toolchain/bin:$PATH" -export CPATH="$JEHANNE/hacking/cross/toolchain/lib/gcc/x86_64-jehanne/4.9.4/include:$JEHANNE/hacking/cross/toolchain/lib/gcc/x86_64-jehanne/4.9.4/include-fixed" +export PATH="$JEHANNE_TOOLCHAIN/cross/posix/bin:$PATH" +#export CPATH="$JEHANNE_TOOLCHAIN/cross/posix/lib/gcc/x86_64-jehanne/9.2.0/include:$JEHANNE_TOOLCHAIN/cross/posix/lib/gcc/x86_64-jehanne/9.2.0/include-fixed" export ARCH=amd64 export TOOLPREFIX=x86_64-jehanne- diff --git a/runOver9P.sh b/runOver9P.sh index 90e170c..fd38b62 100755 --- a/runOver9P.sh +++ b/runOver9P.sh @@ -14,6 +14,7 @@ fi trap : 2 $JEHANNE/hacking/bin/ufs -root=$JEHANNE & +# To debug ufs add: -d 5 > $JEHANNE/../ufs.log 2>&1 ufspid=$! export machineflag=pc diff --git a/src/jehanne/cmd/usyscalls/usyscalls.go b/src/jehanne/cmd/usyscalls/usyscalls.go index a27ff26..f912c80 100644 --- a/src/jehanne/cmd/usyscalls/usyscalls.go +++ b/src/jehanne/cmd/usyscalls/usyscalls.go @@ -1,7 +1,7 @@ /* * This file is part of Jehanne. * - * Copyright (C) 2016 Giacomo Tesio + * Copyright (C) 2016-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ import ( const gplHeader string = `/* * This file is part of Jehanne. * - * Copyright (C) 2016 Giacomo Tesio + * Copyright (C) 2016-2019 Giacomo Tesio * * Jehanne is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -104,7 +104,6 @@ func argTypeName(t string) string{ return "p" } return " [?? " + t + "]" - } func argRegister(index int, t string) string{ @@ -144,6 +143,7 @@ func getHeaderData(calls []SyscallConf) *HeaderCode { wcall.AsmClobbers = "\"cc\", \"rcx\", \"r11\"" wcall.AsmArgs = fmt.Sprintf("\"0\"(%d)", wcall.Id) for i, a := range(call.Args){ + typeName := argTypeName(a) if i > 0 { wcall.FuncArgs += ", " wcall.MacroArgs += ", " @@ -153,7 +153,11 @@ func getHeaderData(calls []SyscallConf) *HeaderCode { } wcall.FuncArgs += fmt.Sprintf("%s a%d", a, i) wcall.MacroArgs += fmt.Sprintf("/* %s */ a%d", a, i) - wcall.VarValues = append(wcall.VarValues, fmt.Sprintf("_sysargs[%d].%s = (a%d); \\\n\t", i, argTypeName(a), i)) + if typeName == "p" { + wcall.VarValues = append(wcall.VarValues, fmt.Sprintf("_sysargs[%d].%s = ((volatile void*)(a%d)); \\\n\t", i, typeName, i)) + } else { + wcall.VarValues = append(wcall.VarValues, fmt.Sprintf("_sysargs[%d].%s = (a%d); \\\n\t", i, typeName, i)) + } wcall.Vars = append(wcall.Vars, fmt.Sprintf("register %s __r%d asm(\"%s\") = _sysargs[%d].%s; \\\n\t", a, i, argRegister(i, a), i, argTypeName(a))) wcall.AsmArgs += fmt.Sprintf(", \"r\"(__r%d)", i) } @@ -169,7 +173,7 @@ func getHeaderData(calls []SyscallConf) *HeaderCode { func generateSyscallTable(calls []SyscallConf){ code := getHeaderData(calls) tmpl, err := template.New("tab.c").Parse(` -{{ range .Wrappers }}"{{ .Name }}", (int(*)()) {{ .Name }}, +{{ range .Wrappers }}"{{ .Name }}", (int(*)()) sys_{{ .Name }}, {{ end }} `) err = tmpl.Execute(os.Stdout, code) @@ -185,9 +189,9 @@ func generateLibcCode(calls []SyscallConf){ #include {{ range .Wrappers }} -#pragma weak {{ .Name }} +#pragma weak sys_{{ .Name }} {{ .RetType }} -{{ .Name }}({{ .FuncArgs }}) +sys_{{ .Name }}({{ .FuncArgs }}) { register {{ .RetType }} __ret asm ("rax"); __asm__ __volatile__ ( @@ -220,34 +224,10 @@ typedef enum Syscalls {{ end }}} Syscalls; #ifndef KERNEL -{{ range .Wrappers }} -#define sys_{{ .Name }}({{ .MacroArgs }}) ({ \ - {{ range .VarValues }}{{.}}{{end}}{{ range .Vars }}{{.}}{{end}}register {{ .RetType }} __ret asm ("rax"); \ - __asm__ __volatile__ ( \ - "syscall" \ - : "=&r" (__ret) \ - : {{ .AsmArgs }} \ - : {{ .AsmClobbers }} \ - ); \ - __ret; }) + +{{ range .Wrappers }}extern {{ .RetType }} sys_{{ .Name }}({{ .FuncArgs }}); {{ end }} -#ifdef PORTABLE_SYSCALLS - -{{ range .Wrappers }}extern {{ .RetType }} {{ .Name }}({{ .FuncArgs }}); -{{ end }} -extern int32_t read(int, void*, int32_t); -extern int32_t write(int, const void*, int32_t); - -#else - -{{ range .Wrappers }}# define {{ .Name }}(...) sys_{{ .Name }}(__VA_ARGS__) -{{ end }} -#define read(fd, buf, size) pread(fd, buf, size, -1) -#define write(fd, buf, size) pwrite(fd, buf, size, -1) - -#endif - #endif `) err = tmpl.Execute(os.Stdout, code)