diff options
author | Pasha <pasha@member.fsf.org> | 2024-02-29 19:30:30 +0000 |
---|---|---|
committer | Pasha <pasha@member.fsf.org> | 2024-02-29 19:30:30 +0000 |
commit | 84d199451cf33734003c00c043a1480920f5563b (patch) | |
tree | 4655f03b3637184bfb363b4e86d376756e85c9e3 | |
download | cross-hurd-84d199451cf33734003c00c043a1480920f5563b.tar.gz cross-hurd-84d199451cf33734003c00c043a1480920f5563b.tar.bz2 |
initial commit
48 files changed, 3946 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..34cb9e9 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Introduction + +'cross-hurd' is a set of scripts for building a toolchain for cross-compiling the GNU Hurd operating system. The scripts will download the sources, compile all the packages required for building a cross-compiler and then compile a very basic operating system that is bootable using Qemu or other virtual machine. + +It has been tested on Linux and does not appear to work on Mac OS X due to problems when building the Glibc. + +# Downloading all the sources + +The first step is to download all the required sources. Run "bash download.sh" to download all the required packages. The build system will use the most up-to-date gnumach, glibc, libpthread, mig and hurd packages by fetching them from the official git repositories available on http://git.savannah.gnu.org/cgit/hurd/. + +# Building a toolchain + +First, update the CC and CXX variables in "vars.sh" to match your architecture and GCC version. + +To build the cross-compiler, run "bash bootstrap.sh". The script will create a build environment on the $PWD/tmp directory. Two directory links, "/tools" and "/cross-tools" will be created: "/cross-tools" is a link to $PWD/tmp/cross-tools and contains the cross-compiler; "/tools" will contain the basic system and points to $PWD/tmp/tools. You will be asked for the root password for some steps in the process since we are creating links in the root file system. + +Note that you need to install GCC, make, flex, bison, and other related packages in order to build the cross tools. + +# Compiling the basic system + +Once the toolchain is in place, run "bash compile.sh" to build a very basic set of packages using the cross-compiler built on the previous phase. Everything is installed into $PWD/tmp/tools. + +# Creating a bootable disk image + +If everything went alright, then run "bash create-image.sh" to create a bootable disk image. You will be asked for a sudo password because you need access to the loopback device. The script will use the base system built previously. The script runs 'grub-install' on the final disk image and needs to have the files for the i386-pc architecture (in debian, you need to install grub-pc-bin). + +Once the file "hd.img" is in place, just run it on your favorite virtual machine. The grub bootloader will load GNU Mach and the Hurd and complete the installation process by populating the /dev directory and then rebooting. Afterwards, just enter "login root" to log into the system. diff --git a/bootstrap-funcs.sh b/bootstrap-funcs.sh new file mode 100644 index 0000000..75dd936 --- /dev/null +++ b/bootstrap-funcs.sh @@ -0,0 +1,235 @@ +#!/bin/sh +# +export CC=$HOST_CC +export CXX=$HOST_CXX + +compile_binutils () +{ + print_info "Cross compiling binutils" + rm -rf "$BINUTILS_SRC".obj && + mkdir -p "$BINUTILS_SRC".obj && + cd "$BINUTILS_SRC".obj && + AR=$HOST_AR AS=$HOST_AS \ + $SOURCE/$BINUTILS_SRC/configure \ + --host="$HOST" \ + --target="$TARGET" \ + --prefix="$CROSS_TOOLS" \ + --with-sysroot="$SYSTEM" \ + --disable-static \ + --with-lib-path="$SYS_ROOT"/lib \ + --disable-multilib \ + --disable-nls && + make -j$PROCS all && + make -j$PROCS install && + cd .. +} + +compile_gcc () +{ + print_info "Cross compiling first phase of GCC" + rm -rf $GCC_SRC.obj && + mkdir -p $GCC_SRC.obj && + cd $GCC_SRC.obj && + AR=$HOST_AR LDFLAGS="-Wl,-rpath,${CROSS_TOOLS}/lib" \ + $SOURCE/$GCC_SRC/configure \ + --prefix=$CROSS_TOOLS \ + --build="$HOST" \ + --host="$HOST" \ + --target="$TARGET" \ + --with-sysroot="$SYSTEM" \ + --with-local-prefix="$SYS_ROOT" \ + --with-native-system-header-dir="$SYS_ROOT"/include \ + --disable-nls \ + --disable-shared \ + --disable-threads \ + --disable-multilib \ + --disable-target-zlib \ + --with-system-zlib \ + --without-headers \ + --with-newlib \ + --disable-decimal-float \ + --disable-threads \ + --disable-libatomic \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libssp \ + --disable-libvtv \ + --disable-libstdcxx \ + --enable-languages=c && + make -j$PROCS all-gcc && + make -j$PROCS install-gcc && + make -j$PROCS configure-target-libgcc && + cd "$TARGET"/libgcc && + make -j$PROCS all && + make -j$PROCS install && + cd - && + mv config.status config.status.removed && + rm -f config.cache *config.cache */*/config.cache && + cd .. +} + +install_gnumach_headers() { + print_info "Installing GNU Mach Headers" && + cd $SOURCE/$GNUMACH_SRC && + autoreconf -i && + cd - && + mkdir -p "$GNUMACH_SRC".obj && + local disable_user32="" + if [ -z "$USER32" ]; then + disable_user32="--disable-user32" + fi + cd "$GNUMACH_SRC".obj && + $SOURCE/$GNUMACH_SRC/configure \ + --host="$TARGET" \ + --prefix="$SYS_ROOT" \ + $disable_user32 && + make -j$PROCS install-data && + cd .. +} + +install_gnumig() { + print_info "Installing cross GNU Mig" && + cd $SOURCE/$GNUMIG_SRC && + autoreconf -i && + cd - && + rm -rf $GNUMIG_SRC.host_obj && + mkdir -p $GNUMIG_SRC.host_obj && + cd $GNUMIG_SRC.host_obj && + $SOURCE/$GNUMIG_SRC/configure --target="$TARGET" \ + --prefix=$CROSS_TOOLS && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_hurd_headers() { + print_info "Installing Hurd headers" && + cd $SOURCE/$HURD_SRC && + autoreconf -i && + cd - && + rm -rf $HURD_SRC.obj && + mkdir -p $HURD_SRC.obj && + cd $HURD_SRC.obj && + $SOURCE/$HURD_SRC/configure \ + --host="$TARGET" \ + --target="$TARGET" \ + --prefix= \ + --disable-profile \ + --without-libbz2 \ + --without-libz \ + --without-rump \ + --disable-ncursesw \ + --without-parted && + make -j$PROCS prefix="$SYS_ROOT" no_deps=t install-headers && + cd .. +} + +compile_first_glibc() { + print_info "Installing glibc (first pass)" && + rm -rf $GLIBC_SRC.first_obj && + mkdir -p $GLIBC_SRC.first_obj && + cd $GLIBC_SRC.first_obj && + BUILD_CC=$HOST_CC CC=$TARGET-gcc \ + AR=$TARGET-ar CXX="cxx-not-found" RANLIB=$TARGET-ranlib \ + $SOURCE/$GLIBC_SRC/configure \ + --with-binutils=${CROSS_TOOLS}/bin \ + --build="$HOST" \ + --host="$TARGET" \ + --prefix="$SYS_ROOT" \ + --with-headers="$SYS_ROOT"/include \ + --cache-file=config.cache \ + --enable-obsolete-rpc \ + --disable-profile \ + --enable-add-ons=libpthread \ + --enable-obsolete-rpc \ + --disable-nscd \ + libc_cv_ctors_header=yes && + make -j$PROCS || # workaround for "fails first time"? + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +compile_full_gcc () { + print_info "Cross compiling GCC" + rm -rf $GCC_SRC.obj && + mkdir -p $GCC_SRC.obj && + cd $GCC_SRC.obj && + AR=$HOST_AR \ + LDFLAGS="-Wl,-rpath,${CROSS_TOOLS}/lib" \ + $SOURCE/$GCC_SRC/configure \ + --prefix=$CROSS_TOOLS \ + --target="$TARGET" \ + --with-sysroot="$SYSTEM" \ + --with-local-prefix="$SYS_ROOT" \ + --with-native-system-header-dir="$SYS_ROOT"/include \ + --disable-static \ + --disable-nls \ + --enable-languages=c,c++ \ + --enable-threads=posix \ + --disable-multilib \ + --with-system-zlib \ + --with-libstdcxx-time \ + --disable-libstdcxx-pch \ + --disable-bootstrap \ + --disable-libcilkrts \ + --disable-libgomp && + make -j$PROCS AS_FOR_TARGET="$TARGET-as" LD_FOR_TARGET="$TARGET-ld" all && + make -j$PROCS install && + cd .. +} + +compile_second_glibc() { + print_info "Installing GLibC (second pass)" && + rm -rf $GLIBC_SRC.second_obj && + mkdir -p $GLIBC_SRC.second_obj && + cd $GLIBC_SRC.second_obj && + rm -f config.cache && + BUILD_CC=$HOST_CC CC=$TARGET-gcc CXX="" \ + AR=$TARGET-ar RANLIB=$TARGET-ranlib \ + $SOURCE/$GLIBC_SRC/configure \ + --with-binutils=$CROSS_TOOLS/bin \ + --build="$HOST" \ + --host="$TARGET" \ + --prefix="$SYS_ROOT" \ + --with-headers="$SYS_ROOT"/include \ + --enable-obsolete-rpc \ + --disable-profile \ + --enable-add-ons=libpthread \ + --enable-obsolete-rpc \ + --disable-nscd && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +compile_pkgconfiglite() { + # otherwise "ln pkg-config i586-pc-gnu-pkg-config" in the install step fails + rm -fv $CROSS_TOOLS/bin/*-pkg-config && + rm -rf $PKGCONFIGLITE_SRC.obj && + mkdir -p $PKGCONFIGLITE_SRC.obj && + cd $PKGCONFIGLITE_SRC.obj && + $SOURCE/$PKGCONFIGLITE_SRC/configure \ + --prefix=$CROSS_TOOLS --host=$TARGET \ + --with-pc-path=$SYS_ROOT/lib/pkgconfig && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +create_tools_symlink() { + if [ ! -e $SYS_ROOT ]; then + sudo ln -sf "$PWD"/$(basename $SYS_ROOT) $SYS_ROOT + fi + if [ ! -e $CROSS_TOOLS ]; then + sudo ln -sf "$PWD"/$(basename $CROSS_TOOLS) $CROSS_TOOLS + fi +} + +setup_directories() { + mkdir -p "$SYSTEM" && cd "$SYSTEM" && + mkdir -p bin boot "$(basename $SYS_ROOT)/include" "$(basename $SYS_ROOT)/lib" "$(basename $CROSS_TOOLS)/$TARGET" && + create_tools_symlink && + ln -sfn $SYS_ROOT/include $SYS_ROOT/lib $CROSS_TOOLS/$TARGET/ && + cd - +} diff --git a/bootstrap-kernel.sh b/bootstrap-kernel.sh new file mode 100644 index 0000000..ba8473c --- /dev/null +++ b/bootstrap-kernel.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +. ./vars.sh +. ./download-funcs.sh +. ./bootstrap-funcs.sh + +print_info "Root is $CROSS_TOOLS" +print_info "Cross-compiling on $HOST to $TARGET" + +setup_directories + +install_gnumach() { + cd $SOURCE/$GNUMACH_SRC && + autoreconf -i && + cd - && + rm -rf $GNUMACH_SRC.obj && + mkdir -p $GNUMACH_SRC.obj && + cd $GNUMACH_SRC.obj && + local disable_user32="" + local user_mig="" + local user_cc + if [ ! -z "$USER32" ]; then + enable_user32="--enable-user32" + user_mig=/cross-tools-i686/bin/i686-gnu-mig + user_cc=/cross-tools-i686/bin/i686-gnu-gcc + user_cpp="$user_cc -E" + else + user_mig=$CROSS_TOOLS/bin/x86_64-gnu-mig + user_cc=$CROSS_TOOLS/bin/x86_64-gnu-gcc + user_cpp="$user_cc -E" + fi && + USER_CC="$user_cc" USER_CPP="$user_cpp" \ + USER_MIG="$user_mig" $SOURCE/$GNUMACH_SRC/configure \ + --host="$TARGET" \ + --build="$HOST" \ + --exec-prefix=$SYSTEM \ + --enable-kdb \ + --enable-kmsg \ + --prefix="$SYS_ROOT" \ + $enable_user32 && + make -j$PROCS gnumach.gz gnumach gnumach.msgids && + make -j$PROCS install && + mkdir -p $SYSTEM/boot && + cp gnumach.gz $SYSTEM/boot/ && + cd - +} + +set_vars() { + export CC="${TARGET}-gcc" + export CXX="${TARGET}-g++" + export AR="${CROSS_TOOLS}/bin/${TARGET}-ar" + export AS="${CROSS_TOOLS}/bin/${TARGET}-as" + export RANLIB="${CROSS_TOOLS}/bin/${TARGET}-ranlib" + export LD="${CROSS_TOOLS}/bin/${TARGET}-ld" + export STRIP="${CROSS_TOOLS}/bin/${TARGET}-strip" + export MIG="${CROSS_TOOLS}/bin/${TARGET}-mig" +} + +mkdir -p $BUILD_ROOT/bootstrap-kernel && + cd $BUILD_ROOT/bootstrap-kernel && + if [ ! "$1" = "--kernel-only" ]; then + compile_binutils && + compile_gcc && + compile_pkgconfiglite && + install_gnumach_headers && + install_gnumig + fi && + set_vars && + install_gnumach && + print_info "bootstrap-kernel.sh finished successfully" && + exit 0 diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 0000000..6ef6efb --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. ./vars.sh +. ./download-funcs.sh +. ./bootstrap-funcs.sh + +print_info "Root is $CROSS_TOOLS" +print_info "Cross-compiling on $HOST to $TARGET" + +setup_directories + +mkdir -p $BUILD_ROOT/bootstrap && + cd $BUILD_ROOT/bootstrap && + compile_binutils && + compile_gcc && + compile_pkgconfiglite && + install_gnumach_headers && + install_gnumig && + install_hurd_headers && + compile_first_glibc && + compile_full_gcc && + compile_second_glibc && + print_info "bootstrap.sh finished successfully" && + exit 0 diff --git a/cleanup.sh b/cleanup.sh new file mode 100644 index 0000000..b80686c --- /dev/null +++ b/cleanup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +sudo rm -f /tools-{x86_64,i686} /cross-tools-{x86_64,i686} + +rm -rfv output* build* + +# Remove built image +rm -fv hd.img diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..15f1a41 --- /dev/null +++ b/compile.sh @@ -0,0 +1,706 @@ +#!/bin/sh + +. ./vars.sh +. ./download-funcs.sh +export CC="$CROSS_TOOLS/bin/${TARGET}-gcc" +export CXX="$CROSS_TOOLS/bin/${TARGET}-g++" +export AR="$CROSS_TOOLS/bin/${TARGET}-ar" +export AS="$CROSS_TOOLS/bin/${TARGET}-as" +export RANLIB="$CROSS_TOOLS/bin/${TARGET}-ranlib" +export LD="$CROSS_TOOLS/bin/${TARGET}-ld" +export STRIP="$CROSS_TOOLS/bin/${TARGET}-strip" +export MIG="$CROSS_TOOLS/bin/${TARGET}-mig" + +install_flex() { + mkdir -p $FLEX_SRC.obj && + cd $FLEX_SRC.obj && + ac_cv_func_realloc_0_nonnull=yes ac_cv_func_malloc_0_nonnull=yes \ + $SOURCE/$FLEX_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" && + sed -i -e 's/tests//' Makefile && + make -j$PROCS all && + make -j$PROCS install && + cd .. +} + +install_mig() { + cd $SOURCE/$GNUMIG_SRC && + autoreconf -i && + cd - && + rm -rf $GNUMIG_SRC.obj && + mkdir -p "$GNUMIG_SRC".obj && + cd "$GNUMIG_SRC".obj && + $SOURCE/$GNUMIG_SRC/configure \ + --build="$HOST" \ + --host="$TARGET" \ + --prefix="$SYS_ROOT" \ + --target="$TARGET" && + make clean && + make -j$PROCS all && + make -j$PROCS install && + cd .. +} + +install_zlib() { + mkdir -p $ZLIB_SRC.obj + cd $ZLIB_SRC.obj && + $SOURCE/$ZLIB_SRC/configure --prefix=$SYS_ROOT && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_bzip2() { + echo $PATH + rm -rf $BZIP2_SRC.obj && + cp -R $SOURCE/$BZIP2_SRC $BZIP2_SRC.obj && + pushd $BZIP2_SRC.obj && + # Ensure installation of symbolic links is relative. + sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile && + make -j$PROCS AR=$AR CC=$CC RANLIB=$RANLIB -f Makefile-libbz2_so && + make -j$PROCS clean && + make -j$PROCS CC=$CC AR=$AR RANLIB=$RANLIB bzip2 bzip2recover && + make -j$PROCS PREFIX=$SYS_ROOT install && + cp -v bzip2-shared $SYS_ROOT/bin/bzip2 && + cp -av libbz2.so* $SYS_ROOT/lib && + ln -fsv $SYS_ROOT/lib/libbz2.so.1.0 $SYS_ROOT/lib/libbz2.so && + popd +} + +install_gpg_error() { + cd $SOURCE/$GPG_ERROR_SRC && + ./autogen.sh && + cd - && + mkdir -p $GPG_ERROR_SRC.obj && + cd $GPG_ERROR_SRC.obj && + $SOURCE/$GPG_ERROR_SRC/configure --prefix=$SYS_ROOT \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_gcrypt() { + mkdir -p $GCRYPT_SRC.obj && + cd $GCRYPT_SRC.obj && + $SOURCE/$GCRYPT_SRC/configure --prefix=$SYS_ROOT \ + --build="$HOST" \ + --host="$TARGET" \ + --disable-padlock-support \ + --with-gpg-error-prefix="$SYS_ROOT" \ + --disable-asm && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_gnumach() { + print_info "Compiling GNUMach kernel" + cd $SOURCE/$GNUMACH_SRC && + autoreconf -i && + cd - && + mkdir -p $GNUMACH_SRC.obj && + cd $GNUMACH_SRC.obj && + local disable_user32="" + local mig_location + if [ -z "$USER32" ]; then + disable_user32="--disable-user32" + mig_location=$CROSS_TOOLS/bin/x86_64-gnu-mig + else + mig_location=/cross-tools-i686/bin/i686-gnu-mig + fi && + CFLAGS="-O2 -Wall -g -pipe -fno-strict-aliasing -no-pie -fno-PIE -fno-pie -Wformat -Werror=format-security" \ + LDFLAGS="-no-pie" \ + MIGUSER=$mig_location $SOURCE/$GNUMACH_SRC/configure \ + --host="$TARGET" \ + --build="$HOST" \ + --exec-prefix=/tmp/throwitaway \ + --enable-kdb \ + --enable-kmsg \ + --prefix="$SYS_ROOT" \ + --disable-net-group \ + --disable-pcmcia-group \ + --disable-wireless-group \ + $disable_user32 && + make clean && + make -j$PROCS gnumach.gz gnumach gnumach.msgids && + make -j$PROCS install && + mkdir -p $SYSTEM/boot && + cp gnumach{,.gz} $SYSTEM/boot/ && + cd - +} + +install_hurd() { + print_info "Compiling Hurd servers..." + pushd $SOURCE/$HURD_SRC && + autoreconf -i && + popd && + local extra_flags="$1" + mkdir -p $HURD_SRC.obj && + cd $HURD_SRC.obj && + $SOURCE/$HURD_SRC/configure \ + --build=$HOST \ + --host=$TARGET \ + --prefix=$SYS_ROOT \ + --with-libgcrypt-prefix=$SYS_ROOT \ + --enable-static-progs='ext2fs,iso9660fs,rumpdisk,pci-arbiter,acpi' \ + --disable-profile \ + $extra_flags && + make -j$PROCS clean && + make -j$PROCS all && + fakeroot make -j$PROCS install && + cd .. +} + +install_binutils () +{ + print_info "Compiling binutils" + rm -rf $BINUTILS_SRC.obj && + mkdir -p $BINUTILS_SRC.obj && + cd $BINUTILS_SRC.obj && + $SOURCE/$BINUTILS_SRC/configure \ + --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" \ + --target="$TARGET" \ + --with-lib-path="$SYS_ROOT"/lib \ + --disable-nls \ + --enable-shared \ + --disable-multilib && + make -j$PROCS all && + make -j$PROCS install && + cd .. +} + +install_bash() { + rm -rf $BASH_SRC.obj && + mkdir -p $BASH_SRC.obj && + cd $BASH_SRC.obj && + export CFLAGS="$CFLAGS -fcommon" + cat > config.cache << "EOF" +ac_cv_func_mmap_fixed_mapped=yes +ac_cv_func_strcoll_works=yes +ac_cv_func_working_mktime=yes +bash_cv_func_sigsetjmp=present +bash_cv_getcwd_malloc=yes +bash_cv_job_control_missing=present +bash_cv_printf_a_format=yes +bash_cv_sys_named_pipes=present +bash_cv_ulimit_maxfds=yes +bash_cv_under_sys_siglist=yes +bash_cv_unusable_rtsigs=no +gt_cv_int_divbyzero_sigfpe=yes +EOF + $SOURCE/$BASH_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" --host="$TARGET" \ + --without-bash-malloc --cache-file=config.cache && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_dash () { + rm -f $DASH_SRC.obj &^ + mkdir -p $DASH_SRC.obj && + pushd $DASH_SRC.obj && + $SOURCE/$DASH_SRC/configure --prefix=$SYS_ROOT \ + --build=$HOST --host=$TARGET + make -j$PROCS && + make -j$PROCS install && + popd +} + +install_coreutils() { + mkdir -p $COREUTILS_SRC.obj && + cd $COREUTILS_SRC.obj && + cat > config.cache << EOF +fu_cv_sys_stat_statfs2_bsize=yes +gl_cv_func_working_mkstemp=yes +EOF + $SOURCE/$COREUTILS_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" \ + --enable-install-program=hostname \ + --disable-year2038 \ + --cache-file=config.cache && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_libuuid() { + cd "$LIBUUID_SRC" && + ./configure --prefix="$SYS_ROOT" \ + --host="$HOST" \ + --target="$TARGET" && + make -j$PROCS && make -j$PROCS install && + cd .. +} + +install_e2fsprogs() { + rm -rf $E2FSPROGS_SRC.obj && + mkdir -p $E2FSPROGS_SRC.obj && + cd $E2FSPROGS_SRC.obj && + LDFLAGS="-luuid" $SOURCE/$E2FSPROGS_SRC/configure \ + --prefix="$SYS_ROOT" \ + --enable-elf-shlibs \ + --build=${HOST} \ + --host=${TARGET} \ + --disable-libblkid \ + --disable-libuuid \ + --disable-uuidd && + make -j$PROCS && make -j$PROCS install && make -j$PROCS install-libs && + cd .. +} + +install_util_linux() { + mkdir -p $UTIL_LINUX_SRC.obj && + cd $UTIL_LINUX_SRC.obj && + $SOURCE/$UTIL_LINUX_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" \ + --disable-makeinstall-chown \ + --without-ncursesw \ + --disable-makeinstall-setuid && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_grub() { + mkdir -p $GRUB_SRC.obj && + cd $GRUB_SRC.obj && + $SOURCE/$GRUB_SRC/configure --prefix="$SYS_ROOT" \ + --build=${HOST} \ + --host=${TARGET} \ + --disable-efiemu \ + --disable-werror \ + --enable-grub-mkfont=no \ + --with-bootdir=$SYS_ROOT/boot && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_libxcrypt () { + mkdir -p $LIBXCRYPT_SRC.obj && + cd $LIBXCRYPT_SRC.obj && + $SOURCE/$LIBXCRYPT_SRC/configure --prefix=$SYS_ROOT \ + --build=$HOST \ + --host=$TARGET \ + --enable-hashes=strong,glibc \ + --enable-obsolete-api=no \ + --disable-static \ + --disable-failure-tokens + make -j$PROCS && + make -j $PROCS install && + cd .. +} + +install_dmidecode () { + rm -rf $DMIDECODE_SRC.obj && + cp -R $SOURCE/$DMIDECODE_SRC ./$DMIDECODE_SRC.obj && + pushd $DMIDECODE_SRC.obj && + make -j$PROCS && + make -j$PROCS install prefix=$SYS_ROOT && + popd +} + +install_parted () { + mkdir -p $PARTED_SRC.obj && + pushd $PARTED_SRC.obj && + $SOURCE/$PARTED_SRC/configure --prefix=$SYS_ROOT \ + --build=$HOST \ + --host=$TARGET \ + --disable-device-mapper \ + --enable-mtrace \ + --enable-shared \ + --without-readline && + make -j$PROCS && + make -j$PROCS install && + popd +} + +install_shadow () { + rm -rf $SHADOW_SRC.copy && + cp -R $SOURCE/$SHADOW_SRC $SHADOW_SRC.copy && + pushd $SHADOW_SRC.copy && + # Disable installation of some tools since they are provided by either + # the Hurd itself or coreutils. + sed -i -e 's/groups$(EXEEXT) //' \ + -e 's/= nologin$(EXEEXT)/= /' \ + -e 's/= login$(EXEEXT)/= /' \ + src/Makefile.in && + # Disable several manpages. + find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \; + find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \; + find man -name Makefile.in -exec sed -i 's/passwd\.5 / /' {} \; + sed -e 's:/var/spool/mail:/var/mail:' \ + -e '/PATH=/{s@/sbin:@@;s@/bin:@@}' \ + -i etc/login.defs && + apply_patch $SCRIPT_DIR/patches/shadow/shadow-utmp.patch 1 && + popd && + rm -rf $SHADOW_SRC.obj && + mkdir -p $SHADOW_SRC.obj && + cd $SHADOW_SRC.obj && + ../$SHADOW_SRC.copy/configure --prefix="$SYS_ROOT" \ + --build=${HOST} \ + --host=${TARGET} \ + --cache-file=config.cache \ + --enable-subordinate-ids=no \ + --disable-dependency-tracking \ + --without-libbsd && + echo "#define ENABLE_SUBIDS 1" >> config.h && + make -j$PROCS && make exec_prefix=$SYS_ROOT -j$PROCS install && cd .. +} + +install_sed() { + mkdir -p $SED_SRC.obj && + cd $SED_SRC.obj && + $SOURCE/$SED_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_gmp() { + rm -rf $GMP_SRC.obj && + mkdir -p $GMP_SRC.obj && + cd $GMP_SRC.obj && + CC_FOR_BUILD="$HOST_MACHINE-gcc" $SOURCE/$GMP_SRC/configure \ + --prefix="$SYS_ROOT" \ + --build=${HOST} \ + --host=${TARGET} && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_mpfr() { + rm -rf $MPFR_SRC.obj && + mkdir -p $MPFR_SRC.obj && + cd $MPFR_SRC.obj && + $SOURCE/$MPFR_SRC/configure --prefix="$SYS_ROOT" \ + --build=${HOST} \ + --host=${TARGET} && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_mpc() { + rm -rf $MPC_SRC.obj && + mkdir -p $MPC_SRC.obj && + cd $MPC_SRC.obj && + $SOURCE/$MPC_SRC/configure --prefix="$SYS_ROOT" \ + --build=${HOST} \ + --host=${TARGET} && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_gcc() { + print_info "Compiling GCC" + cp -R $SOURCE/$GCC_SRC $GCC_SRC.compiler + cd $GCC_SRC.compiler && + cp -v gcc/Makefile.in{,.orig} && + sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in && + cd .. && + rm -rf $GCC_SRC.obj && + mkdir -p $GCC_SRC.obj && + cd $GCC_SRC.obj && + LDFLAGS="-lpthread" \ + ../$GCC_SRC.compiler/configure \ + --prefix=$SYS_ROOT \ + --build=${HOST} \ + --target=${TARGET} \ + --host=${TARGET} \ + --disable-multilib \ + --disable-bootstrap \ + --with-local-prefix="$SYS_ROOT" \ + --disable-nls \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch \ + --with-system-zlib \ + --with-native-system-header-dir="$SYS_ROOT/include" \ + --enable-checking=release \ + --disable-libcilkrts \ + --disable-libssp + cp -v Makefile{,.orig} && + sed "/^HOST_\(GMP\|ISL\|CLOOG\)\(LIBS\|INC\)/s:$SYS_ROOT:$CROSS_TOOLS:g" \ + Makefile.orig > Makefile + make -j$PROCS AS_FOR_TARGET="$AS" LD_FOR_TARGET="$LD" all && + make -j$PROCS install && + cd .. +} + +install_ncurses () { + rm -rf $NCURSES_SRC.obj && + mkdir -p $NCURSES_SRC.obj && + pushd $NCURSES_SRC.obj && + # Build required host tools. + mkdir host && + pushd host && + CC=gcc RANLIB=ranlib AR=ar LD=ld PATH=/usr/bin \ + $SOURCE/$NCURSES_SRC/configure && + make -j$PROCS -C include && + make -j$PROCS -C progs tic && + popd && + LDFLAGS="-lpthread" CPPFLAGS="-P" $SOURCE/$NCURSES_SRC/configure \ + --prefix="${SYS_ROOT}" \ + --with-shared \ + --build=${HOST} \ + --host=${TARGET} \ + --without-debug \ + --without-ada \ + --with-termlib \ + --enable-overwrite \ + --with-build-cc=gcc && + make -j$PROCS && + make -j$PROCS TIC_PATH=$PWD/host/progs/tic install && + popd +} + +install_vim () { + rm -rf $VIM_SRC.obj && + cp -R $SOURCE/vim$VIM_BASE_VERSION $VIM_SRC.obj && + pushd $VIM_SRC.obj && + cat > src/auto/config.cache << "EOF" + vim_cv_getcwd_broken=no + vim_cv_memmove_handles_overlap=yes + vim_cv_stat_ignores_slash=no + vim_cv_terminfo=yes + vim_cv_toupper_broken=no + vim_cv_tty_group=world + vim_cv_tgetent=zero +EOF + ./configure --build=${HOST} \ + --host=${TARGET} \ + --prefix=${SYS_ROOT} \ + --enable-gui=no \ + --disable-gtktest \ + --disable-xim \ + --disable-gpm \ + --without-x \ + --disable-netbeans \ + --with-tlib=tinfo && + make -j$PROCS && + make -j$PROCS uninstall && + make -j$PROCS install && + ln -sfv vim $SYS_ROOT/bin/vi && + popd && + cat > $SYS_ROOT/etc/vimrc << "EOF" +set nocompatible +set backspace=2 +set expandtab +set ts=2 +set ruler +syntax on +EOF +} + +install_make() { + rm -rf $MAKE_SRC.obj && + mkdir -p $MAKE_SRC.obj && + cd $MAKE_SRC.obj && + $SOURCE/$MAKE_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make -j$PROCS install && + cd .. +} + +install_grep() { + rm -rf $GREP_SRC.obj && + mkdir -p $GREP_SRC.obj && + cd $GREP_SRC.obj && + $SOURCE/$GREP_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make install && + cd .. +} + +install_gawk() { + rm -rf $GAWK_SRC.obj && + mkdir -p $GAWK_SRC.obj && + cd $GAWK_SRC.obj && + $SOURCE/$GAWK_SRC/configure --prefix="$SYS_ROOT" \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make install && + cd .. +} + +install_libpciaccess () { + rm -rf $LIBPCIACCESS_SRC.obj && + mkdir -p $LIBPCIACCESS_SRC.obj && + pushd $LIBPCIACCESS_SRC.obj && + $SOURCE/$LIBPCIACCESS_SRC/configure --prefix=$SYS_ROOT \ + --build=$HOST \ + --host=$TARGET && + make -j$PROCS && + make install && + popd +} + +install_libacpica () { + rm -rf libacpica.obj && + mkdir -p libacpica.obj && + pushd libacpica.obj && + mkdir -p src && + cp -R $SOURCE/libacpica/* src/ && + pushd src && + (for patch in `ls debian/patches/*.diff`; do + print_info "Patch $patch" + patch -p1 < $patch + done) && + make -j$PROCS && + make PREFIX=$SYS_ROOT install && + popd && + popd +} + +install_rump () { + local arch="" + if [ $CPU = "i686" ]; then + arch="i386" + else + arch="amd64" + fi + pushd $SOURCE/rumpkernel/ && + OBJ=`pwd`/obj + mkdir -p $OBJ && + echo "OBJ $OBJ" && + git clean -fdx && + git checkout . && + for file in `cat debian/patches/series`; do + echo $file + patch -p1 < debian/patches/$file + done + pushd buildrump.sh/src && + pushd lib/librumpuser && + ./configure --prefix=$SYS_ROOT \ + --build=$HOST \ + --host=$TARGET && + popd && + CFLAGS="-Wno-format-security -Wno-omit-frame-pointer" \ + HOST_GCC=$HOST_CC TARGET_CC=$CC TARGET_CXX=$CC \ + TARGET_LD=$LD TARGET_MIG=$MIG \ + TARGET_LDADD="-B/$SYS_ROOT/lib -L$SYS_ROOT/lib -L$SYS_ROOT/lib" \ + _GCC_CRTENDS= _GCC_CRTEND= _CC_CRTBEGINS= \ + _GCC_CRTBEGIN= _GCC_CRTI= _GCC_CRTN= \ + BSDOBJECTDIR=$OBJ \ + ./build.sh \ + -V TOOLS_BUILDRUMP=yes \ + -V MKBINUTILS=no -V MKGDB=no -V MKGROFF=no \ + -V MKDTRACE=no -V MKZFS=no \ + -V TOPRUMP=$SOURCE/rumpkernel/buildrump.sh/src/sys/rump \ + -V BUILDRUMP_CPPFLAGS="-Wno-error=stringop-overread" \ + -V RUMPUSER_EXTERNAL_DPLIBS=pthread \ + -V CPPFLAGS="-I$OBJ/destdir/usr/include -D_FILE_OFFSET_BITS=64 -DRUMP_REGISTER_T=int -DRUMPUSER_CONFIG=yes -DNO_PCI_MSI_MSIX=yes -DNUSB_DMA=1 -DPAE" \ + -V CWARNFLAGS="-Wno-error=maybe-uninitialized -Wno-error=address-of-packed-member -Wno-error=unused-variable -Wno-error=stack-protector -Wno-error=array-parameter -Wno-error=array-bounds -Wno-error=stringop-overflow -Wno-error=int-to-pointer-cast -Wno-error=incompatible-pointer-types" \ + -V LIBCRTBEGIN=" " -V LIBCRTEND=" " -V LIBCRT0=" " -V LIBCRTI=" " \ + -V MIG=mig \ + -V DESTDIR=$OBJ/destdir \ + -V _GCC_CRTENDS=" " -V _GCC_CRTEND=" " \ + -V _GCC_CRTBEGINS=" " -V _GCC_CRTBEGIN=" " \ + -V _GCC_CRTI=" " -V _GCC_CRTN=" " \ + -V TARGET_LDADD="-B$SYS_ROOT/lib -L$SYS_ROOT/lib -L$SYS_ROOT/lib" \ + -U -u -T $OBJ/tooldir -m $arch -j $PROCS tools rump && + pushd lib/librumpuser && + RUMPRUN=true $OBJ/tooldir/bin/nbmake-$arch dependall + popd && + popd && + pushd pci-userspace/src-gnu && + $OBJ/tooldir/bin/nbmake-$arch MIG=$MIG dependall && + popd && + # Perform installation by copying the required files. + # Copy headers. + cp -aR buildrump.sh/src/sys/rump/include/rump $SYS_ROOT/include/ && + # Copy libraries. + find $OBJ/destdir buildrump.sh/src -type f,l \ + -name "librump*.so*" -not -path '*.map' -not -path '*librumpkern_z*' -exec cp -a {} $SYS_ROOT/lib/ \; && + find $OBJ/destdir buildrump.sh/src -type f,l \ + -name "librump*.a" -not -path '*librumpkern_z*' -exec cp -a {} $SYS_ROOT/lib \; && + popd +} + +install_findutils () { + rm -rf $LIBPCIACCESS_SRC.obj && + mkdir -p $LIBPCIACCESS_SRC.obj && + pushd $LIBPCIACCESS_SRC.obj && + $SOURCE/$FINDUTILS_SRC/configure --prefix=$SYS_ROOT \ + --build="$HOST" \ + --host="$TARGET" && + make -j$PROCS && + make -j$PROCS install && + popd +} + +install_minimal_system() { + install_libxcrypt && + install_libpciaccess && + install_libacpica && + install_zlib && + install_bzip2 && + install_gnumach && + install_gpg_error && + install_gcrypt && + install_ncurses && + install_util_linux && + install_rump && + # We need to build basic hurd libraries in order to + # compile parted. + install_hurd --without-parted && + install_dmidecode && + install_parted && + install_hurd && + install_bash && + install_dash && + install_coreutils && + install_e2fsprogs && + install_findutils && + install_grub && + install_shadow && + install_sed +} + +install_more_shell_tools() { + install_grep && + install_gawk +} + +install_development_tools() { + install_flex && + install_mig && + install_binutils && + install_gmp && + install_mpfr && + install_mpc && + install_gcc && + install_make +} + +install_editors() { + install_vim +} + +mkdir -p $BUILD_ROOT/native && + cd $BUILD_ROOT/native && + install_minimal_system && + if [ $BUILD_TYPE = "full" ]; then + install_more_shell_tools && + install_editors && + install_development_tools + fi && + print_info "compile.sh finished successfully" && + exit 0 diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..25165f1 --- /dev/null +++ b/config.sh @@ -0,0 +1,29 @@ +# Change your host GCC here. +export HOST_MACHINE=x86_64-linux-gnu + +# You can change the host toolchain used here. +export HOST_CC=gcc +export HOST_CXX=g++ +export HOST_AR=ar +export HOST_AS=as +export HOST_RANLIB=ranlib + +# Change how many CPUs you want to use. +if [ -z "$PROCS" ]; then + export PROCS=$(nproc) +fi + +# Set this to your ccache path if using ccache. +export CCACHE_DIRECTORY="/usr/lib/ccache" + +# The kind of hurd system to build. The options are: +# minimal: enough to run a shell. +# full: everything. +if [ -z "$BUILD_TYPE" ]; then + export BUILD_TYPE=minimal +fi + +# GNU Hurd target. +if [ -z "$CPU" ]; then + export CPU=i686 +fi diff --git a/create-image.sh b/create-image.sh new file mode 100644 index 0000000..1ae60cc --- /dev/null +++ b/create-image.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +. ./vars.sh + +LOOP=$(sudo losetup -f) +LOOPPART="${LOOP}p1" +IMG=hd.img +IMG_SIZE=10GB +BASE_SYS_ROOT=$(basename $SYS_ROOT) + +create_image () { + print_info "Creating disk image $IMG using $LOOP..." + fallocate -l $IMG_SIZE $IMG && + sudo losetup $LOOP $IMG && + sudo parted -a optimal -s $LOOP mklabel msdos && + sudo parted -a optimal -s $LOOP -- mkpart primary ext2 2048s -1 && + sudo parted -s $LOOP -- set 1 boot on && + sudo losetup -d $LOOP && + sudo losetup -P $LOOP $IMG && + sleep 2 && + sudo mkfs.ext2 -o hurd -m 1 -v $LOOPPART +} + +mount_image () { + mkdir -p mount && + sudo mount -o rw -t ext2 $LOOPPART mount && + sudo chmod ogu+w -R mount/ +} + +copy_files () { + print_info "Copying system into mount..." + mkdir -p mount/{etc,boot,dev,usr,hurd,include,servers,lib,libexec,proc,sbin,bin,var,root,share} && + mkdir -p mount/var/{run,lib} && + mkdir -p mount/servers/{socket,bus} && + cp -R files/etc/* mount/etc/ && + mkdir -p mount/etc/hurd && + cp files/runsystem.hurd mount/libexec/ && + chmod ogu+x mount/libexec/runsystem.hurd && + mkdir -p mount/boot/grub && + cp files/boot/grub.cfg mount/boot/grub/grub.cfg && + cp $SYSTEM/boot/gnumach.gz mount/boot && + mkdir -p mount/servers && + touch mount/servers/{acpi,exec,crash-kill,default-pager,password,socket,startup,proc,auth,symlink} && + mkdir mount/tmp && chmod 01777 mount/tmp && + cp -R $SYSTEM/$BASE_SYS_ROOT/hurd/* mount/hurd/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/dev/* mount/dev/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/include/* mount/include/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/sbin/* mount/sbin/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/bin/* mount/bin/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/lib/* mount/lib/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/share/* mount/share/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/etc/* mount/etc/ && + cp -R $SYSTEM/$BASE_SYS_ROOT/libexec/* mount/libexec/ && + cp files/{rc,runsystem} mount/libexec/ && + (if [ -f mount/lib/ld-x86-64.so.1 ]; then + ln -sfv /lib/ld-x86-64.so.1 mount/lib/ld.so + else + ln -sfv /lib/ld.so.1 mount/lib/ld.so + fi) && + ln -svf / mount/$BASE_SYS_ROOT + ln -svf /bin/bash mount/bin/sh && + cp files/SETUP mount/ && + chmod +x mount/SETUP && + rm -f manifest-$CPU.txt && + pushd mount && + (find . > ../manifest-$CPU.txt || true) && + popd && + # Create a motd message. + echo "Welcome to the HURD!" > mount/etc/motd && + echo "Cross-compiled from a $HOST on `date`" >> mount/etc/motd && + # Ensure all files are owned by root inside the system image. + sudo chown root:root -R mount/* +} + +install_grub () { + print_info "Installing the GRUB on $IMG..." + sudo grub-install --target=i386-pc --directory=$SYS_ROOT/lib/grub/i386-pc --boot-directory=$PWD/mount/boot $LOOP +} + +umount_image () { + print_info "Umounting $LOOP" + sudo umount mount >/dev/null 2>&1 && + sudo losetup -d $LOOP && + rmdir mount +} + +trap umount_image EXIT +trap umount_image INT + +umount mount >/dev/null 2>&1 +sudo losetup -d $LOOP >/dev/null 2>&1 +rm -f $IMG +create_image && + mount_image && + copy_files && + install_grub && +print_info "Disk image available on $IMG" && +print_info "Run 'qemu-system-i386 $IMG' to enjoy the Hurd!" && +exit 0 diff --git a/create-initrd.sh b/create-initrd.sh new file mode 100644 index 0000000..40bc2a9 --- /dev/null +++ b/create-initrd.sh @@ -0,0 +1,118 @@ +#!/bin/bash +# +if [ -z $CPU ]; then + echo "CPU needs to be set" + exit 1 +fi + +. ./vars.sh + +LOOP=$(sudo losetup -f) +LOOPPART="${LOOP}p1" +IMG_SIZE=2048MB +BASE_SYS_ROOT=$(basename $SYS_ROOT) +INITRD_FILE=initrd.ext2 +INITRD_SIZE=100MB +DISK_SIZE=2048MB +IMG=hd.img + +create_initrd () { + print_info "Creating disk image $INITRD_FILE using $LOOP..." + fallocate -l $INITRD_SIZE $INITRD_FILE && + sudo losetup $LOOP $INITRD_FILE && + sudo mkfs.ext2 -o hurd -b 4096 -v $LOOP + sudo losetup -d $LOOP && + sudo losetup -P $LOOP $INITRD_FILE && + sleep 2 && + fill_initrd +} + +fill_initrd () { + local src=$SYSTEM/$BASE_SYS_ROOT + echo "Copying from $src" + mkdir -p output-initrd && + sudo mount -o rw -t ext2 $LOOP output-initrd && + sudo chmod ogu+w -R output-initrd && + mkdir -p output-initrd/{dev,hurd,bin,lib,libexec,proc,sbin,servers} && + touch output-initrd/servers/{exec,crash-kill,default-pager,password,socket,startup,proc,auth,symlink} && + cp $src/hurd/{exec,auth,init,null,devnode,storeio,ext2fs,console,hello,streamio,proc,procfs,startup} output-initrd/hurd/ && + cp $src/lib/*.so* output-initrd/lib/ && + cp $src/bin/{settrans,echo,uname} output-initrd/bin/ && + cp $src/bin/bash output-initrd/bin/sh && + cp $src/bin/{ls,ps,settrans,cat,uptime,wall,who,yes,whoami,sleep,portinfo,msgport,fsysopts,env,sleep,date,tty,rpctrace,md5sum,cal,df,du} output-initrd/bin/ && + cp $src/sbin/{halt,reboot} output-initrd/sbin/ && + cp files/runsystem.initrd output-initrd/libexec/runsystem && + cp $src/bin/dash output-initrd/libexec/console-run && + ln -sf / output-initrd/tools-$CPU && + sudo mknod -m 600 output-initrd/dev/mach-console c 5 1 && + echo "Contents of initrd:" && + pushd output-initrd && + find . + popd && + sudo losetup -d $LOOP +} + +create_image () { + print_info "Creating disk image $IMG using $LOOP..." + fallocate -l $IMG_SIZE $IMG && + sudo losetup $LOOP $IMG && + sudo parted -a optimal -s $LOOP mklabel msdos && + sudo parted -a optimal -s $LOOP -- mkpart primary ext2 2048s -1 && + sudo parted -s $LOOP -- set 1 boot on && + sudo losetup -d $LOOP && + sudo losetup -P $LOOP $IMG && + sleep 2 && + sudo mkfs.ext2 -o hurd -m 1 -v $LOOPPART +} + +mount_image () { + mkdir -p output-disk && + sudo mount -o rw -t ext2 $LOOPPART output-disk && + sudo chmod ogu+w -R output-disk/ +} + +fill_disk () { + local src=$SYSTEM/$BASE_SYS_ROOT + mkdir -p output-disk/{sbin,boot,tools,lib} && + mkdir -p output-disk/boot/grub && + cp $src/hurd/ext2fs.static output-disk/sbin && + cp $src/lib/ld-x86-64.so.1 output-disk/lib/ld.so.1 && + mv $INITRD_FILE output-disk/boot && + cp $SYSTEM/boot/gnumach output-disk/boot && + cp files/boot/grub.initrd.cfg output-disk/boot/grub/grub.cfg && + echo "Disk contents:" + pushd output-disk && + find . + popd +} + +install_grub () { + print_info "Installing the GRUB on $IMG..." + sudo grub-install --target=i386-pc --directory=$SYS_ROOT/lib/grub/i386-pc --boot-directory=output-disk/boot $LOOP +} + +umount_initrd () { + sudo umount output-initrd + sudo losetup -d $LOOP +} + +umount_image () { + sudo umount output-disk >/dev/null 2>&1 + sudo losetup -d $LOOP >/dev/null 2>&1 +} + +trap umount_initrd EXIT +trap umount_initrd INT +trap umount_image EXIT +trap umount_image INT + +rm -f $INITRD_FILE && +rm -f $IMG && +create_initrd && +sudo umount output-initrd && +echo $(losetup -f) +create_image && +mount_image && +fill_disk && +install_grub && +umount_image diff --git a/download-funcs.sh b/download-funcs.sh new file mode 100644 index 0000000..8699503 --- /dev/null +++ b/download-funcs.sh @@ -0,0 +1,307 @@ +#!/bin/sh + +. ./config.sh + +BINUTILS_URL=https://ftp.gnu.org/gnu/binutils/$BINUTILS_PKG +GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-"$GCC_VERSION"/"$GCC_PKG" +FLEX_URL=https://github.com/westes/flex/releases/download/v$FLEX_VERSION/$FLEX_PKG +ZLIB_URL=http://zlib.net/"$ZLIB_PKG" +BZIP2_URL=https://sourceware.org/pub/bzip2/$BZIP2_PKG +BASH_URL=https://ftp.gnu.org/gnu/bash/"$BASH_PKG" +COREUTILS_URL=https://ftp.gnu.org/gnu/coreutils/"$COREUTILS_PKG" +E2FSPROGS_URL=https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v"$E2FSPROGS_VERSION"/"$E2FSPROGS_PKG" +PKGCONFIGLITE_URL=http://downloads.sourceforge.net/project/pkgconfiglite/"$PKGCONFIGLITE_VERSION"/"$PKGCONFIGLITE_PKG" +LIBUUID_URL=http://downloads.sourceforge.net/project/libuuid/"$LIBUUID_PKG" +UTIL_LINUX_URL=https://www.kernel.org/pub/linux/utils/util-linux/v$UTIL_LINUX_MAJOR_VERSION/"$UTIL_LINUX_PKG" +GRUB_URL=https://ftp.gnu.org/gnu/grub/"$GRUB_PKG" +SHADOW_URL=https://github.com/shadow-maint/shadow/releases/download/"$SHADOW_VERSION"/"$SHADOW_PKG" +SED_URL=https://ftp.gnu.org/gnu/sed/"$SED_PKG" +GMP_URL=https://ftp.gnu.org/gnu/gmp/"$GMP_PKG" +MPFR_URL=http://mpfr.org/mpfr-current/"$MPFR_PKG" +MPC_URL=https://ftp.gnu.org/gnu/mpc/"$MPC_PKG" +NCURSES_URL=https://ftp.gnu.org/gnu/ncurses/"$NCURSES_PKG" +VIM_URL=ftp://ftp.vim.org/pub/vim/unix/"$VIM_PKG" +GPG_ERROR_URL=ftp://ftp.gnupg.org/gcrypt/libgpg-error/"$GPG_ERROR_PKG" +GCRYPT_URL=ftp://ftp.gnupg.org/gcrypt/libgcrypt/"$GCRYPT_PKG" +MAKE_URL=ftp://ftp.gnu.org/gnu/make/"$MAKE_PKG" +GREP_URL=https://ftp.gnu.org/gnu/grep/"$GREP_PKG" +GAWK_URL=https://ftp.gnu.org/gnu/gawk/"$GAWK_PKG" +DASH_URL=http://gondor.apana.org.au/~herbert/dash/files/$DASH_PKG +LIBPCIACCESS_URL=https://www.x.org/pub/individual/lib/$LIBPCIACCESS_PKG +LIBXCRYPT_URL=https://github.com/besser82/libxcrypt/releases/download/v$LIBXCRYPT_VERSION/$LIBXCRYPT_PKG +PARTED_URL=https://ftp.gnu.org/gnu/parted/$PARTED_PKG +DMIDECODE_URL=http://download.savannah.gnu.org/releases/dmidecode/$DMIDECODE_PKG +FINDUTILS_URL=https://ftp.gnu.org/gnu/findutils/$FINDUTILS_PKG + +unpack () { + if [ -d "$3" ]; then + return 0 + fi + print_info "unpacking $2" && + tar $1 $2 +} + +DOWNLOAD_CACHE_DIRECTORY=~/.cache/cross-hurd +CACHE_DOWNLOADS=1 +CACHE_GIT=1 + +download () { + if [ -f $1 ]; then + return 0 + fi + if [ -n "$CACHE_DOWNLOADS" ]; then + mkdir -p $DOWNLOAD_CACHE_DIRECTORY + pushd $DOWNLOAD_CACHE_DIRECTORY && + (test -f $1 || wget $2) && + popd && + cp $DOWNLOAD_CACHE_DIRECTORY/$1 . + else + wget $2 + fi +} + +download_from_git () { + dir=$1 + repo=$2 + branch=$3 + add_branch="" + if [ -n "$branch" ]; then + add_branch="--branch $branch" + fi + (if [ -d $dir ]; then + pushd $dir && + git reset --hard && + git pull && + local git_result=$? + popd && + return $git_result + elif [ -n "$CACHE_GIT" ]; then + mkdir -p $DOWNLOAD_CACHE_DIRECTORY && + pushd $DOWNLOAD_CACHE_DIRECTORY && + (if [ -d $dir ]; then + pushd $dir && + git reset --hard && + git pull && + popd + else + git clone --depth=1 $repo $add_branch $dir + fi) && + popd && + ln -sf $DOWNLOAD_CACHE_DIRECTORY/$dir . + else + git clone --depth=1 $repo + fi) +} + +download_gnumach () { + download_from_git gnumach git://git.savannah.gnu.org/hurd/gnumach.git && + pushd gnumach && + apply_patch $SCRIPT_DIR/patches/gnumach/50_initrd.patch 1 && + apply_patch $SCRIPT_DIR/patches/gnumach/79_dde-debian.patch 1 && + popd +} + +download_mig () { + download_from_git mig git://git.savannah.gnu.org/hurd/mig.git +} + +download_hurd () { + download_from_git hurd git://git.savannah.gnu.org/hurd/hurd.git && + pushd hurd && + apply_patch $SCRIPT_DIR/patches/hurd/link-rump.patch 1 + popd +} + +download_rumpkernel () { + download_from_git rumpkernel https://salsa.debian.org/hurd-team/rumpkernel.git +} + +download_libacpica () { + download_from_git libacpica https://salsa.debian.org/hurd-team/libacpica.git +} + +apply_patch() { + print_info "Using patch $1 (level: $2)" + if patch -f -Np$2 --dry-run < $1 > /dev/null 2>&1; then + patch -Np$2 < $1 || exit 1 + else + echo "Cannot apply patch!" + fi +} + +download_glibc () { + (if [ ! -d glibc ]; then + git clone --depth=1 git://sourceware.org/git/glibc.git + fi) && + + cd glibc && + git reset --hard && + git pull && + git checkout $GLIBC_TAG && + apply_patch $SCRIPT_DIR/patches/glibc/tg-bits_atomic.h_multiple_threads.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/tg-unlockpt-chroot.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/local-clock_gettime_MONOTONIC.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/submitted-AF_LINK.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/unsubmitted-prof-eintr.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/unsubmitted-getaux_at_secure.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/local-static_pthread_setcancelstate.diff 1 && + apply_patch $SCRIPT_DIR/patches/glibc/tg-mach-hurd-link.diff 1 && + cd .. +} + +download_gcc () { + download $GCC_PKG $GCC_URL && + if [ -d "$GCC_SRC" ]; then + return 0 + fi + unpack zxf $GCC_PKG $GCC_SRC && + pushd $GCC_SRC && + apply_patch $SCRIPT_DIR/patches/gcc/hurd-amd64.diff 1 && + apply_patch $SCRIPT_DIR/patches/gcc/hurd-multiarch.diff 1 && + apply_patch $SCRIPT_DIR/patches/gcc/hurd-multilib-multiarch.diff 1 && + popd +} + +download_binutils () { + download $BINUTILS_PKG $BINUTILS_URL && + if [ -d "$BINUTILS_SRC" ]; then + return 0 + fi + unpack jxf $BINUTILS_PKG $BINUTILS_SRC + } + +download_coreutils () { + download $COREUTILS_PKG $COREUTILS_URL && + if [ ! -d "$COREUTILS_SRC" ]; then + unpack Jxf $COREUTILS_PKG $COREUTILS_SRC + fi +} + +download_sed () { + download $SED_PKG $SED_URL && + if [ -d "$SED_SRC" ]; then + return 0 + fi + unpack xf $SED_PKG $SED_SRC +} + +download_ncurses () { + download $NCURSES_PKG $NCURSES_URL && + if [ -d "$NCURSES_SRC" ]; then + return 0 + fi + unpack zxf $NCURSES_PKG $NCURSES_SRC +} + +download_vim () { + download $VIM_PKG $VIM_URL && + if [ -d "vim$VIM_BASE_VERSION" ]; then + return 0 + fi + unpack jxf $VIM_PKG $VIM_SRC +} + +download_gpg_error () { + download $GPG_ERROR_PKG $GPG_ERROR_URL && + if [ -d "$GPG_ERROR_SRC" ]; then + return 0 + fi + unpack jxf $GPG_ERROR_PKG $GPG_ERROR_SRC && + pushd $GPG_ERROR_SRC && + apply_patch $SCRIPT_DIR/patches/libgpg-error/hurd-amd64.patch 1 && + popd +} + +download_gcrypt () { + download $GCRYPT_PKG $GCRYPT_URL && + if [ -d "$GCRYPT_SRC" ]; then + return 0 + fi + unpack jxf $GCRYPT_PKG $GCRYPT_SRC +} + +download_make () { + download $MAKE_PKG $MAKE_URL && + if [ -d "$MAKE_SRC" ]; then + return 0 + fi + unpack xf $MAKE_PKG $MAKE_SRC +} + +download_grub () { + download $GRUB_PKG $GRUB_URL && + if [ -d "$GRUB_SRC" ]; then + return 0 + fi + unpack zxf $GRUB_PKG $GRUB_SRC +} + +download_grep () { + download $GREP_PKG $GREP_URL && + if [ -d "$GREP_SRC" ]; then + return 0 + fi + unpack xf $GREP_PKG $GREP_SRC + pushd $GREP_SRC && + apply_patch $SCRIPT_DIR/patches/grep/gnulib-hurd-x86_64.patch 1 && + popd +} + +download_gawk () { + download $GAWK_PKG $GAWK_URL && + if [ -d "$GAWK_SRC" ]; then + return 0 + fi + unpack xf $GAWK_PKG $GAWK_SRC +} + +download_dash () { + download $DASH_PKG $DASH_URL && + if [ -d $DASH_SRC ]; then + return 0 + fi + unpack xf $DASH_PKG $DASH_SRC + pushd $DASH_SRC && + apply_patch $SCRIPT_DIR/patches/dash/dash-path-max.patch 1 && + popd +} + +download_libpciaccess () { + download $LIBPCIACCESS_PKG $LIBPCIACCESS_URL && + if [ -d $LIBPCIACCESS_SRC ]; then + return 0 + fi + unpack xf $LIBPCIACCESS_PKG $LIBPCIACCESS_SRC +} + +download_libxcrypt () { + download $LIBXCRYPT_PKG $LIBXCRYPT_URL && + if [ -d $LIBXCRYPT_SRC ]; then + return 0 + fi + unpack xf $LIBXCRYPT_PKG $LIBXCRYPT_SRC +} + +download_parted () { + download $PARTED_PKG $PARTED_URL && + if [ -d $PARTED_SRC ]; then + return 0 + fi + unpack xf $PARTED_PKG $PARTED_SRC +} + +download_dmidecode () { + download $DMIDECODE_PKG $DMIDECODE_URL && + if [ -d $DMIDECODE_SRC ]; then + return 0 + fi + unpack xf $DMIDECODE_PKG $DMIDECODE_SRC +} + +download_findutils () { + download $FINDUTILS_PKG $FINDUTILS_URL && + if [ -d $FINDUTILS_SRC ]; then + return 0 + fi + unpack xf $FINDUTILS_PKG $FINDUTILS_SRC +} diff --git a/download.sh b/download.sh new file mode 100644 index 0000000..8301602 --- /dev/null +++ b/download.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +. ./vars.sh +. ./download-funcs.sh + +mkdir -p $SOURCE && +cd $SOURCE && + +download_gcc && +download_binutils && +download $FLEX_PKG $FLEX_URL && +unpack zxf $FLEX_PKG $FLEX_SRC && +download $ZLIB_PKG $ZLIB_URL && +unpack zxf $ZLIB_PKG $ZLIB_SRC && +download $BZIP2_PKG $BZIP2_URL && +unpack zxf $BZIP2_PKG $BZIP2_SRC && +download $BASH_PKG $BASH_URL && +unpack zxf $BASH_PKG $BASH_SRC && +download_coreutils && +download $E2FSPROGS_PKG $E2FSPROGS_URL && +unpack zxf $E2FSPROGS_PKG $E2FSPROGS_SRC && +download $PKGCONFIGLITE_PKG $PKGCONFIGLITE_URL && +unpack zxf $PKGCONFIGLITE_PKG $PKGCONFIGLITE_SRC && +download $LIBUUID_PKG $LIBUUID_URL && +unpack zxf $LIBUUID_PKG $LIBUUID_SRC && +download $UTIL_LINUX_PKG $UTIL_LINUX_URL && +unpack zxf $UTIL_LINUX_PKG $UTIL_LINUX_SRC && + +download_grub && + +download $SHADOW_PKG $SHADOW_URL && +unpack Jxf $SHADOW_PKG $SHADOW_SRC && + +download $GMP_PKG $GMP_URL && +unpack jxf $GMP_PKG $GMP_SRC && + +download $MPFR_PKG $MPFR_URL && +unpack jxf $MPFR_PKG $MPFR_SRC && + +download $MPC_PKG $MPC_URL && +unpack zxf $MPC_PKG $MPC_SRC && + +download_libxcrypt && + +download_ncurses && + +download_vim && + +download_gpg_error && +download_gcrypt && +download_dmidecode && +download_findutils && +download_parted && + +download_make && +download_grep && +download_gawk && + +download_sed && +download_dash && +download_libpciaccess && +download_gnumach && +download_mig && +download_hurd && +download_glibc && +download_libacpica && +download_rumpkernel && +echo "Download complete." diff --git a/files/SETUP b/files/SETUP new file mode 100644 index 0000000..2fc10a3 --- /dev/null +++ b/files/SETUP @@ -0,0 +1,50 @@ +#!/bin/bash +# Setup critical hurd translators + +PATH=/bin:/sbin:/hurd + +# BOOT_DEV="$1" +# if [ ! "$BOOT_DEV" ]; then +# echo "No device to install a boot loader was specified." +# echo "Here are some possible devices to use:" +# /bin/devprobe sd0 hd0 sd1 hd1 +# echo -n "Boot device? [none] " +# read BOOT_DEV +# fi +# +# if [ "$BOOT_DEV" ]; then +# if /bin/devprobe -s "$BOOT_DEV"; then true; else +# echo 2>&1 "$0: $BOOT_DEV: No such device known"; exit 1 +# fi +# fi + +set -v + +# Make sure the filesystem is writable +fsysopts / --writable + +# Set up standard passive translators +/bin/settrans -c /servers/socket/local /hurd/pflocal +/bin/settrans -c /servers/crash /hurd/crash +/bin/settrans -c /servers/password /hurd/password +/bin/settrans -c /servers/acpi /hurd/acpi +/bin/settrans -c /servers/bus/pci /hurd/pci-arbiter + +# Setup crucial devices +cd /dev +rm -f console +/bin/bash /sbin/MAKEDEV console std hd0 hd0s1 sd0 rumpdisk wd0 wd0s1 tty1 tty2 tty3 tty4 tty5 tty6 +set +v + +# if test "$BOOT_DEV" && /bin/sh ./MAKEDEV "$BOOT_DEV"; then +# echo -n "Install grub as main boot record on $BOOT_DEV? [y] " +# read yn +# case "$yn" in +# "" | "[yY]*") +# /bin/sh /INSTALL-GRUB-MBR /dev/$BOOT_DEV;; +# esac +# fi + +rm -f /SETUP +sync +reboot diff --git a/files/boot/grub.cfg b/files/boot/grub.cfg new file mode 100644 index 0000000..25db24f --- /dev/null +++ b/files/boot/grub.cfg @@ -0,0 +1,31 @@ +insmod part_msdos +insmod ext2 +set root='hd0,msdos1' +set menu_color_normal=cyan/blue +set menu_color_highlight=white/black +set timeout=1 + +menuentry 'GNU' { + set root='hd0,msdos1' + echo 'Loading GNU Mach' + multiboot /boot/gnumach.gz root=part:1:device:wd0 noide + insmod part_msdos + insmod ext2 + set root='hd0,msdos1' + echo 'Loading the Hurd ...' + module /hurd/pci-arbiter.static pci-arbiter \ + --host-priv-port='${host-port}' --device-master-port='${device-port}' \ + --next-task='${acpi-task}' \ + '$(pci-task=task-create)' '$(task-resume)' + module /hurd/acpi.static acpi \ + --next-task='${disk-task}' \ + '$(acpi-task=task-create)' + module /hurd/rumpdisk.static rumpdisk \ + --next-task='${fs-task}' \ + '$(disk-task=task-create)' + module /hurd/ext2fs.static ext2fs \ + --multiboot-command-line='${kernel-command-line}' \ + --exec-server-task='${exec-task}' -T typed '${root}' \ + '$(fs-task=task-create)' + module /lib/ld.so exec /hurd/exec '$(exec-task=task-create)' +} diff --git a/files/boot/grub.initrd.cfg b/files/boot/grub.initrd.cfg new file mode 100644 index 0000000..41325bf --- /dev/null +++ b/files/boot/grub.initrd.cfg @@ -0,0 +1,19 @@ +insmod part_msdos +insmod ext2 +set root='hd0,msdos1' +set menu_color_normal=cyan/blue +set menu_color_highlight=white/black +set timeout=20 + +menuentry 'Hurd' { + set root='hd0,msdos1' + echo 'Loading GNU Mach' + multiboot /boot/gnumach console=com0 + echo 'Loading the Hurd initrd...' + module /boot/initrd.ext2 initrd.ext2 '$(ramdisk-create)' + echo 'Loading ext2fs.static' + module /sbin/ext2fs.static ext2fs --multiboot-command-line='${kernel-command-line}' --readonly --host-priv-port='${host-port}' --device-master-port='${device-port}' --exec-server-task='${exec-task}' --kernel-task='${kernel-task}' -T device rd0 '$(fs-task=task-create)' '$(prompt-task-resume)' + echo 'Loading exec' + module /lib/ld.so.1 ld.so.1 /hurd/exec --device-master-port='${device-port}' '$(exec-task=task-create)' + boot +} diff --git a/files/etc/fstab b/files/etc/fstab new file mode 100644 index 0000000..a1df882 --- /dev/null +++ b/files/etc/fstab @@ -0,0 +1 @@ +/dev/wd0s1 / ext2 defaults 0 1 diff --git a/files/etc/group b/files/etc/group new file mode 100644 index 0000000..fcfc2a1 --- /dev/null +++ b/files/etc/group @@ -0,0 +1,2 @@ +root:x:0: +daemon:x:1: diff --git a/files/etc/hostname b/files/etc/hostname new file mode 100644 index 0000000..16b8348 --- /dev/null +++ b/files/etc/hostname @@ -0,0 +1 @@ +hurd diff --git a/files/etc/mtab b/files/etc/mtab new file mode 100644 index 0000000..4140ff7 --- /dev/null +++ b/files/etc/mtab @@ -0,0 +1,4 @@ +/dev/wd0s1 / ext2fs writable,no-inherit-dir-group,store-type=typed 0 0 +none /run /hurd/tmpfs writable,no-suid,no-exec,no-inherit-dir-group,no-sync,size=187152K 0 0 +none /run/lock /hurd/tmpfs writable,no-suid,no-exec,no-inherit-dir-group,no-sync,size=5M 0 0 +none /run/shm /hurd/tmpfs writable,no-suid,no-exec,no-inherit-dir-group,no-sync,size=415520K 0 0 diff --git a/files/etc/passwd b/files/etc/passwd new file mode 100644 index 0000000..5e5956e --- /dev/null +++ b/files/etc/passwd @@ -0,0 +1 @@ +root::0:0:root:/root:/bin/bash diff --git a/files/etc/resolv.conf b/files/etc/resolv.conf new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/files/etc/resolv.conf diff --git a/files/etc/shadow b/files/etc/shadow new file mode 100644 index 0000000..6081749 --- /dev/null +++ b/files/etc/shadow @@ -0,0 +1 @@ +root:*:0:0:99999:7::: diff --git a/files/rc b/files/rc new file mode 100755 index 0000000..0339eaf --- /dev/null +++ b/files/rc @@ -0,0 +1,133 @@ +#!/bin/bash + +PATH=/bin:/sbin:/hurd + +# Set up swap space. This will complain if no default pager is functioning. +swapon -a + +# Check filesystems. +if [ -r /fastboot ] +then + # ... or don't. + rm -f /fastboot + echo Fast boot ... skipping disk checks +elif [ $1x = autobootx ] +then + echo Automatic boot in progress... + date + + /sbin/fsck -a + + case $? in + # Successful completion + 0) + ;; + # Filesystem modified (but ok now) + 1) + ;; + # Filesystem modified, filesystem should be restarted + # Ideally we would only restart the filesystem + 2 | 3) + /sbin/reboot + ;; + # Fsck couldn't fix it. + 4 | 5 | 8 | 9) + echo "Automatic boot failed... help!" + exit 1 + ;; + # Signal that really interrupted something + 20 | 130 | 131) + echo "Boot interrupted" + exit 1 + ;; + # Special `let fsck finish' interruption (SIGQUIT) + 12) + echo "Boot interrupted (filesystem checks complete)" + exit 1 + ;; + # Oh dear. + *) + echo "Unknown error during fsck (exit status $?)" + exit 1 + ;; + esac +fi + +fsysopts / --writable +echo -n cleaning up left over files... +rm -f /etc/nologin +rm -f /var/lock/LCK.* +if test -d /tmp; then + + # Forcibly remove all translators in the directory. + # It is then safe to attempt to remove files and descend directories. + # All parameters must begin with "./". + function remove_translators() { + local f + for f; do + settrans -pagfS "$f" + if [ -L "$f" ] || [ ! -d "$f" ]; then + rm "$f" + else + remove_translators "$f"/* "$f"/.[!.] "$f"/.??* + rmdir "$f" + fi + done + } + + (cd /tmp + shopt -s nullglob + for f in * .[!.] .??*; do + case "$f" in + 'lost+found'|'quotas') ;; + *) remove_translators "./$f" + esac + done) + + unset -f remove_translators # because it relies on nullglob + +fi +if test -d /var/run; then + (cd /var/run && { rm -rf -- *; cp /dev/null utmp; chmod 644 utmp; }) +fi +echo done + +# This file must exist for e2fsck to work. XXX +touch /var/run/mtab + +#echo -n restoring pty permissions... +#chmod 666 /dev/tty[pqrs]* +#echo done + +#echo -n updating /etc/motd... +#echo GNU\'s Not Unix Version `uname --release` > /tmp/newmotd +#egrep -v 'GNU|Version' /etc/motd >> /tmp/newmotd +#mv /tmp/newmotd /etc/motd +#echo done + +chmod 664 /etc/motd + +echo -n starting daemons: + +if [ -x "/sbin/syslogd" ]; then + /sbin/syslogd && echo -n ' syslogd' +fi +if [ -x "/sbin/inetd" ]; then + /sbin/inetd && echo -n ' inetd' +fi + +if test -x /sbin/sendmail -a -r /etc/sendmail.cf; then + /sbin/sendmail -bd -q30m && echo -n ' sendmail' +fi + +echo . + +echo -n starting translators: + +if [ ! -e /proc/cmdline ]; then + settrans -ac /proc /hurd/procfs --compatible && echo -n ' procfs' +fi + +echo . + +date diff --git a/files/runsystem b/files/runsystem new file mode 100755 index 0000000..98d7f42 --- /dev/null +++ b/files/runsystem @@ -0,0 +1,137 @@ +#!/bin/bash +# +# This program is run by /hurd/init at boot time after the essential +# servers are up. It does some initialization of its own and then +# execs /hurd/init or any other roughly SysV init-compatible program +# to bring up the "userland" parts of a normal system. +# + + +### +### Where to find programs, etc. +### + +PATH=/bin:/sbin:/hurd +export PATH + +umask 022 + +# If we lose badly, try to exec each of these in turn. +fallback_shells='/bin/bash /bin/dash /bin/sh /bin/csh /bin/ash /bin/shd' + +# Shell used for normal single-user startup. +SHELL=/bin/bash + +# The init program to call. +# +# Can be overridden using init=something in the kernel command line. +init=/hurd/init + +### + + +# If we get a SIGLOST, attempt to reopen the console in case +# our console ports were revoked. This lets us print messages. +function reopen_console () +{ + exec 1>/dev/console 2>&1 || exit 3 +} +trap 'reopen_console' SIGLOST + + +# Call this when we are losing badly enough that we want to punt normal +# startup entirely. We exec a single-user shell, so we will not come back +# here. The only way to get to multi-user from that shell will be +# explicitly exec this script or something like that. +function singleuser() +{ + test $# -eq 0 || echo "$0: $*" + for try in ${fallback_shells}; do + SHELL=${try} + exec ${SHELL} + done + exit 127 +} + +# Print a newline. +echo +echo "Starting the HURD..." + +# See whether pflocal is set up already, and do so if not (install case) +# +# Normally this should be the case, but we better make sure since +# without the pflocal server, pipe(2) does not work. +if ! test -e /servers/socket/1 ; then + # The root filesystem should be read-only at this point. + if fsysopts / --update --writable ; then + settrans -c /servers/socket/1 /hurd/pflocal + else + singleuser "Failed to create /servers/socket/1." + fi +fi + +if [ -x "/SETUP" ]; then + echo "This is the first execution of the system." + echo "I'm going to setup everything and then reboot. Please wait..." + sleep 2 + ./SETUP + exit 0 +fi + +# We expect to be started by console-run, which gives us no arguments and +# puts FALLBACK_CONSOLE=file-name in the environment if our console is +# other than a normal /dev/console. + +if [ "${FALLBACK_CONSOLE+set}" = set ]; then + singleuser "Running on fallback console ${FALLBACK_CONSOLE}" +fi + + +### +### Normal startup procedures +### + +# Parse the multiboot command line. We only pay attention to -s and -f. +# The first argument is the kernel file name; skip that. +shift +flags= +single= +while [ $# -gt 0 ]; do + arg="$1" + shift + case "$arg" in + --*) ;; + init=*) + eval "${arg}" + ;; + *=*) ;; + -*) + flags="${flags}${arg#-}" + ;; + 'single') + single="-s" + ;; + 'fastboot'|'emergency') + ;; + esac +done + +# Check boot flags. +case "$flags" in +*s*) + single="-s" # force single-user + ;; +esac + +# Start the default pager. It will bail if there is already one running. +# TODO: we crash if we start it, investigate to understand what is happening. +# /hurd/mach-defpager + +# This is necessary to make stat / return the correct device ids. +# Work around a race condition (probably in the root translator). +for i in `seq 1 100000` ; do : ; done # XXX + +fsysopts / --update --readonly + +# Finally, start the actual init. +exec ${init} ${single} -a diff --git a/files/runsystem.hurd b/files/runsystem.hurd new file mode 100644 index 0000000..60f9e72 --- /dev/null +++ b/files/runsystem.hurd @@ -0,0 +1,155 @@ +#!/bin/bash +# +# This program is run by /hurd/init at boot time after the essential +# servers are up, and is responsible for running the "userland" parts of a +# normal system. This includes running the single-user shell as well as a +# multi-user system. This program is expected never to exit. +# + + +### +### Where to find programs, etc. +### + +PATH=/bin:/sbin:/hurd +export PATH + +umask 022 + +# If we lose badly, try to exec each of these in turn. +fallback_shells='/bin/sh /bin/bash /bin/dash /bin/csh /bin/ash /bin/shd' + +# Shell used for normal single-user startup. +SHELL=/bin/bash + +# Programs that do multi-user startup. +RUNCOM=/libexec/rc +RUNTTYS=/libexec/runttys +# Signals that we should pass down to runttys. +runttys_sigs='TERM INT HUP TSTP' + +### + + +# If we get a SIGLOST, attempt to reopen the console in case +# our console ports were revoked. This lets us print messages. +function reopen_console () +{ + exec 1>/dev/console 2>&1 || exit 3 +} +trap 'reopen_console' SIGLOST + + +# Call this when we are losing badly enough that we want to punt normal +# startup entirely. We exec a single-user shell, so we will not come back +# here. The only way to get to multi-user from that shell will be +# explicitly exec this script or something like that. +function singleuser () +{ + test $# -eq 0 || echo "$0: $*" + for try in ${fallback_shells}; do + SHELL=${try} + exec ${SHELL} + done + exit 127 +} + + +# See whether pflocal is set up already, and do so if not (install case) +# +# Normally this should be the case, but we better make sure since +# without the pflocal server, pipe(2) does not work. +if ! test -e /servers/socket/1 ; then + # The root filesystem should be read-only at this point. + if fsysopts / --update --writable ; then + settrans -c /servers/socket/1 /hurd/pflocal + else + singleuser "Failed to create /servers/socket/1." + fi +fi + +# We expect to be started by console-run, which gives us no arguments and +# puts FALLBACK_CONSOLE=file-name in the environment if our console is +# other than a normal /dev/console. + +if [ "${FALLBACK_CONSOLE+set}" = set ]; then + singleuser "Running on fallback console ${FALLBACK_CONSOLE}" +fi + + +### +### Normal startup procedures +### + +# Parse the multiboot command line. We only pay attention to -s and -f. +# The first argument is the kernel file name; skip that. +shift +flags= +while [ $# -gt 0 ]; do + arg="$1" + shift + case "$arg" in + --*) ;; + *=*) ;; + -*) + flags="${flags}${arg#-}" + ;; + 'single'|'emergency') # Linux compat + flags="${flags}s" + ;; + 'fastboot') + flags="${flags}f" + ;; + esac +done + +# Check boot flags. +case "$flags" in +*s*) + rc=false # force single-user + ;; +*f*) + rc="${RUNCOM}" # fastboot + ;; +*) + rc="${RUNCOM} autoboot" # multi-user default + ;; +esac + +# Large infinite loop. If this script ever exits, init considers that +# a serious bogosity and punts to a fallback single-user shell. +# We handle here the normal transitions between single-user and multi-user. +while : ; do + + # Run the rc script. As long as it exits nonzero, punt to single-user. + # After the single-user shell exits, we will start over attempting to + # run rc; but later invocations strip the `autoboot' argument. + until $rc; do + rc=${RUNCOM} + + # Run single-user shell and repeat as long as it dies with a signal. + until ${SHELL} || test $? -lt 128; do + : + done + done + + # Now we are officially ready for normal multi-user operation. + + # Trap certain signals and send them on to runttys. For this to work, we + # must run it asynchronously and wait for it with the `wait' built-in. + runttys_pid=0 + for sig in $runttys_sigs; do + trap "kill -$sig \${runttys_pid}" $sig + done + + # This program reads /etc/ttys and starts the programs it says to. + ${RUNTTYS} & + runttys_pid=$! + + # Wait for runttys to die, meanwhile handling trapped signals. + wait + + # Go back to the top of the infinite loop, as if booting single-user. + rc=false + +done diff --git a/files/runsystem.initrd b/files/runsystem.initrd new file mode 100755 index 0000000..be3ccfc --- /dev/null +++ b/files/runsystem.initrd @@ -0,0 +1,10 @@ +#!/bin/sh +# runsystem for initrd. + +settrans -ac /dev/mach-console /hurd/streamio console +exec <>/dev/mach-console >&0 2>&0 +export PATH=/bin:/sbin +echo Hello from /bin/sh! +uname -a +settrans -ac /proc /hurd/procfs --stat-mode=444 +exec /bin/sh -i diff --git a/package-versions.sh b/package-versions.sh new file mode 100644 index 0000000..d72110f --- /dev/null +++ b/package-versions.sh @@ -0,0 +1,38 @@ +# Package versions. +BINUTILS_VERSION=2.41 +GCC_VERSION=13.2.0 +FLEX_VERSION=2.6.4 +ZLIB_VERSION=1.3.1 +BZIP2_VERSION=1.0.8 +BASH_VERSION=5.2.21 +COREUTILS_VERSION=9.4 +# e2fsprogs 1.45.4 is failing due to something with sys/mount.h in configure +E2FSPROGS_VERSION=1.44.1 +PKGCONFIGLITE_VERSION=0.28-1 +LIBUUID_VERSION=1.0.3 +UTIL_LINUX_MAJOR_VERSION=2.39 +# 2.39.2 fails because libmount/src/hooks.c is being compiled without proper support. +UTIL_LINUX_VERSION=2.39 +GRUB_VERSION=2.06 +SHADOW_VERSION=4.14.2 +SED_VERSION=4.9 +GMP_VERSION=6.3.0 +MPFR_VERSION=4.2.1 +MPC_VERSION=1.3.1 +NCURSES_VERSION=6.4 +# 8.1: checking what tgetent() returns for an unknown terminal... configure: error: failed to compile test program. +VIM_BASE_VERSION=90 +VIM_VERSION=9.0 +GPG_ERROR_VERSION=1.47 +GCRYPT_VERSION=1.10.3 +MAKE_VERSION=4.4 +GREP_VERSION=3.11 +GAWK_VERSION=5.3.0 +DASH_VERSION=0.5.12 +LIBPCIACCESS_VERSION=0.17 +LIBXCRYPT_VERSION=4.4.36 +PARTED_VERSION=3.5 +DMIDECODE_VERSION=3.5 +FINDUTILS_VERSION=4.9.0 +# Mach, Hurd and Glibc are all taken from the Git repository. + diff --git a/patches/dash/dash-path-max.patch b/patches/dash/dash-path-max.patch new file mode 100644 index 0000000..bc6924d --- /dev/null +++ b/patches/dash/dash-path-max.patch @@ -0,0 +1,12 @@ +diff -Naur dash-0.5.12/src/expand.c cross-hurd/src/dash-0.5.12/src/expand.c +--- dash-0.5.12.old/src/expand.c 2022-12-11 01:29:21.000000000 -0500 ++++ dash-0.5.12/src/expand.c 2023-05-25 00:26:17.332804650 -0400 +@@ -84,6 +84,8 @@ + #define RMESCAPE_GROW 0x8 /* Grow strings instead of stalloc */ + #define RMESCAPE_HEAP 0x10 /* Malloc strings instead of stalloc */ + ++#define PATH_MAX 4096 ++ + /* Add CTLESC when necessary. */ + #define QUOTES_ESC (EXP_FULL | EXP_CASE) + diff --git a/patches/gcc/hurd-amd64.diff b/patches/gcc/hurd-amd64.diff new file mode 100644 index 0000000..0899c3d --- /dev/null +++ b/patches/gcc/hurd-amd64.diff @@ -0,0 +1,127 @@ +commit 5707e9db9c398d311defc80c5b7822c9a07ead60 +Author: Samuel Thibault <samuel.thibault@gnu.org> +Date: Sat May 6 13:50:36 2023 +0200 + + hurd: Add multilib paths for gnu-x86_64 + + We need the multilib paths in gcc to find e.g. glibc crt files on + Debian. This is essentially based on t-linux64 version. + + gcc/ChangeLog: + + * config/i386/t-gnu64: New file. + * config.gcc [x86_64-*-gnu*]: Add i386/t-gnu64 to + tmake_file. + +commit c768917402d4cba69a92c737e56e177f5b8ab0df +Author: Samuel Thibault <samuel.thibault@gnu.org> +Date: Sat May 6 13:55:44 2023 +0200 + + hurd: Ad default-pie and static-pie support + + This fixes the Hurd spec in the default-pie case, and adds static-pie + support. + + gcc/ChangeLog: + + * config/i386/gnu.h: Use PIE_SPEC, add static-pie case. + * config/i386/gnu64.h: Use PIE_SPEC, add static-pie case. + +diff --git a/gcc/config.gcc b/gcc/config.gcc +index 3000379cafc..e62849c1230 100644 +--- a/gcc/config.gcc ++++ b/gcc/config.gcc +@@ -5973,6 +5973,9 @@ case ${target} in + visium-*-*) + target_cpu_default2="TARGET_CPU_$with_cpu" + ;; ++ x86_64-*-gnu*) ++ tmake_file="$tmake_file i386/t-gnu64" ++ ;; + esac + + t= +diff --git a/src/gcc/config/i386/t-gnu64 b/src/gcc/config/i386/t-gnu64 +new file mode 100644 +index 00000000000..23ee6823d65 +--- /dev/null ++++ b/gcc/config/i386/t-gnu64 +@@ -0,0 +1,38 @@ ++# Copyright (C) 2002-2023 Free Software Foundation, Inc. ++# ++# This file is part of GCC. ++# ++# GCC 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, or (at your option) ++# any later version. ++# ++# GCC 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 GCC; see the file COPYING3. If not see ++# <http://www.gnu.org/licenses/>. ++ ++# On Debian, Ubuntu and other derivative distributions, the 32bit libraries ++# are found in /lib32 and /usr/lib32, /lib64 and /usr/lib64 are symlinks to ++# /lib and /usr/lib, while other distributions install libraries into /lib64 ++# and /usr/lib64. The LSB does not enforce the use of /lib64 and /usr/lib64, ++# it doesn't tell anything about the 32bit libraries on those systems. Set ++# MULTILIB_OSDIRNAMES according to what is found on the target. ++ ++# To support i386, x86-64 and x32 libraries, the directory structrue ++# should be: ++# ++# /lib has i386 libraries. ++# /lib64 has x86-64 libraries. ++# /libx32 has x32 libraries. ++# ++comma=, ++MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG)) ++MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS))) ++MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu) ++MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-gnu) ++MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32) + + +diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h +index 8dc6d9ee4e3..e776144f96c 100644 +--- a/gcc/config/i386/gnu.h ++++ b/gcc/config/i386/gnu.h +@@ -27,12 +27,12 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>. + #undef STARTFILE_SPEC + #if defined HAVE_LD_PIE + #define STARTFILE_SPEC \ +- "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}} \ +- crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" ++ "%{!shared: %{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;" PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \ ++ crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC ":crtbeginS.o%s;:crtbegin.o%s}" + #else + #define STARTFILE_SPEC \ + "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \ +- crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" ++ crti.o%s %{static:crtbeginT.o%s;shared:crtbeginS.o%s;:crtbegin.o%s}" + #endif + + #ifdef TARGET_LIBC_PROVIDES_SSP +diff --git a/gcc/config/i386/gnu64.h b/gcc/config/i386/gnu64.h +index a411f0e802a..332372fa067 100644 +--- a/gcc/config/i386/gnu64.h ++++ b/gcc/config/i386/gnu64.h +@@ -31,10 +31,10 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>. + #undef STARTFILE_SPEC + #if defined HAVE_LD_PIE + #define STARTFILE_SPEC \ +- "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}} \ +- crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" ++ "%{!shared: %{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;" PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \ ++ crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC ":crtbeginS.o%s;:crtbegin.o%s}" + #else + #define STARTFILE_SPEC \ + "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \ +- crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" ++ crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC ":crtbeginS.o%s;:crtbegin.o%s}" + #endif diff --git a/patches/gcc/hurd-multiarch.diff b/patches/gcc/hurd-multiarch.diff new file mode 100644 index 0000000..82271f0 --- /dev/null +++ b/patches/gcc/hurd-multiarch.diff @@ -0,0 +1,16 @@ +--- a/gcc/config/i386/t-gnu64 2023-05-06 22:43:39.395795420 +0200 ++++ b/gcc/config/i386/t-gnu64 2023-05-06 22:43:39.395795420 +0200 +@@ -36,3 +36,13 @@ + MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu) + MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-gnu) + MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32) ++ ++ifneq (,$(findstring x86_64,$(target))) ++ ifneq (,$(findstring biarchx32.h,$(tm_include_list))) ++ MULTIARCH_DIRNAME = $(call if_multiarch,x86_64-gnux32) ++ else ++ MULTIARCH_DIRNAME = $(call if_multiarch,x86_64-gnu) ++ endif ++else ++ MULTIARCH_DIRNAME = $(call if_multiarch,i386-gnu) ++endif diff --git a/patches/gcc/hurd-multilib-multiarch.diff b/patches/gcc/hurd-multilib-multiarch.diff new file mode 100644 index 0000000..8173450 --- /dev/null +++ b/patches/gcc/hurd-multilib-multiarch.diff @@ -0,0 +1,23 @@ +--- a/gcc/config/i386/t-gnu64 2023-05-06 22:43:39.395795420 +0200 ++++ b/gcc/config/i386/t-gnu64 2023-05-06 22:43:39.395795420 +0200 +@@ -33,9 +33,19 @@ + comma=, + MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG)) + MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS))) ++ifneq (,$(findstring gnux32,$(target))) + MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu) +-MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-gnu) ++MULTILIB_OSDIRNAMES+= m32=../lib32$(call if_multiarch,:i386-gnu) ++MULTILIB_OSDIRNAMES+= mx32=../lib$(call if_multiarch,:x86_64-gnux32) ++else ifneq (,$(findstring x86_64,$(target))) ++MULTILIB_OSDIRNAMES = m64=../lib$(call if_multiarch,:x86_64-gnu) ++MULTILIB_OSDIRNAMES+= m32=../lib32$(call if_multiarch,:i386-gnu) + MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32) ++else ++MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-gnu) ++MULTILIB_OSDIRNAMES+= m32=../lib$(call if_multiarch,:i386-gnu) ++MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-gnux32) ++endif + + ifneq (,$(findstring x86_64,$(target))) + ifneq (,$(findstring biarchx32.h,$(tm_include_list))) diff --git a/patches/glibc/local-clock_gettime_MONOTONIC.diff b/patches/glibc/local-clock_gettime_MONOTONIC.diff new file mode 100644 index 0000000..3207a94 --- /dev/null +++ b/patches/glibc/local-clock_gettime_MONOTONIC.diff @@ -0,0 +1,133 @@ +Use the realtime clock for the monotonic clock. This is of course not a proper +implementation (which is being done in Mach), but will permit to fix at least +the iceweasel stack. + +vlc however doesn't build when _POSIX_CLOCK_SELECTION is enabled but +_POSIX_TIMERS is not, and they refuse to fix that (see #765578), so disable the +former. + +--- + sysdeps/mach/hurd/bits/posix_opt.h | 2 +- + sysdeps/unix/clock_gettime.c | 1 + + 2 files changed, 2 insertions(+), 1 deletion(-) +Index: glibc-2.27/sysdeps/mach/clock_gettime.c +=================================================================== +--- glibc-2.27.orig/sysdeps/mach/clock_gettime.c ++++ glibc-2.27/sysdeps/mach/clock_gettime.c +@@ -31,6 +31,10 @@ __clock_gettime (clockid_t clock_id, str + switch (clock_id) { + + case CLOCK_REALTIME: ++ case CLOCK_MONOTONIC: ++ case CLOCK_MONOTONIC_RAW: ++ case CLOCK_REALTIME_COARSE: ++ case CLOCK_MONOTONIC_COARSE: + { + /* __host_get_time can only fail if passed an invalid host_t. + __mach_host_self could theoretically fail (producing an +Index: glibc-2.27/rt/timer_create.c +=================================================================== +--- glibc-2.27.orig/rt/timer_create.c ++++ glibc-2.27/rt/timer_create.c +@@ -48,7 +48,7 @@ timer_create (clockid_t clock_id, struct + return -1; + } + +- if (clock_id != CLOCK_REALTIME) ++ if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC && clock_id != CLOCK_MONOTONIC_RAW && clock_id != CLOCK_REALTIME_COARSE && clock_id != CLOCK_MONOTONIC_COARSE) + { + __set_errno (EINVAL); + return -1; +Index: glibc-2.27/sysdeps/mach/hurd/bits/posix_opt.h +=================================================================== +--- glibc-2.27.orig/sysdeps/mach/hurd/bits/posix_opt.h ++++ glibc-2.27/sysdeps/mach/hurd/bits/posix_opt.h +@@ -163,10 +163,10 @@ + #define _POSIX_THREAD_PROCESS_SHARED -1 + + /* The monotonic clock might be available. */ +-#define _POSIX_MONOTONIC_CLOCK 0 ++#define _POSIX_MONOTONIC_CLOCK 200809L + +-/* The clock selection interfaces are available. */ +-#define _POSIX_CLOCK_SELECTION 200809L ++/* The clock selection interfaces are not really available yet. */ ++#define _POSIX_CLOCK_SELECTION -1 + + /* Advisory information interfaces could be available in future. */ + #define _POSIX_ADVISORY_INFO 0 +Index: glibc-upstream/sysdeps/posix/clock_getres.c +=================================================================== +--- glibc-upstream.orig/sysdeps/posix/clock_getres.c ++++ glibc-upstream/sysdeps/posix/clock_getres.c +@@ -52,6 +52,10 @@ __clock_getres (clockid_t clock_id, stru + switch (clock_id) + { + case CLOCK_REALTIME: ++ case CLOCK_MONOTONIC: ++ case CLOCK_MONOTONIC_RAW: ++ case CLOCK_REALTIME_COARSE: ++ case CLOCK_MONOTONIC_COARSE: + retval = realtime_getres (res); + break; + +--- ./sysdeps/mach/clock_nanosleep.c.original 2020-07-21 00:31:35.226113142 +0200 ++++ ./sysdeps/mach/clock_nanosleep.c 2020-07-21 00:31:49.026185761 +0200 +@@ -62,7 +62,7 @@ + __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, + struct timespec *rem) + { +- if (clock_id != CLOCK_REALTIME ++ if ((clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC && clock_id != CLOCK_MONOTONIC_RAW && clock_id != CLOCK_REALTIME_COARSE && clock_id != CLOCK_MONOTONIC_COARSE) + || !valid_nanoseconds (req->tv_nsec) + || (flags != 0 && flags != TIMER_ABSTIME)) + return EINVAL; +Index: glibc-2.32/hurd/hurdlock.c +=================================================================== +--- glibc-2.32.orig/hurd/hurdlock.c ++++ glibc-2.32/hurd/hurdlock.c +@@ -47,7 +47,7 @@ int + __lll_abstimed_wait (void *ptr, int val, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -59,7 +59,7 @@ int + __lll_abstimed_wait_intr (void *ptr, int val, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -79,7 +79,7 @@ int + __lll_abstimed_xwait (void *ptr, int lo, int hi, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + int mlsec = compute_reltime (tsp, clk); +@@ -91,7 +91,7 @@ int + __lll_abstimed_lock (void *ptr, + const struct timespec *tsp, int flags, int clk) + { +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + if (__lll_trylock (ptr) == 0) +@@ -177,7 +177,7 @@ __lll_robust_abstimed_lock (void *ptr, + int wait_time = 25; + unsigned int val; + +- if (clk != CLOCK_REALTIME) ++ if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC) + return EINVAL; + + while (1) diff --git a/patches/glibc/local-static_pthread_setcancelstate.diff b/patches/glibc/local-static_pthread_setcancelstate.diff new file mode 100644 index 0000000..18684a0 --- /dev/null +++ b/patches/glibc/local-static_pthread_setcancelstate.diff @@ -0,0 +1,87 @@ +since the move of libpthread functions to libc, glibc dropped the use +of __libc_ptf_call. But htl hasn't made the move yet, so we have to use +__libc_ptf_call there for now. + +Index: glibc-2.36/misc/error.c +=================================================================== +--- glibc-2.36.orig/misc/error.c ++++ glibc-2.36/misc/error.c +@@ -240,7 +240,8 @@ __error_internal (int status, int errnum + /* We do not want this call to be cut short by a thread + cancellation. Therefore disable cancellation for now. */ + int state = PTHREAD_CANCEL_ENABLE; +- __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); ++ __libc_ptf_call (__pthread_setcancelstate, ++ (PTHREAD_CANCEL_DISABLE, &state), 0); + #endif + + flush_stdout (); +@@ -262,7 +263,7 @@ __error_internal (int status, int errnum + + #ifdef _LIBC + _IO_funlockfile (stderr); +- __pthread_setcancelstate (state, NULL); ++ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); + #endif + } + +@@ -306,7 +307,9 @@ __error_at_line_internal (int status, in + /* We do not want this call to be cut short by a thread + cancellation. Therefore disable cancellation for now. */ + int state = PTHREAD_CANCEL_ENABLE; +- __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); ++ __libc_ptf_call (__pthread_setcancelstate, ++ (PTHREAD_CANCEL_DISABLE, &state), ++ 0); + #endif + + flush_stdout (); +@@ -336,7 +339,7 @@ __error_at_line_internal (int status, in + + #ifdef _LIBC + _IO_funlockfile (stderr); +- __pthread_setcancelstate (state, NULL); ++ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); + #endif + } + +Index: glibc-2.36/libio/iopopen.c +=================================================================== +--- glibc-2.36.orig/libio/iopopen.c ++++ glibc-2.36/libio/iopopen.c +@@ -281,9 +281,10 @@ _IO_new_proc_close (FILE *fp) + do + { + int state; +- __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); ++ __libc_ptf_call (__pthread_setcancelstate, ++ (PTHREAD_CANCEL_DISABLE, &state), 0); + wait_pid = __waitpid (((_IO_proc_file *) fp)->pid, &wstatus, 0); +- __pthread_setcancelstate (state, NULL); ++ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); + } + while (wait_pid == -1 && errno == EINTR); + if (wait_pid == -1) +Index: glibc-2.36/stdlib/fmtmsg.c +=================================================================== +--- glibc-2.36.orig/stdlib/fmtmsg.c ++++ glibc-2.36/stdlib/fmtmsg.c +@@ -124,7 +124,8 @@ fmtmsg (long int classification, const c + /* We do not want this call to be cut short by a thread + cancellation. Therefore disable cancellation for now. */ + int state = PTHREAD_CANCEL_ENABLE; +- __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); ++ __libc_ptf_call (__pthread_setcancelstate, ++ (PTHREAD_CANCEL_DISABLE, &state), 0); + + __libc_lock_lock (lock); + +@@ -193,7 +194,7 @@ fmtmsg (long int classification, const c + + __libc_lock_unlock (lock); + +- __pthread_setcancelstate (state, NULL); ++ __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); + + return result; + } diff --git a/patches/glibc/submitted-AF_LINK.diff b/patches/glibc/submitted-AF_LINK.diff new file mode 100644 index 0000000..e95a987 --- /dev/null +++ b/patches/glibc/submitted-AF_LINK.diff @@ -0,0 +1,29 @@ +Hurd: comment PF_LINK/AF_LINK defines + +Comment out the PF_LINK and AF_LINK defines, since they are usually associated +with struct sockaddr_dl, which is not available on Hurd. + +2012-06-22 Pino Toscano <toscano.pino@tiscali.it> + + * sysdeps/mach/hurd/bits/socket.h (PF_LINK): Comment out. + (AF_LINK): Likewise. +--- a/sysdeps/mach/hurd/bits/socket.h ++++ b/sysdeps/mach/hurd/bits/socket.h +@@ -97,7 +97,7 @@ enum __socket_type + #define PF_HYLINK 15 /* NSC Hyperchannel protocol. */ + #define PF_APPLETALK 16 /* Don't use this. */ + #define PF_ROUTE 17 /* Internal Routing Protocol. */ +-#define PF_LINK 18 /* Link layer interface. */ ++/* #define PF_LINK 18 Link layer interface. */ + #define PF_XTP 19 /* eXpress Transfer Protocol (no AF). */ + #define PF_COIP 20 /* Connection-oriented IP, aka ST II. */ + #define PF_CNT 21 /* Computer Network Technology. */ +@@ -130,7 +130,7 @@ enum __socket_type + #define AF_HYLINK PF_HYLINK + #define AF_APPLETALK PF_APPLETALK + #define AF_ROUTE PF_ROUTE +-#define AF_LINK PF_LINK ++/* #define AF_LINK PF_LINK */ + #ifdef __USE_MISC + # define pseudo_AF_XTP PF_XTP + #endif diff --git a/patches/glibc/tg-bits_atomic.h_multiple_threads.diff b/patches/glibc/tg-bits_atomic.h_multiple_threads.diff new file mode 100644 index 0000000..bc52b29 --- /dev/null +++ b/patches/glibc/tg-bits_atomic.h_multiple_threads.diff @@ -0,0 +1,279 @@ +From: Thomas Schwinge <thomas@schwinge.name> +Subject: [PATCH] bits_atomic.h_multiple_threads + +TODO. bits/atomic.h for GNU Hurd. + +Source: Debian, eglibc-2.10/debian/patches/hurd-i386/local-atomic-no-multiple_threads.diff, r3536. +Author: Samuel Thibault <samuel.thibault@ens-lyon.org> + +We always at least start the sigthread anyway. For now, let's avoid forking +the file (which would mean having to maintain it). + +Need to override sysdeps/i386/i486/bits/atomic.h to remove Linuxisms. + +--- + sysdeps/i386/atomic-machine.h | 107 +++++++++++++++--------------------------- + 1 file changed, 37 insertions(+), 70 deletions(-) + +Index: glibc-2.23/sysdeps/x86/atomic-machine.h +=================================================================== +--- glibc-2.23.orig/sysdeps/x86/atomic-machine.h ++++ glibc-2.23/sysdeps/x86/atomic-machine.h +@@ -66,35 +66,26 @@ typedef uintmax_t uatomic_max_t; + + #define __arch_c_compare_and_exchange_val_8_acq(mem, newval, oldval) \ + ({ __typeof (*mem) ret; \ +- __asm __volatile ("cmpl $0, %%" SEG_REG ":%P5\n\t" \ +- "je 0f\n\t" \ +- "lock\n" \ +- "0:\tcmpxchgb %b2, %1" \ ++ __asm __volatile ("lock\n" \ ++ "\tcmpxchgb %b2, %1" \ + : "=a" (ret), "=m" (*mem) \ +- : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval)); \ + ret; }) + + #define __arch_c_compare_and_exchange_val_16_acq(mem, newval, oldval) \ + ({ __typeof (*mem) ret; \ +- __asm __volatile ("cmpl $0, %%" SEG_REG ":%P5\n\t" \ +- "je 0f\n\t" \ +- "lock\n" \ +- "0:\tcmpxchgw %w2, %1" \ ++ __asm __volatile ("lock\n" \ ++ "\tcmpxchgw %w2, %1" \ + : "=a" (ret), "=m" (*mem) \ +- : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval)); \ + ret; }) + + #define __arch_c_compare_and_exchange_val_32_acq(mem, newval, oldval) \ + ({ __typeof (*mem) ret; \ +- __asm __volatile ("cmpl $0, %%" SEG_REG ":%P5\n\t" \ +- "je 0f\n\t" \ +- "lock\n" \ +- "0:\tcmpxchgl %2, %1" \ ++ __asm __volatile ("lock\n" \ ++ "\tcmpxchgl %2, %1" \ + : "=a" (ret), "=m" (*mem) \ +- : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : BR_CONSTRAINT (newval), "m" (*mem), "0" (oldval)); \ + ret; }) + + #ifdef __x86_64__ +@@ -210,24 +195,20 @@ typedef uintmax_t uatomic_max_t; + if (sizeof (*mem) == 1) \ + __asm __volatile (lock "xaddb %b0, %1" \ + : "=q" (__result), "=m" (*mem) \ +- : "0" (__addval), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "0" (__addval), "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "xaddw %w0, %1" \ + : "=r" (__result), "=m" (*mem) \ +- : "0" (__addval), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "0" (__addval), "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "xaddl %0, %1" \ + : "=r" (__result), "=m" (*mem) \ +- : "0" (__addval), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "0" (__addval), "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "xaddq %q0, %1" \ + : "=r" (__result), "=m" (*mem) \ + : "0" ((int64_t) cast_to_integer (__addval)), \ +- "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ "m" (*mem)); \ + else \ + __result = do_exchange_and_add_val_64_acq (pfx, (mem), __addval); \ + __result; }) +@@ -238,7 +220,7 @@ typedef uintmax_t uatomic_max_t; + __sync_fetch_and_add (mem, value) + + #define __arch_exchange_and_add_cprefix \ +- "cmpl $0, %%" SEG_REG ":%P4\n\tje 0f\n\tlock\n0:\t" ++ "lock\n\t" + + #define catomic_exchange_and_add(mem, value) \ + __arch_exchange_and_add_body (__arch_exchange_and_add_cprefix, __arch_c, \ +@@ -254,24 +236,20 @@ typedef uintmax_t uatomic_max_t; + else if (sizeof (*mem) == 1) \ + __asm __volatile (lock "addb %b1, %0" \ + : "=m" (*mem) \ +- : IBR_CONSTRAINT (value), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : IBR_CONSTRAINT (value), "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "addw %w1, %0" \ + : "=m" (*mem) \ +- : "ir" (value), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (value), "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "addl %1, %0" \ + : "=m" (*mem) \ +- : "ir" (value), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (value), "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "addq %q1, %0" \ + : "=m" (*mem) \ + : "ir" ((int64_t) cast_to_integer (value)), \ +- "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ "m" (*mem)); \ + else \ + do_add_val_64_acq (apfx, (mem), (value)); \ + } while (0) +@@ -283,7 +262,7 @@ typedef uintmax_t uatomic_max_t; + __arch_add_body (LOCK_PREFIX, atomic, __arch, mem, value) + + #define __arch_add_cprefix \ +- "cmpl $0, %%" SEG_REG ":%P3\n\tje 0f\n\tlock\n0:\t" ++ "lock\n\t" + + #define catomic_add(mem, value) \ + __arch_add_body (__arch_add_cprefix, atomic, __arch_c, mem, value) +@@ -332,23 +311,19 @@ typedef uintmax_t uatomic_max_t; + if (sizeof (*mem) == 1) \ + __asm __volatile (lock "incb %b0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "incw %w0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "incl %0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "incq %q0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else \ + do_add_val_64_acq (pfx, mem, 1); \ + } while (0) +@@ -359,7 +335,7 @@ typedef uintmax_t uatomic_max_t; + #define atomic_increment(mem) __arch_increment_body (LOCK_PREFIX, __arch, mem) + + #define __arch_increment_cprefix \ +- "cmpl $0, %%" SEG_REG ":%P2\n\tje 0f\n\tlock\n0:\t" ++ "lock\n\t" + + #define catomic_increment(mem) \ + __arch_increment_body (__arch_increment_cprefix, __arch_c, mem) +@@ -389,23 +365,19 @@ typedef uintmax_t uatomic_max_t; + if (sizeof (*mem) == 1) \ + __asm __volatile (lock "decb %b0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "decw %w0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "decl %0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "decq %q0" \ + : "=m" (*mem) \ +- : "m" (*mem), \ ++ : "m" (*mem)); \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ + else \ + do_add_val_64_acq (pfx, mem, -1); \ + } while (0) +@@ -416,7 +389,7 @@ typedef uintmax_t uatomic_max_t; + #define atomic_decrement(mem) __arch_decrement_body (LOCK_PREFIX, __arch, mem) + + #define __arch_decrement_cprefix \ +- "cmpl $0, %%" SEG_REG ":%P2\n\tje 0f\n\tlock\n0:\t" ++ "lock\n\t" + + #define catomic_decrement(mem) \ + __arch_decrement_body (__arch_decrement_cprefix, __arch_c, mem) +@@ -487,29 +460,25 @@ typedef uintmax_t uatomic_max_t; + if (sizeof (*mem) == 1) \ + __asm __volatile (lock "andb %b1, %0" \ + : "=m" (*mem) \ +- : IBR_CONSTRAINT (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : IBR_CONSTRAINT (mask), "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "andw %w1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "andl %1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "andq %q1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else \ + __atomic_link_error (); \ + } while (0) + + #define __arch_cprefix \ +- "cmpl $0, %%" SEG_REG ":%P3\n\tje 0f\n\tlock\n0:\t" ++ "lock\n\t" + + #define atomic_and(mem, mask) __arch_and_body (LOCK_PREFIX, mem, mask) + +@@ -516,23 +486,19 @@ typedef uintmax_t uatomic_max_t; + if (sizeof (*mem) == 1) \ + __asm __volatile (lock "orb %b1, %0" \ + : "=m" (*mem) \ +- : IBR_CONSTRAINT (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : IBR_CONSTRAINT (mask), "m" (*mem)); \ + else if (sizeof (*mem) == 2) \ + __asm __volatile (lock "orw %w1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else if (sizeof (*mem) == 4) \ + __asm __volatile (lock "orl %1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else if (__HAVE_64B_ATOMICS) \ + __asm __volatile (lock "orq %q1, %0" \ + : "=m" (*mem) \ +- : "ir" (mask), "m" (*mem), \ +- "i" (offsetof (tcbhead_t, multiple_threads))); \ ++ : "ir" (mask), "m" (*mem)); \ + else \ + __atomic_link_error (); \ + } while (0) diff --git a/patches/glibc/tg-mach-hurd-link.diff b/patches/glibc/tg-mach-hurd-link.diff new file mode 100644 index 0000000..6ee98ed --- /dev/null +++ b/patches/glibc/tg-mach-hurd-link.diff @@ -0,0 +1,32 @@ +From: Samuel Thibault <samuel.thibault@ens-lyon.org> +Subject: [PATCH] Add -lmachuser -lhurduser to libc.so on GNU/Hurd. + +http://lists.gnu.org/archive/html/bug-hurd/2011-03/msg00112.html + +2011-03-29 Samuel Thibault <samuel.thibault@ens-lyon.org> + + * Makerules ($(inst_libdir)/libc.so): Add -lmachuser -lhurduser to + libc.so on GNU/Hurd. + +It's still unclear what we want to aim for. + +--- + Makerules | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/Makerules b/Makerules +index 53eabfaba8..b0f5e1b3a0 100644 +--- a/Makerules ++++ b/Makerules +@@ -1066,6 +1066,9 @@ $(inst_libdir)/libc.so: $(common-objpfx)format.lds \ + '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\ + ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \ + ) > $@.new ++ifeq ($(patsubst gnu%,,$(config-os)),) ++ echo 'INPUT ( AS_NEEDED ( -lmachuser -lhurduser ) )' >> $@.new ++endif + mv -f $@.new $@ + + endif +-- +tg: (7bb5f8a836..) t/mach-hurd-link (depends on: baseline) diff --git a/patches/glibc/tg-unlockpt-chroot.diff b/patches/glibc/tg-unlockpt-chroot.diff new file mode 100644 index 0000000..a8f0d17 --- /dev/null +++ b/patches/glibc/tg-unlockpt-chroot.diff @@ -0,0 +1,22 @@ +From: Samuel Thibault <samuel.thibault@ens-lyon.org> +Subject: [PATCH] Fix pty path in chroot + +when e.g. using a chroot, the pty path is not so short. + +--- + sysdeps/unix/bsd/unlockpt.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Index: eglibc-2.16/sysdeps/unix/bsd/unlockpt.c +=================================================================== +--- eglibc-2.16.orig/sysdeps/unix/bsd/unlockpt.c 2012-07-23 00:23:14.000000000 +0200 ++++ eglibc-2.16/sysdeps/unix/bsd/unlockpt.c 2012-07-23 00:24:55.000000000 +0200 +@@ -27,7 +27,7 @@ + int + unlockpt (int fd) + { +- char buf[sizeof (_PATH_TTY) + 2]; ++ char buf[1024]; /* XXX */ + + /* BSD doesn't have a lock, but it does have `revoke'. */ + if (__ptsname_r (fd, buf, sizeof (buf))) diff --git a/patches/glibc/unsubmitted-getaux_at_secure.diff b/patches/glibc/unsubmitted-getaux_at_secure.diff new file mode 100644 index 0000000..0ecd5f7 --- /dev/null +++ b/patches/glibc/unsubmitted-getaux_at_secure.diff @@ -0,0 +1,30 @@ +FIXME: sysdeps/mach/hurd/i386/init-first.c should instead pass an auxv +to __libc_start_main + +Index: glibc-2.33/misc/getauxval.c +=================================================================== +--- glibc-2.33.orig/misc/getauxval.c ++++ glibc-2.33/misc/getauxval.c +@@ -19,6 +19,7 @@ + #include <errno.h> + #include <ldsodefs.h> + #include <stdbool.h> ++#include <unistd.h> + + bool + __getauxval2 (unsigned long int type, unsigned long int *result) +@@ -27,6 +28,14 @@ __getauxval2 (unsigned long int type, un + ElfW(auxv_t) *p; + #endif + ++#ifdef AT_SECURE ++ if (type == AT_SECURE) ++ { ++ *result = __libc_enable_secure; ++ return true; ++ } ++#endif ++ + if (type == AT_HWCAP) + { + *result = GLRO(dl_hwcap); diff --git a/patches/glibc/unsubmitted-prof-eintr.diff b/patches/glibc/unsubmitted-prof-eintr.diff new file mode 100644 index 0000000..1b0808c --- /dev/null +++ b/patches/glibc/unsubmitted-prof-eintr.diff @@ -0,0 +1,21 @@ +When profiling ext2fs, the shutdown stops all RPC, which thus interrupts this +open, and we have to retry here. + +TODO: is open really supposed to expose such EINTR? Should the generic gmon +loop around EINTR (since there might be signals happening indeed) + +diff --git a/gmon/gmon.c b/gmon/gmon.c +index 6439ed1caa..507ad0c9fc 100644 +--- a/gmon/gmon.c ++++ b/gmon/gmon.c +@@ -390,8 +390,10 @@ write_gmon (void) + + if (fd == -1) + { ++ do + fd = __open_nocancel ("gmon.out", O_CREAT | O_TRUNC | O_WRONLY + | O_NOFOLLOW | O_CLOEXEC, 0666); ++ while (fd < 0 && errno == EINTR); + if (fd < 0) + { + char buf[300]; diff --git a/patches/gnumach/50_initrd.patch b/patches/gnumach/50_initrd.patch new file mode 100644 index 0000000..4b0226e --- /dev/null +++ b/patches/gnumach/50_initrd.patch @@ -0,0 +1,326 @@ +Jérémie Koenig <jk@jk.fr.eu.org> +Add ramdisk support for d-i. + +Index: gnumach/Makefrag.am +=================================================================== +--- gnumach.orig/Makefrag.am ++++ gnumach/Makefrag.am +@@ -324,6 +324,8 @@ libkernel_a_SOURCES += \ + device/net_io.c \ + device/net_io.h \ + device/param.h \ ++ device/ramdisk.c \ ++ device/ramdisk.h \ + device/subrs.c \ + device/subrs.h \ + device/tty.h +Index: gnumach/i386/i386at/conf.c +=================================================================== +--- gnumach.orig/i386/i386at/conf.c ++++ gnumach/i386/i386at/conf.c +@@ -31,6 +31,7 @@ + #include <device/conf.h> + #include <kern/mach_clock.h> + #include <i386at/model_dep.h> ++#include <device/ramdisk.h> + + #define timename "time" + +@@ -138,6 +139,8 @@ struct dev_ops dev_name_list[] = + nodev_info }, + #endif /* MACH_HYP */ + ++ RAMDISK_DEV_OPS, ++ + #ifdef MACH_KMSG + { kmsgname, kmsgopen, kmsgclose, kmsgread, + nulldev_write, kmsggetstat, nulldev_setstat, nomap, +Index: gnumach/kern/boot_script.c +=================================================================== +--- gnumach.orig/kern/boot_script.c ++++ gnumach/kern/boot_script.c +@@ -90,12 +90,20 @@ prompt_resume_task (struct cmd *cmd, con + return boot_script_prompt_task_resume (cmd); + } + ++/* Create an initial ramdisk */ ++static int ++ramdisk_create (struct cmd *cmd, long *val) ++{ ++ return boot_script_ramdisk_create (cmd, (char **) val); ++} ++ + /* List of builtin symbols. */ + static struct sym builtin_symbols[] = + { + { "task-create", VAL_FUNC, (long) create_task, VAL_TASK, 0 }, + { "task-resume", VAL_FUNC, (long) resume_task, VAL_NONE, 1 }, + { "prompt-task-resume", VAL_FUNC, (long) prompt_resume_task, VAL_NONE, 1 }, ++ { "ramdisk-create", VAL_FUNC, (long) ramdisk_create, VAL_STR, 0 }, + }; + #define NUM_BUILTIN (sizeof (builtin_symbols) / sizeof (builtin_symbols[0])) + +Index: gnumach/kern/bootstrap.c +=================================================================== +--- gnumach.orig/kern/bootstrap.c ++++ gnumach/kern/bootstrap.c +@@ -51,6 +51,7 @@ + #include <vm/vm_user.h> + #include <vm/pmap.h> + #include <device/device_port.h> ++#include <device/ramdisk.h> + + #if MACH_KDB + #include <machine/db_machdep.h> +@@ -849,6 +850,23 @@ boot_script_free (void *ptr, unsigned in + } + + int ++boot_script_ramdisk_create (struct cmd *cmd, char **name) ++{ ++ struct multiboot_module *mod = cmd->hook; ++ vm_size_t size = mod->mod_end - mod->mod_start; ++ kern_return_t rc; ++ int no; ++ ++ rc = ramdisk_create (size, (void *) phystokv (mod->mod_start), &no); ++ if (rc != KERN_SUCCESS) ++ return BOOT_SCRIPT_MACH_ERROR; ++ ++ *name = boot_script_malloc (RAMDISK_NAMESZ); ++ sprintf(*name, RAMDISK_NAME "%d", no); ++ return 0; ++} ++ ++int + boot_script_task_create (struct cmd *cmd) + { + kern_return_t rc = task_create_kernel(TASK_NULL, FALSE, &cmd->task); +Index: gnumach/device/ramdisk.c +=================================================================== +--- /dev/null ++++ gnumach/device/ramdisk.c +@@ -0,0 +1,160 @@ ++#include <mach/vm_param.h> ++#include <machine/vm_param.h> ++#include <vm/vm_kern.h> ++#include <vm/vm_user.h> ++#include <device/device_types.h> ++#include <device/ds_routines.h> ++#include <device/conf.h> ++#include <device/ramdisk.h> ++#include <kern/printf.h> ++#include <string.h> ++ ++static struct ramdisk { ++ void *data; ++ vm_size_t size; ++} ramdisk[RAMDISK_MAX]; ++ ++static int ramdisk_num = 0; ++ ++/* Initial ramdisks are created from the boot scripts */ ++int ramdisk_create(vm_size_t size, const void *initdata, int *out_no) ++{ ++ struct ramdisk *rd = &ramdisk[ramdisk_num]; ++ int err; ++ ++ if(ramdisk_num >= RAMDISK_MAX) ++ return -1; ++ ++ /* allocate the memory */ ++ rd->size = round_page(size); ++ err = kmem_alloc(kernel_map, (vm_offset_t *) &rd->data, rd->size); ++ if(err != KERN_SUCCESS) ++ return err; ++ ++ /* initialize */ ++ if(initdata) ++ memcpy(rd->data, initdata, rd->size); ++ else ++ memset(rd->data, 0, rd->size); ++ ++ /* report */ ++ if(out_no) *out_no = ramdisk_num; ++ printf("%s%d: %lu bytes @%p\n", RAMDISK_NAME, ramdisk_num, ++ (unsigned long) rd->size, rd->data); ++ ++ ramdisk_num++; ++ return KERN_SUCCESS; ++} ++ ++/* On d_open() we just check whether the ramdisk exists */ ++int ramdisk_open(dev_t dev, int mode, io_req_t ior) ++{ ++ return (dev < ramdisk_num) ? D_SUCCESS : D_NO_SUCH_DEVICE; ++} ++ ++/* d_getstat() is used to query the device characteristics */ ++int ramdisk_getstat(dev_t dev, dev_flavor_t flavor, dev_status_t status, ++ mach_msg_type_number_t *status_count) ++{ ++ switch(flavor) { ++ case DEV_GET_SIZE: ++ status[DEV_GET_SIZE_DEVICE_SIZE] = ramdisk[dev].size; ++ status[DEV_GET_SIZE_RECORD_SIZE] = RAMDISK_BLOCKSZ; ++ *status_count = DEV_GET_SIZE_COUNT; ++ return D_SUCCESS; ++ ++ case DEV_GET_RECORDS: ++ status[DEV_GET_RECORDS_DEVICE_RECORDS] ++ = ramdisk[dev].size / RAMDISK_BLOCKSZ; ++ status[DEV_GET_RECORDS_RECORD_SIZE] = RAMDISK_BLOCKSZ; ++ *status_count = DEV_GET_RECORDS_COUNT; ++ return D_SUCCESS; ++ } ++ return D_INVALID_OPERATION; ++} ++ ++/* TODO: implement freeramdisk with setstat() ? */ ++ ++/* Check the given io request and compute a pointer to the ramdisk data and the ++ * amount to be handled. */ ++static int ramdisk_ioreq(int dev, io_req_t ior, void **data, int *amt) ++{ ++ vm_offset_t ofs = ior->io_recnum * RAMDISK_BLOCKSZ; ++ if(ofs >= ramdisk[dev].size) ++ return D_INVALID_RECNUM; ++ ++ *data = (char*) ramdisk[dev].data + ofs; ++ *amt = ior->io_count; ++ if(ofs + *amt > ramdisk[dev].size) ++ *amt = ramdisk[dev].size - ofs; ++ ++ return KERN_SUCCESS; ++} ++ ++/* Copy data from a vm_map_copy by mapping it temporarily. */ ++static int mem_map_cpy(void *dst, vm_map_copy_t src, int amt) ++{ ++ vm_offset_t srcaddr; ++ int err; ++ ++ err = vm_map_copyout(device_io_map, &srcaddr, src); ++ if (err != KERN_SUCCESS) ++ return err; ++ ++ memcpy(dst, (void *) srcaddr, amt); ++ vm_deallocate(device_io_map, srcaddr, amt); ++ return KERN_SUCCESS; ++} ++ ++int ramdisk_read(dev_t dev, io_req_t ior) ++{ ++ void *data; ++ int amt, err; ++ ++ err = ramdisk_ioreq(dev, ior, &data, &amt); ++ if(err != KERN_SUCCESS) ++ return err; ++ ++ err = device_read_alloc (ior, ior->io_count); ++ if (err != KERN_SUCCESS) ++ return err; ++ ++ memcpy(ior->io_data, data, amt); ++ ior->io_residual = ior->io_count - amt; ++ ++ return D_SUCCESS; ++} ++ ++int ramdisk_write(dev_t dev, io_req_t ior) ++{ ++ void *data; ++ int amt, err; ++ ++ err = ramdisk_ioreq(dev, ior, &data, &amt); ++ if(err != KERN_SUCCESS) ++ return err; ++ ++ if (!(ior->io_op & IO_INBAND)) { ++ /* Out-of-band data is transmitted as a vm_map_copy */ ++ err = mem_map_cpy(data, (vm_map_copy_t) ior->io_data, amt); ++ if(err != KERN_SUCCESS) ++ return err; ++ } else { ++ /* In-band data can be accessed directly */ ++ memcpy(data, ior->io_data, amt); ++ } ++ ++ ior->io_residual = ior->io_count - amt; ++ return D_SUCCESS; ++} ++ ++vm_offset_t ramdisk_mmap(dev_t dev, vm_offset_t off, vm_prot_t prot) ++{ ++ if(dev >= ramdisk_num) ++ return -1; ++ if(off >= ramdisk[dev].size) ++ return -1; ++ ++ return pmap_phys_to_frame(kvtophys((vm_offset_t) ramdisk[dev].data + off)); ++} ++ +Index: gnumach/device/ramdisk.h +=================================================================== +--- /dev/null ++++ gnumach/device/ramdisk.h +@@ -0,0 +1,47 @@ ++#ifndef _KERN_RAMDISK_H_ ++#define _KERN_RAMDISK_H_ ++ ++#include <vm/pmap.h> ++#include <device/io_req.h> ++#include <device/conf.h> ++ ++/* Maximum number of ramdisk devices */ ++#define RAMDISK_MAX 4 ++ ++/* The block size used (userspace requires 512) */ ++#define RAMDISK_BLOCKSZ 512 ++ ++/* Name associated to the ramdisk major */ ++#define RAMDISK_NAME "rd" ++#define RAMDISK_NAMESZ (sizeof RAMDISK_NAME + sizeof (int) * 3 + 1) ++ ++/* Create a new ramdisk of the given size. On success, if out_no and/or out_ptr ++ * are not NULL, the device number and pointer to the ramdisk's data are stored ++ * there. Returns D_SUCCESS or D_NO_MEMORY. */ ++int ramdisk_create(vm_size_t size, const void *initdata, int *out_no); ++ ++/* Device operations */ ++int ramdisk_open(dev_t, int, io_req_t); ++int ramdisk_getstat(dev_t, dev_flavor_t, dev_status_t, mach_msg_type_number_t *); ++int ramdisk_read(dev_t, io_req_t); ++int ramdisk_write(dev_t, io_req_t); ++vm_offset_t ramdisk_mmap(dev_t, vm_offset_t, vm_prot_t); ++ ++/* dev_ops initializer to be used from <machine>/conf.c */ ++#define RAMDISK_DEV_OPS { \ ++ .d_name = RAMDISK_NAME, \ ++ .d_open = ramdisk_open, \ ++ .d_close = nulldev_close, \ ++ .d_read = ramdisk_read, \ ++ .d_write = ramdisk_write, \ ++ .d_getstat = ramdisk_getstat, \ ++ .d_setstat = nulldev_setstat, \ ++ .d_mmap = ramdisk_mmap, \ ++ .d_async_in = nodev_async_in, \ ++ .d_reset = nulldev_reset, \ ++ .d_port_death = nulldev_portdeath, \ ++ .d_subdev = 0, \ ++ .d_dev_info = nodev_info, \ ++ } ++ ++#endif +Index: gnumach/kern/bootstrap.h +=================================================================== +--- gnumach.orig/kern/bootstrap.h ++++ gnumach/kern/bootstrap.h +@@ -22,5 +22,6 @@ + #include <kern/boot_script.h> + + void bootstrap_create(void); ++int boot_script_ramdisk_create(struct cmd *cmd, char **name); + + #endif /* _KERN_BOOTSTRAP_H_ */ diff --git a/patches/gnumach/79_dde-debian.patch b/patches/gnumach/79_dde-debian.patch new file mode 100644 index 0000000..b6a0f17 --- /dev/null +++ b/patches/gnumach/79_dde-debian.patch @@ -0,0 +1,274 @@ +This contains a compatibility layer for netdde and rump still using the experimental irq/alloc_contig support. It is the output of + +git diff master master-user_level_drivers-debian + +(master was 6054cda4de2341b9a77ec4421411725f3684006b and +master-user_level_drivers-debian was 19283fdffa782b2e485ef39e0de1574006ec4a1a at +the time) + +When dropping this, break netdde (<< 0.0.20200330-5), +hurd-libs0.3 (<< hurd_1:0.9.git20200718-1+b1) + +--- + Makefrag.am | 1 + device/ds_routines.c | 64 +++++++++++++++++++++++++++++++++++++++- + device/intr.c | 16 ++++++---- + device/intr.h | 3 + + include/mach/experimental.defs | 38 +++++++++++++++++++++++ + linux/dev/drivers/block/genhd.c | 4 +- + vm/vm_user.c | 14 ++++++++ + 7 files changed, 130 insertions(+), 10 deletions(-) + +--- a/Makefrag.am ++++ b/Makefrag.am +@@ -362,7 +362,6 @@ include_device_HEADERS = \ + include/device/disk_status.h \ + include/device/input.h \ + include/device/net_status.h \ +- include/device/notify.defs \ + include/device/notify.h \ + include/device/tape_status.h \ + include/device/tty_status.h +--- a/device/ds_routines.c ++++ b/device/ds_routines.c +@@ -354,7 +354,7 @@ ds_device_intr_register (device_t dev, i + if (! name_equal(mdev->dev_ops->d_name, 3, "irq")) + return D_INVALID_OPERATION; + +- user_intr_t *e = insert_intr_entry (&irqtab, id, receive_port); ++ user_intr_t *e = insert_intr_entry (&irqtab, id, receive_port, 0); + if (!e) + return D_NO_MEMORY; + +@@ -371,6 +371,52 @@ ds_device_intr_register (device_t dev, i + #endif /* MACH_XEN */ + } + ++static ipc_port_t intr_receive_ports[16]; ++io_return_t ++experimental_device_intr_register (ipc_port_t master_port, int line, ++ int id, int flags, ipc_port_t receive_port) ++{ ++#ifdef MACH_XEN ++ return D_INVALID_OPERATION; ++#else /* MACH_XEN */ ++ io_return_t ret; ++ /* Open must be called on the master device port. */ ++ if (master_port != master_device_port) ++ return D_INVALID_OPERATION; ++ ++ /* XXX: move to arch-specific */ ++ if (line < 0 || line >= 16) ++ return D_INVALID_OPERATION; ++ ++ if (flags != 0x04000000) ++ return D_INVALID_OPERATION; ++ ++ user_intr_t *user_intr = insert_intr_entry (&irqtab, line, receive_port, 1); ++ if (!user_intr) ++ return D_NO_MEMORY; ++ ++ // TODO The original port should be replaced ++ // when the same device driver calls it again, ++ // in order to handle the case that the device driver crashes and restarts. ++ ret = install_user_intr_handler (&irqtab, line, 0, user_intr); ++ ++ if (ret == 0) ++ { ++ /* If the port is installed successfully, increase its reference by 1. ++ * Thus, the port won't be destroyed after its task is terminated. */ ++ ip_reference (receive_port); ++ ++ intr_receive_ports[line] = receive_port; ++ /* For now netdde calls device_intr_enable once after registration. Assume ++ * it does so for now. When we move to IRQ acknowledgment convention we will ++ * change this. */ ++ __disable_irq (line); ++ } ++ ++ return ret; ++#endif /* MACH_XEN */ ++} ++ + kern_return_t + ds_device_intr_ack (device_t dev, ipc_port_t receive_port) + { +@@ -399,6 +445,22 @@ ds_device_intr_ack (device_t dev, ipc_po + #endif /* MACH_XEN */ + } + ++kern_return_t ++experimental_device_intr_enable(ipc_port_t master_port, int line, char status) ++{ ++#ifdef MACH_XEN ++ return D_INVALID_OPERATION; ++#else /* MACH_XEN */ ++ if (master_port != master_device_port) ++ return D_INVALID_OPERATION; ++ ++ if (status != 1) ++ return D_INVALID_OPERATION; ++ ++ return irq_acknowledge(intr_receive_ports[line]); ++#endif /* MACH_XEN */ ++} ++ + boolean_t + ds_notify (mach_msg_header_t *msg) + { +--- a/device/intr.c ++++ b/device/intr.c +@@ -25,7 +25,7 @@ + #ifndef MACH_XEN + + queue_head_t main_intr_queue; +-static boolean_t deliver_intr (int id, ipc_port_t dst_port); ++static boolean_t deliver_intr (int id, mach_msg_id_t msgh_id, ipc_port_t dst_port); + + #ifndef LINUX_DEV + #define SA_SHIRQ 0x04000000 +@@ -122,7 +122,7 @@ deliver_user_intr (struct irqdev *dev, i + * This entry exists in the queue until + * the corresponding interrupt port is removed.*/ + user_intr_t * +-insert_intr_entry (struct irqdev *dev, int id, ipc_port_t dst_port) ++insert_intr_entry (struct irqdev *dev, int id, ipc_port_t dst_port, int compat) + { + user_intr_t *e, *new, *ret; + int free = 0; +@@ -146,7 +146,11 @@ insert_intr_entry (struct irqdev *dev, i + new->id = id; + new->dst_port = dst_port; + new->interrupts = 0; +- new->n_unacked = 0; ++ new->compat = compat; ++ if (compat) ++ new->n_unacked = 1; ++ else ++ new->n_unacked = 0; + + queue_enter (dev->intr_queue, new, user_intr_t *, chain); + out: +@@ -268,7 +272,7 @@ intr_thread (void) + irqtab.tot_num_intr--; + + splx (s); +- deliver_intr (id, dst_port); ++ deliver_intr (id, e->compat ? 424242 : DEVICE_INTR_NOTIFY, dst_port); + s = splhigh (); + } + } +@@ -307,7 +311,7 @@ intr_thread (void) + } + + static boolean_t +-deliver_intr (int id, ipc_port_t dst_port) ++deliver_intr (int id, mach_msg_id_t msgh_id, ipc_port_t dst_port) + { + ipc_kmsg_t kmsg; + device_intr_notification_t *n; +@@ -331,7 +335,7 @@ deliver_intr (int id, ipc_port_t dst_por + m->msgh_seqno = DEVICE_NOTIFY_MSGH_SEQNO; + m->msgh_local_port = MACH_PORT_NULL; + m->msgh_remote_port = MACH_PORT_NULL; +- m->msgh_id = DEVICE_INTR_NOTIFY; ++ m->msgh_id = msgh_id; + + t->msgt_name = MACH_MSG_TYPE_INTEGER_32; + t->msgt_size = 32; +--- a/device/intr.h ++++ b/device/intr.h +@@ -36,6 +36,7 @@ typedef struct { + int n_unacked; /* Number of times irqs were disabled for this */ + ipc_port_t dst_port; /* Notification port */ + int id; /* Mapping to machine dependent irq_t array elem */ ++ int compat; + } user_intr_t; + + struct irqdev { +@@ -52,7 +53,7 @@ struct irqdev { + extern queue_head_t main_intr_queue; + extern int install_user_intr_handler (struct irqdev *dev, int id, unsigned long flags, user_intr_t *e); + extern int deliver_user_intr (struct irqdev *dev, int id, user_intr_t *e); +-extern user_intr_t *insert_intr_entry (struct irqdev *dev, int id, ipc_port_t receive_port); ++extern user_intr_t *insert_intr_entry (struct irqdev *dev, int id, ipc_port_t receive_port, int compat); + + void intr_thread (void); + kern_return_t irq_acknowledge (ipc_port_t receive_port); +--- a/include/mach/experimental.defs ++++ b/include/mach/experimental.defs +@@ -13,3 +13,41 @@ subsystem + serverprefix experimental_; + + /* This is free for experimenting RPCs, with no backward compatibility guarantees. */ ++ ++type notify_port_t = MACH_MSG_TYPE_MOVE_SEND_ONCE ++ ctype: mach_port_t; ++ ++skip; /*simpleroutine mach_intr_notify( ++ notify : notify_port_t; ++ name : int);*/ ++ ++routine device_intr_register( ++ master_port : mach_port_t; ++ in line : int; ++ in id : int; ++ in flags : int; ++ in receive_port : mach_port_send_t ++ ); ++ ++/* ++ * enable/disable the specified line. ++ */ ++/* XXX: Naming a function taht can disable something "xxx_enable" is confusing. */ ++/* Is the disable part actually used at all? AIUI, the kernel IRQ handler ++should always disable the line; and the userspace driver only has to ++reenable it, after acknowledging and handling the interrupt... ++*/ ++routine device_intr_enable( ++ master_port : mach_port_t; ++ line : int; ++ status : char); ++ ++/* ++ * This routine is for compatibility with old userland drivers. ++ */ ++routine vm_allocate_contiguous( ++ host_priv : host_priv_t; ++ target_task : vm_task_t; ++ out vaddr : vm_address_t; ++ out paddr : vm_address_t; ++ size : vm_size_t); +--- a/linux/dev/drivers/block/genhd.c ++++ b/linux/dev/drivers/block/genhd.c +@@ -1060,7 +1060,9 @@ void device_setup(void) + scsi_dev_init(); + #endif + #ifdef CONFIG_INET +- net_dev_init(); ++ extern char *kernel_cmdline; ++ if (!strstr(kernel_cmdline, " nonetdev")) ++ net_dev_init(); + #endif + #ifndef MACH + console_map_init(); +--- a/vm/vm_user.c ++++ b/vm/vm_user.c +@@ -688,3 +688,17 @@ kern_return_t vm_allocate_contiguous( + + return KERN_SUCCESS; + } ++ ++kern_return_t experimental_vm_allocate_contiguous(host_priv, map, result_vaddr, result_paddr, size) ++ host_t host_priv; ++ vm_map_t map; ++ vm_address_t *result_vaddr; ++ vm_address_t *result_paddr; ++ vm_size_t size; ++{ ++ rpc_phys_addr_t paddr; ++ kern_return_t ret; ++ ret = vm_allocate_contiguous(host_priv, map, result_vaddr, &paddr, size, 0, ~0ULL, 0); ++ *result_paddr = paddr; ++ return ret; ++} diff --git a/patches/grep/gnulib-hurd-x86_64.patch b/patches/grep/gnulib-hurd-x86_64.patch new file mode 100644 index 0000000..c5ffd1f --- /dev/null +++ b/patches/grep/gnulib-hurd-x86_64.patch @@ -0,0 +1,50 @@ +From acb36717d8dd76b5cb755edc53aa5cea7f24db01 Mon Sep 17 00:00:00 2001 +From: Bruno Haible <bruno@clisp.org> +Date: Fri, 12 May 2023 21:28:47 +0200 +Subject: sigsegv: Add tentative support for Hurd/x86_64. + +Reported by Samuel Thibault <samuel.thibault@ens-lyon.org>. + +* lib/sigsegv.c: Update from libsigsegv/src/fault-hurd-i386.h. +--- + ChangeLog | 6 ++++++ + lib/sigsegv.c | 20 +++++++++++++++++--- + 2 files changed, 23 insertions(+), 3 deletions(-) + +diff --git a/lib/sigsegv.c b/lib/sigsegv.c +index 5e943e4..aadba4e 100644 +--- a/lib/sigsegv.c ++++ b/lib/sigsegv.c +@@ -365,12 +365,26 @@ int libsigsegv_version = LIBSIGSEGV_VERSION; + # define SIGSEGV_FAULT_ADDRESS (unsigned long) code + # define SIGSEGV_FAULT_CONTEXT scp + +-# if defined __i386__ ++# if defined __x86_64__ ++/* 64 bit registers */ ++ ++/* scp points to a 'struct sigcontext' (defined in ++ glibc/sysdeps/mach/hurd/x86_64/bits/sigcontext.h). ++ The registers, at the moment the signal occurred, get pushed on the stack ++ through gnumach/x86_64/locore.S:alltraps and then copied into the struct ++ through glibc/sysdeps/mach/hurd/x86/trampoline.c. */ ++/* sc_rsp is unused (not set by gnumach/x86_64/locore.S:alltraps). We need ++ to use sc_ursp. */ ++# define SIGSEGV_FAULT_STACKPOINTER scp->sc_ursp ++ ++# elif defined __i386__ ++/* 32 bit registers */ + + /* scp points to a 'struct sigcontext' (defined in + glibc/sysdeps/mach/hurd/i386/bits/sigcontext.h). +- The registers of this struct get pushed on the stack through +- gnumach/i386/i386/locore.S:trapall. */ ++ The registers, at the moment the signal occurred, get pushed on the stack ++ through gnumach/i386/i386/locore.S:alltraps and then copied into the struct ++ through glibc/sysdeps/mach/hurd/x86/trampoline.c. */ + /* Both sc_esp and sc_uesp appear to have the same value. + It appears more reliable to use sc_uesp because it is labelled as + "old esp, if trapped from user". */ +-- +cgit v1.1 + diff --git a/patches/hurd/link-rump.patch b/patches/hurd/link-rump.patch new file mode 100644 index 0000000..7375edf --- /dev/null +++ b/patches/hurd/link-rump.patch @@ -0,0 +1,13 @@ +diff --git a/configure.ac b/configure.ac +index dd2481b0..6e754a7a 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -239,7 +239,7 @@ AS_IF([test "x$with_rump" != xno], [ + # Save + oldLIBS="$LIBS" + +- LIBS="$oldLIBS -lrump" ++ LIBS="$oldLIBS -lrump -lrumpuser -lrumpvfs -lrumpvfs_fifofs -lrumpnet -lrumpnet_net -lrumpnet_local" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <hurd.h> diff --git a/patches/libgpg-error/hurd-amd64.patch b/patches/libgpg-error/hurd-amd64.patch new file mode 100644 index 0000000..23bf744 --- /dev/null +++ b/patches/libgpg-error/hurd-amd64.patch @@ -0,0 +1,54 @@ +Index: libgpg-error-1.46/src/Makefile.am
+===================================================================
+--- libgpg-error-1.46.orig/src/Makefile.am
++++ libgpg-error-1.46/src/Makefile.am
+@@ -67,6 +67,7 @@ lock_obj_pub = \
+ syscfg/lock-obj-pub.sparc-unknown-linux-gnu.h \
+ syscfg/lock-obj-pub.sparc64-unknown-linux-gnu.h \
+ syscfg/lock-obj-pub.x86_64-apple-darwin.h \
++ syscfg/lock-obj-pub.x86_64-unknown-gnu.h \
+ syscfg/lock-obj-pub.x86_64-unknown-kfreebsd-gnu.h \
+ syscfg/lock-obj-pub.x86_64-unknown-linux-gnu.h \
+ syscfg/lock-obj-pub.x86_64-unknown-linux-gnux32.h \
+Index: libgpg-error-1.46/src/mkheader.c
+===================================================================
+--- libgpg-error-1.46.orig/src/mkheader.c
++++ libgpg-error-1.46/src/mkheader.c
+@@ -108,6 +108,8 @@ canon_host_triplet (const char *triplet,
+ {"x86_64-pc-linux-gnuhardened1", "x86_64-unknown-linux-gnu" },
+ {"x86_64-pc-linux-gnu" },
+
++ {"x86_64-pc-gnu"},
++
+ {"powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-gnu" },
+
+ {"arm-unknown-linux-gnueabihf", "arm-unknown-linux-gnueabi" },
+Index: libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
+===================================================================
+--- /dev/null
++++ libgpg-error-1.46/src/syscfg/lock-obj-pub.x86_64-unknown-gnu.h
+@@ -0,0 +1,24 @@
++## lock-obj-pub.x86_64-pc-gnu.h
++## File created by gen-posix-lock-obj - DO NOT EDIT
++## To be included by mkheader into gpg-error.h
++
++typedef struct
++{
++ long _vers;
++ union {
++ volatile char _priv[32];
++ long _x_align;
++ long *_xp_align;
++ } u;
++} gpgrt_lock_t;
++
++#define GPGRT_LOCK_INITIALIZER {1,{{0,0,0,0,0,0,0,0, \
++ 0,0,0,0,0,0,0,0, \
++ 0,0,0,0,0,0,0,0, \
++ 0,0,0,0,0,0,0,0}}}
++##
++## Local Variables:
++## mode: c
++## buffer-read-only: t
++## End:
++##
diff --git a/patches/shadow/shadow-utmp.patch b/patches/shadow/shadow-utmp.patch new file mode 100644 index 0000000..db5e479 --- /dev/null +++ b/patches/shadow/shadow-utmp.patch @@ -0,0 +1,11 @@ +diff -Naur build-i686/native/shadow-4.14.2.copy/lib/user_busy.c src/shadow-4.14.2/lib/user_busy.c +--- shadow-4.14.2.copy/lib/user_busy.c 2023-11-27 23:37:31.067406127 -0500 ++++ shadow-4.14.2/lib/user_busy.c 2023-11-27 23:37:08.507284180 -0500 +@@ -17,6 +17,7 @@ + #include <dirent.h> + #include <fcntl.h> + #include <unistd.h> ++#include <utmp.h> + #include "defines.h" + #include "prototypes.h" + #ifdef ENABLE_SUBIDS diff --git a/reset.sh b/reset.sh new file mode 100644 index 0000000..f35bf6d --- /dev/null +++ b/reset.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +. ./vars.sh + +if [ "$SYSTEM" = "/" ]; then + exit 1 +fi + +echo "Removing from $SYSTEM..." + +rm -rf build* && +rm -rf output* && +echo "Removing $SYS_ROOT" +sudo rm -f $SYS_ROOT && +echo "Removing $CROSS_TOOLS" +sudo rm -f $CROSS_TOOLS +echo "Removing $SYSTEM" +rm -rf $SYSTEM +rm -f hd.img +for dir in `ls $SOURCE`; do + if [ -d $SOURCE/$dir ]; then + if [ ! -d $SOURCE/$dir/.git ]; then + echo "Removing $SOURCE/$dir" + rm -rf $SOURCE/$dir + fi + fi +done diff --git a/start-qemu-debug.sh b/start-qemu-debug.sh new file mode 100644 index 0000000..c9cc964 --- /dev/null +++ b/start-qemu-debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +qemu-system-x86_64 -s hd.img --enable-kvm -m 4096 -serial stdio diff --git a/test-all.sh b/test-all.sh new file mode 100644 index 0000000..a50d081 --- /dev/null +++ b/test-all.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Runs all known build configurations locally. + +# Full i686 build. +CPU=i686 bash bootstrap.sh +CPU=i686 bash compile.sh + +# Full x86_64 build. +CPU=x86_64 bash bootstrap.sh +CPU=x86_64 bash compile.sh + +# x86_64 Gnumach on 32 bit userland. +CPU=x86_64 USER32=1 bash bootstrap-kernel.sh @@ -0,0 +1,89 @@ +. ./config.sh + +export SCRIPT_DIR=$PWD +export SYSTEM=$PWD/output-$CPU +export CROSS_TOOLS=/cross-tools-$CPU +export SYS_ROOT=/tools-$CPU +export SOURCE=$PWD/src +export BUILD_ROOT=$PWD/build-$CPU +export TARGET=$CPU-gnu +export HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/g")" +export PATH=$CROSS_TOOLS/bin:$PATH + +if [ ! -z "$CCACHE_DIRECTORY" ]; then + export PATH=$CCACHE_DIRECTORY:$PATH +fi + +. ./package-versions.sh + +BINUTILS_SRC=binutils-"$BINUTILS_VERSION" +BINUTILS_PKG="${BINUTILS_SRC}.tar.bz2" +GCC_SRC=gcc-"$GCC_VERSION" +GCC_PKG="$GCC_SRC".tar.gz +GNUMACH_SRC=gnumach +GNUMIG_SRC=mig +HURD_SRC=hurd +GLIBC_SRC=glibc +GLIBC_TAG=master +FLEX_SRC=flex-"$FLEX_VERSION" +FLEX_PKG="$FLEX_SRC".tar.gz +ZLIB_SRC=zlib-"$ZLIB_VERSION" +ZLIB_PKG="$ZLIB_SRC".tar.gz +BZIP2_SRC=bzip2-$BZIP2_VERSION +BZIP2_PKG=$BZIP2_SRC.tar.gz +BASH_SRC=bash-"$BASH_VERSION" +BASH_PKG="$BASH_SRC".tar.gz +COREUTILS_SRC=coreutils-"$COREUTILS_VERSION" +COREUTILS_PKG="$COREUTILS_SRC".tar.xz +E2FSPROGS_SRC=e2fsprogs-"$E2FSPROGS_VERSION" +E2FSPROGS_PKG="$E2FSPROGS_SRC".tar.gz +PKGCONFIGLITE_SRC=pkg-config-lite-"$PKGCONFIGLITE_VERSION" +PKGCONFIGLITE_PKG="$PKGCONFIGLITE_SRC".tar.gz +LIBUUID_SRC=libuuid-"$LIBUUID_VERSION" +LIBUUID_PKG="$LIBUUID_SRC".tar.gz +UTIL_LINUX_SRC=util-linux-"$UTIL_LINUX_VERSION" +UTIL_LINUX_PKG="$UTIL_LINUX_SRC".tar.gz +GRUB_SRC=grub-"$GRUB_VERSION" +GRUB_PKG="$GRUB_SRC".tar.gz +SHADOW_SRC=shadow-"$SHADOW_VERSION" +SHADOW_PKG="$SHADOW_SRC".tar.xz +SED_SRC=sed-"$SED_VERSION" +SED_PKG="$SED_SRC".tar.xz +GMP_SRC=gmp-"$GMP_VERSION" +GMP_PKG="${GMP_SRC}".tar.bz2 +MPFR_SRC=mpfr-"$MPFR_VERSION" +MPFR_PKG="${MPFR_SRC}".tar.bz2 +MPC_SRC=mpc-"$MPC_VERSION" +MPC_PKG="${MPC_SRC}".tar.gz +NCURSES_SRC=ncurses-"$NCURSES_VERSION" +NCURSES_PKG="${NCURSES_SRC}".tar.gz +VIM_SRC=vim-"$VIM_VERSION" +VIM_PKG="$VIM_SRC".tar.bz2 +GPG_ERROR_SRC=libgpg-error-"$GPG_ERROR_VERSION" +GPG_ERROR_PKG=${GPG_ERROR_SRC}.tar.bz2 +GCRYPT_SRC=libgcrypt-"$GCRYPT_VERSION" +GCRYPT_PKG=${GCRYPT_SRC}.tar.bz2 +MAKE_SRC=make-"$MAKE_VERSION" +MAKE_PKG=${MAKE_SRC}.tar.gz +GREP_SRC=grep-"$GREP_VERSION" +GREP_PKG=${GREP_SRC}.tar.xz +GAWK_SRC=gawk-"$GAWK_VERSION" +GAWK_PKG=${GAWK_SRC}.tar.xz +DASH_SRC=dash-$DASH_VERSION +DASH_PKG=$DASH_SRC.tar.gz +LIBPCIACCESS_SRC=libpciaccess-$LIBPCIACCESS_VERSION +LIBPCIACCESS_PKG=$LIBPCIACCESS_SRC.tar.gz +LIBXCRYPT_SRC=libxcrypt-$LIBXCRYPT_VERSION +LIBXCRYPT_PKG=$LIBXCRYPT_SRC.tar.xz +PARTED_SRC=parted-$PARTED_VERSION +PARTED_PKG=$PARTED_SRC.tar.xz +DMIDECODE_SRC=dmidecode-$DMIDECODE_VERSION +DMIDECODE_PKG=$DMIDECODE_SRC.tar.xz +FINDUTILS_SRC=findutils-$FINDUTILS_VERSION +FINDUTILS_PKG=$FINDUTILS_SRC.tar.xz + +print_info () +{ + echo "* $*" +} + |