1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

Toolchain+Ports: Enable threads for gcc

This enables POSIX threads for GCC and makes the -pthread
argument available.
This commit is contained in:
Gunnar Beutner 2021-04-18 08:34:26 +02:00 committed by Andreas Kling
parent 7400e3d8fc
commit 75d41657d5
5 changed files with 101 additions and 19 deletions

View file

@ -67,13 +67,13 @@ jobs:
# *and* as actual output variable, in this order. # *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=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', 'Userland/Libraries/LibPthread/**/*.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') }}")
- name: Toolchain cache - name: Toolchain cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: ${{ github.workspace }}/Toolchain/Cache/ 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. # This is wrong, and causes more Toolchain rebuilds than necessary.
# However, we want to avoid false cache hits at all costs. # However, we want to avoid false cache hits at all costs.
key: ${{ runner.os }}-toolchain-i686-${{ steps.stamps.outputs.libc_headers }} key: ${{ runner.os }}-toolchain-i686-${{ steps.stamps.outputs.libc_headers }}

View file

@ -2,10 +2,11 @@
port=gcc port=gcc
version=10.3.0 version=10.3.0
useconfigure=true 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 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/gcc/gcc-${version}/gcc-${version}.tar.xz.sig gcc-${version}.tar.xz.sig
https://ftpmirror.gnu.org/gnu/gnu-keyring.gpg gnu-keyring.gpg" 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)" 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" installopts="DESTDIR=${SERENITY_INSTALL_ROOT} install-gcc install-target-libgcc install-target-libstdc++-v3"
depends="binutils" depends="binutils"

View file

@ -6,7 +6,7 @@ diff -ruN a/config.sub b/config.sub
# Copyright 1992-2019 Free Software Foundation, Inc. # Copyright 1992-2019 Free Software Foundation, Inc.
-timestamp='2019-06-30' -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 # 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 # under the terms of the GNU General Public License as published by
@ -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 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 --- 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 +++ 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. */ +/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY +#undef TARGET_SERENITY
+#define TARGET_SERENITY 1 +#define TARGET_SERENITY 1
@ -114,7 +114,7 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+/* Default arguments you want when running your +/* Default arguments you want when running your
+ i686-serenity-gcc/x86_64-serenity-gcc toolchain */ + i686-serenity-gcc/x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC +#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. +/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */ + The %s tells GCC to look for these files in the library directory. */
@ -134,6 +134,9 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+#undef CC1PLUS_SPEC +#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC "-fno-exceptions -ftls-model=initial-exec" +#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. */ +/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS +#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \ +#define TARGET_OS_CPP_BUILTINS() \
@ -144,10 +147,46 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+ builtin_assert ("system=unix"); \ + builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \ + builtin_assert ("system=posix"); \
+ } while(0); + } 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 <gunnar@beutner.name>
+;
+; 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/>.
+
+; 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 diff -ruN a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300 --- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300
+++ b/gcc/config.gcc 2020-12-12 10:43:35.280270540 +0200 +++ 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. # Common parts for widely ported systems.
case ${target} in case ${target} in
@ -155,11 +194,12 @@ diff -ruN a/gcc/config.gcc b/gcc/config.gcc
+ gas=yes + gas=yes
+ gnu_ld=yes + gnu_ld=yes
+ default_use_cxa_atexit=yes + default_use_cxa_atexit=yes
+ extra_options="${extra_options} serenity.opt"
+ ;; + ;;
*-*-darwin*) *-*-darwin*)
tmake_file="t-darwin " tmake_file="t-darwin "
tm_file="${tm_file} darwin.h" tm_file="${tm_file} darwin.h"
@@ -1033,6 +1038,15 @@ @@ -1063,6 +1069,15 @@
esac esac
case ${target} in case ${target} in
@ -224,7 +264,7 @@ diff -ruN a/libgcc/config.host b/libgcc/config.host
diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure
--- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300 --- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300
+++ b/libstdc++-v3/configure 2020-12-12 10:43:35.288270409 +0200 +++ 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. # Base decisions on target environment.
case "${host}" in case "${host}" in

View file

@ -239,14 +239,14 @@ pushd "$DIR/Build/$ARCH"
buildstep "binutils/install" "$MAKE" install || exit 1 buildstep "binutils/install" "$MAKE" install || exit 1
popd popd
echo "XXX serenity libc and libm headers" echo "XXX serenity libc, libm and libpthread headers"
mkdir -p "$BUILD" mkdir -p "$BUILD"
pushd "$BUILD" pushd "$BUILD"
mkdir -p Root/usr/include/ mkdir -p Root/usr/include/
SRC_ROOT=$($REALPATH "$DIR"/..) 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 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" buildstep "system_headers" $INSTALL -D "$header" "Root/usr/include/$target"
done done
unset SRC_ROOT unset SRC_ROOT
@ -289,6 +289,7 @@ pushd "$DIR/Build/$ARCH"
--enable-languages=c,c++ \ --enable-languages=c,c++ \
--enable-default-pie \ --enable-default-pie \
--enable-lto \ --enable-lto \
--enable-threads=posix \
${TRY_USE_LOCAL_TOOLCHAIN:+"--quiet"} || exit 1 ${TRY_USE_LOCAL_TOOLCHAIN:+"--quiet"} || exit 1
if [ "$STAGE" = "Userland" ]; then if [ "$STAGE" = "Userland" ]; then

View file

@ -6,7 +6,7 @@ diff -ruN a/config.sub b/config.sub
# Copyright 1992-2019 Free Software Foundation, Inc. # Copyright 1992-2019 Free Software Foundation, Inc.
-timestamp='2019-06-30' -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 # 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 # under the terms of the GNU General Public License as published by
@ -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 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 --- 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 +++ 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. */ +/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY +#undef TARGET_SERENITY
+#define TARGET_SERENITY 1 +#define TARGET_SERENITY 1
@ -114,7 +114,7 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+/* Default arguments you want when running your +/* Default arguments you want when running your
+ i686-serenity-gcc/x86_64-serenity-gcc toolchain */ + i686-serenity-gcc/x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC +#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. +/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */ + The %s tells GCC to look for these files in the library directory. */
@ -134,6 +134,9 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+#undef CC1PLUS_SPEC +#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC "-fno-exceptions -ftls-model=initial-exec" +#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. */ +/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS +#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \ +#define TARGET_OS_CPP_BUILTINS() \
@ -144,10 +147,46 @@ diff -ruN a/gcc/config/serenity.h b/gcc/config/serenity.h
+ builtin_assert ("system=unix"); \ + builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \ + builtin_assert ("system=posix"); \
+ } while(0); + } 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 <gunnar@beutner.name>
+;
+; 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/>.
+
+; 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 diff -ruN a/gcc/config.gcc b/gcc/config.gcc
--- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300 --- a/gcc/config.gcc 2020-07-23 09:35:17.316384243 +0300
+++ b/gcc/config.gcc 2020-12-12 10:43:35.280270540 +0200 +++ 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. # Common parts for widely ported systems.
case ${target} in case ${target} in
@ -155,11 +194,12 @@ diff -ruN a/gcc/config.gcc b/gcc/config.gcc
+ gas=yes + gas=yes
+ gnu_ld=yes + gnu_ld=yes
+ default_use_cxa_atexit=yes + default_use_cxa_atexit=yes
+ extra_options="${extra_options} serenity.opt"
+ ;; + ;;
*-*-darwin*) *-*-darwin*)
tmake_file="t-darwin " tmake_file="t-darwin "
tm_file="${tm_file} darwin.h" tm_file="${tm_file} darwin.h"
@@ -1033,6 +1038,15 @@ @@ -1063,6 +1069,15 @@
esac esac
case ${target} in case ${target} in
@ -224,7 +264,7 @@ diff -ruN a/libgcc/config.host b/libgcc/config.host
diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure diff -ruN a/libstdc++-v3/configure b/libstdc++-v3/configure
--- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300 --- a/libstdc++-v3/configure 2020-07-23 09:35:19.188404867 +0300
+++ b/libstdc++-v3/configure 2020-12-12 10:43:35.288270409 +0200 +++ 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. # Base decisions on target environment.
case "${host}" in case "${host}" in