Skip to content

Commit

Permalink
Toolchain+Ports: Enable threads for gcc
Browse files Browse the repository at this point in the history
This enables POSIX threads for GCC and makes the -pthread
argument available.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Apr 20, 2021
1 parent 7400e3d commit 75d4165
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ jobs:
# *and* as actual output variable, in this order.
message(" set-output name=time::${current_date}")
message("::set-output name=time::${current_date}")
message(" set-output name=libc_headers::${{ hashFiles('Userland/Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}")
message("::set-output name=libc_headers::${{ hashFiles('Userland/Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}")
message(" set-output name=libc_headers::${{ hashFiles('Userland/Libraries/LibC/**/*.h', 'Userland/Libraries/LibPthread/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}")
message("::set-output name=libc_headers::${{ hashFiles('Userland/Libraries/LibC/**/*.h', 'Userland/Libraries/LibPthread/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }}")
- name: Toolchain cache
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/Toolchain/Cache/
# This assumes that *ALL* LibC headers have an impact on the Toolchain.
# This assumes that *ALL* LibC and LibPthread headers have an impact on the Toolchain.
# This is wrong, and causes more Toolchain rebuilds than necessary.
# However, we want to avoid false cache hits at all costs.
key: ${{ runner.os }}-toolchain-i686-${{ steps.stamps.outputs.libc_headers }}
Expand Down
3 changes: 2 additions & 1 deletion Ports/gcc/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
port=gcc
version=10.3.0
useconfigure=true
configopts="--target=${SERENITY_ARCH}-pc-serenity --with-sysroot=/ --with-build-sysroot=${SERENITY_INSTALL_ROOT} --with-newlib --enable-languages=c,c++ --disable-lto --disable-nls --enable-shared --enable-default-pie --enable-host-shared"
configopts="--target=${SERENITY_ARCH}-pc-serenity --with-sysroot=/ --with-build-sysroot=${SERENITY_INSTALL_ROOT} --with-newlib --enable-languages=c,c++ --disable-lto --disable-nls --enable-shared --enable-default-pie --enable-host-shared --enable-threads=posix"
files="https://ftpmirror.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz gcc-${version}.tar.xz
https://ftpmirror.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz.sig gcc-${version}.tar.xz.sig
https://ftpmirror.gnu.org/gnu/gnu-keyring.gpg gnu-keyring.gpg"
configopts="--target=${SERENITY_ARCH}-pc-serenity --with-sysroot=/ --with-build-sysroot=${SERENITY_BUILD_DIR}/Root --with-newlib --enable-languages=c,c++ --disable-lto --disable-nls --enable-shared --enable-default-pie --enable-host-shared --enable-threads=posix"
makeopts="all-gcc all-target-libgcc all-target-libstdc++-v3 -j $(nproc)"
installopts="DESTDIR=${SERENITY_INSTALL_ROOT} install-gcc install-target-libgcc install-target-libstdc++-v3"
depends="binutils"
Expand Down
52 changes: 46 additions & 6 deletions Ports/gcc/patches/gcc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ diff -ruN a/config.sub b/config.sub
# Copyright 1992-2019 Free Software Foundation, Inc.

-timestamp='2019-06-30'
+timestamp='2020-05-16'
+timestamp='2021-04-20'

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -102,7 +102,7 @@ diff -ruN a/gcc/config/arm/serenity-elf.h b/gcc/config/arm/serenity-elf.h
diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
--- a/gcc/config/serenity.h 1970-01-01 02:00:00.000000000 +0200
+++ b/gcc/config/serenity.h 2020-12-12 10:43:35.280270540 +0200
@@ -0,0 +1,41 @@
@@ -0,0 +1,44 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY
+#define TARGET_SERENITY 1
Expand All @@ -114,7 +114,7 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+/* Default arguments you want when running your
+ i686-serenity-gcc/x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+#define LIB_SPEC "%{pthread:-lpthread} -lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
Expand All @@ -134,6 +134,9 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC "-fno-exceptions -ftls-model=initial-exec"
+
+#undef CPP_SPEC
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
+
+/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
Expand All @@ -144,22 +147,59 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff -ruN a/gcc/config/serenity.opt b/gcc/config/serenity.opt
--- a/gcc/config/serenity.opt 1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/config/serenity.opt 2021-04-18 11:59:44.933484216 +0200
@@ -0,0 +1,32 @@
+; SerenityOS options.
+
+; Copyright (C) 2021 Gunnar Beutner <[email protected]>
+;
+; 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:https://www.gnu.org/licenses/>.
+
+; See the GCC internals manual (options.texi) for a description of
+; this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+posix
+Driver
+
+pthread
+Driver
+
+; This comment is to ensure we retain the blank line above.
diff -ruN a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300
+++ b/gcc/config.gcc 2020-12-12 10:43:35.280270540 +0200
@@ -675,6 +675,11 @@
@@ -675,6 +675,12 @@

# Common parts for widely ported systems.
case ${target} in
+*-*-serenity*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ extra_options="${extra_options} serenity.opt"
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1033,6 +1038,15 @@
@@ -1063,6 +1069,15 @@
esac

case ${target} in
Expand Down Expand Up @@ -224,7 +264,7 @@ diff -ruN a/libgcc/config.host b/libgcc/config.host
diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure
--- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300
+++ b/libstdc++-v3/configure 2020-12-12 10:43:35.288270409 +0200
@@ -29846,6 +29846,5986 @@
@@ -29217,6 +29217,5986 @@

# Base decisions on target environment.
case "${host}" in
Expand Down
7 changes: 4 additions & 3 deletions Toolchain/BuildIt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ pushd "$DIR/Build/$ARCH"
buildstep "binutils/install" "$MAKE" install || exit 1
popd

echo "XXX serenity libc and libm headers"
echo "XXX serenity libc, libm and libpthread headers"
mkdir -p "$BUILD"
pushd "$BUILD"
mkdir -p Root/usr/include/
SRC_ROOT=$($REALPATH "$DIR"/..)
FILES=$(find "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM -name '*.h' -print)
FILES=$(find "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM "$SRC_ROOT"/Userland/Libraries/LibPthread -name '*.h' -print)
for header in $FILES; do
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@")
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@" -e "s@$SRC_ROOT/Userland/Libraries/LibPthread@@")
buildstep "system_headers" $INSTALL -D "$header" "Root/usr/include/$target"
done
unset SRC_ROOT
Expand Down Expand Up @@ -289,6 +289,7 @@ pushd "$DIR/Build/$ARCH"
--enable-languages=c,c++ \
--enable-default-pie \
--enable-lto \
--enable-threads=posix \
${TRY_USE_LOCAL_TOOLCHAIN:+"--quiet"} || exit 1

if [ "$STAGE" = "Userland" ]; then
Expand Down
52 changes: 46 additions & 6 deletions Toolchain/Patches/gcc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ diff -ruN a/config.sub b/config.sub
# Copyright 1992-2019 Free Software Foundation, Inc.

-timestamp='2019-06-30'
+timestamp='2020-05-16'
+timestamp='2021-04-20'

# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -102,7 +102,7 @@ diff -ruN a/gcc/config/arm/serenity-elf.h b/gcc/config/arm/serenity-elf.h
diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
--- a/gcc/config/serenity.h 1970-01-01 02:00:00.000000000 +0200
+++ b/gcc/config/serenity.h 2020-12-12 10:43:35.280270540 +0200
@@ -0,0 +1,41 @@
@@ -0,0 +1,44 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY
+#define TARGET_SERENITY 1
Expand All @@ -114,7 +114,7 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+/* Default arguments you want when running your
+ i686-serenity-gcc/x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+#define LIB_SPEC "%{pthread:-lpthread} -lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
Expand All @@ -134,6 +134,9 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC "-fno-exceptions -ftls-model=initial-exec"
+
+#undef CPP_SPEC
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
+
+/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
Expand All @@ -144,22 +147,59 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff -ruN a/gcc/config/serenity.opt b/gcc/config/serenity.opt
--- a/gcc/config/serenity.opt 1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/config/serenity.opt 2021-04-18 11:59:44.933484216 +0200
@@ -0,0 +1,32 @@
+; SerenityOS options.
+
+; Copyright (C) 2021 Gunnar Beutner <[email protected]>
+;
+; 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:https://www.gnu.org/licenses/>.
+
+; See the GCC internals manual (options.texi) for a description of
+; this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+posix
+Driver
+
+pthread
+Driver
+
+; This comment is to ensure we retain the blank line above.
diff -ruN a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300
+++ b/gcc/config.gcc 2020-12-12 10:43:35.280270540 +0200
@@ -675,6 +675,11 @@
@@ -675,6 +675,12 @@

# Common parts for widely ported systems.
case ${target} in
+*-*-serenity*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ extra_options="${extra_options} serenity.opt"
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1033,6 +1038,15 @@
@@ -1063,6 +1069,15 @@
esac

case ${target} in
Expand Down Expand Up @@ -224,7 +264,7 @@ diff -ruN a/libgcc/config.host b/libgcc/config.host
diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure
--- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300
+++ b/libstdc++-v3/configure 2020-12-12 10:43:35.288270409 +0200
@@ -29846,6 +29846,5986 @@
@@ -29217,6 +29217,5986 @@

# Base decisions on target environment.
case "${host}" in
Expand Down

0 comments on commit 75d4165

Please sign in to comment.