Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: GCC with separated runtime libraries #132343

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions pkgs/development/compilers/gcc-ng/11/custom-threading-model.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
diff --git a/config/gthr.m4 b/config/gthr.m4
index 4b937306ad0..754e622f159 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -5,6 +5,35 @@ dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.

+dnl Define thread model
+
+dnl usage: GCC_AC_THREAD_MODEL
+AC_DEFUN([GCC_AC_THREAD_MODEL],
+[
+# With threads
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+AC_ARG_WITH(threads,
+[AS_HELP_STRING([[--with-threads=MODEL]],
+ [specify thread model for this GCC
+ runtime library])],,
+[with_threads=''])
+
+if test x"$with_threads" = x'yes'; then
+ AC_MSG_ERROR([Cannot pass bare --with-threads, must pass explicit --with-threads=MODEL])
+elif test x"$with_threads" = x'no'; then
+ target_thread_file=single
+elif test x"$with_threads" = x''; then
+ AC_MSG_CHECKING([for thread model used by GCC])
+ target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+ AC_MSG_RESULT([$target_thread_file])
+else
+ target_thread_file=$with_threads
+fi
+])
+
+
dnl Define header location by thread model

dnl usage: GCC_AC_THREAD_HEADER([thread_model])
@@ -22,6 +51,9 @@ case $1 in
tpf) thread_header=config/s390/gthr-tpf.h ;;
vxworks) thread_header=config/gthr-vxworks.h ;;
win32) thread_header=config/i386/gthr-win32.h ;;
+ *)
+ AC_MSG_ERROR([No known header for threading model '$1'.])
+ ;;
esac
AC_SUBST(thread_header)
])
diff --git a/libatomic/configure.ac b/libatomic/configure.ac
index 2a371870c2f..42d2016b7a2 100644
--- a/libatomic/configure.ac
+++ b/libatomic/configure.ac
@@ -161,9 +161,7 @@ libtool_VERSION=3:0:2
AC_SUBST(libtool_VERSION)

# Check for used threading-model
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file])
+GCC_AC_THREAD_MODEL

case "$target" in
*aarch64*)
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 13a80b2551b..1209a0986e0 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -298,9 +298,7 @@ AC_SUBST([use_tm_clone_registry])

AC_LIB_PROG_LD_GNU

-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file])
+GCC_AC_THREAD_MODEL

# Check for assembler CFI support.
AC_CACHE_CHECK([whether assembler supports CFI directives], [libgcc_cv_cfi],
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
index 351558dbcda..2b44fbca8fc 100644
--- a/libphobos/m4/druntime/os.m4
+++ b/libphobos/m4/druntime/os.m4
@@ -32,7 +32,7 @@ case $1 in
# TODO: These targets need porting.
dce|mipssde|rtems|tpf|vxworks)
DCFG_THREAD_MODEL="Single" ;;
- *) as_fn_error "Thread implementation '$1' not recognised" "$LINENO" 5 ;;
+ *) AC_MSG_ERROR([Thread implementation '$1' not recognised]) ;;
esac
AC_SUBST(DCFG_THREAD_MODEL)
])
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 1c0a4c13052..34a55d4e609 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -3977,9 +3977,7 @@ dnl Substs:
dnl thread_header
dnl
AC_DEFUN([GLIBCXX_ENABLE_THREADS], [
- AC_MSG_CHECKING([for thread model used by GCC])
- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
- AC_MSG_RESULT([$target_thread_file])
+ GCC_AC_THREAD_MODEL
GCC_AC_THREAD_HEADER([$target_thread_file])
])

@@ -3989,7 +3987,8 @@ dnl Check if gthread implementation defines the types and functions
dnl required by the c++0x thread library. Conforming gthread
dnl implementations can define __GTHREADS_CXX0X to enable use with c++0x.
dnl
-dnl GLIBCXX_ENABLE_SYMVERS must be done before this.
+dnl GLIBCXX_ENABLE_SYMVERS and GLIBCXX_ENABLE_THREADS must be done
+dnl before this.
dnl
AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
GLIBCXX_ENABLE(libstdcxx-threads,auto,,[enable C++11 threads support])
@@ -4004,7 +4003,6 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
CXXFLAGS="$CXXFLAGS -fno-exceptions \
-I${toplevel_srcdir}/libgcc -I${toplevel_builddir}/libgcc"

- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
case $target_thread_file in
posix)
CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS"
180 changes: 180 additions & 0 deletions pkgs/development/compilers/gcc-ng/11/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{ lowPrio, newScope, pkgs, lib, stdenv
, fetchzip, wrapCCWith, overrideCC
, preLibcCrossHeaders
, buildGccTools # tools, but from the previous stage, for cross
, targetGccLibraries # libraries, but from the next stage, for cross
# This is the default binutils, but with *this* version of LLD rather
# than the default LLVM verion's, if LLD is the choice. We use these for
# the `useLLVM` bootstrapping below.
, bintoolsNoLibc
, bintools
, darwin
}:

let
version = "11.2.0";

# fetchzip to unpack makes debug cycle much better
gcc_src = fetchzip {
url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz";
sha256 = "0aj1l0wkdbd5l2h5qybw0i5nwqbhqx89klnp7m5mwr63gmjfxwmi";
};

gcc_meta = {
description = "GNU Compiler Collection";
longDescription = ''
The GNU Compiler Collection includes compiler front ends for C, C++,
Objective-C, Fortran, OpenMP for C/C++/Fortran, and Ada, as well as
libraries for these languages (libstdc++, libgomp,...).

GCC development is a part of the GNU Project, aiming to improve the
compiler used in the GNU system including the GNU/Linux variant.
'';
homepage = "https://gcc.gnu.org/";
maintainers = with lib.maintainers; [ ericson231 sternenseemann ];
};
gcc_libs_meta = gcc_meta // {
license = lib.licenses.lgpl3Plus;
platforms = lib.platforms.all;
};
gcc_tools_meta = gcc_meta // {
license = lib.licenses.gpl3Plus;
platforms = lib.platforms.unix;
};
sternenseemann marked this conversation as resolved.
Show resolved Hide resolved

tools = lib.makeExtensible (tools: let
callPackage = newScope (tools // { inherit version gcc_tools_meta gcc_src buildGccTools; });

mkExtraBuildCommands0 = _: "";

mkExtraBuildCommands = _: "";

in {

gcc-unwrapped = callPackage ./gcc { };

# TODO: support libcxx? is there even an usecase for that?
gcc = if stdenv.cc.isClang then tools.libcxxGcc else tools.libstdcxxGcc;

libcxxGcc = wrapCCWith rec {
cc = tools.gcc-unwrapped;
extraPackages = [
targetGccLibraries.libgcc
];
extraBuildCommands = mkExtraBuildCommands cc;
};

libstdcxxGcc = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = targetGccLibraries.libstdcxx;
extraPackages = [
targetGccLibraries.libgcc
];
extraBuildCommands = mkExtraBuildCommands cc;
};

# Below, is the GCC Next Gen bootstrapping logic. It handles building a
# fully GCC toolchain from scratch via Nix. No LLVM toolchain should be
# pulled in. We should deduplicate this bootstrapping with its LLVM
# equivalence one GCC "old gen" is gone.

gccUseGccNg = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = targetGccLibraries.libstdcxx;
extraPackages = [
targetGccLibraries.libgcc
] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [
targetGccLibraries.libunwind
];
extraBuildCommands = ''
echo "-B${targetGccLibraries.libgcc}/lib" >> $out/nix-support/cc-cflags
'' + lib.optionalString (!stdenv.targetPlatform.isWasm) ''
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
'' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
echo "-lunwind" >> $out/nix-support/cc-ldflags
'' + lib.optionalString stdenv.targetPlatform.isWasm ''
echo "-fno-exceptions" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

gccNoLibstdcxx = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = null;
extraPackages = [
targetGccLibraries.libgcc
];
extraBuildCommands = ''
echo "-B${targetGccLibraries.libgcc}/lib" >> $out/nix-support/cc-cflags
echo "-B${targetGccLibraries.libatomic}/lib" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

gccNoLibatomic = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = null;
extraPackages = [
targetGccLibraries.libgcc
];
extraBuildCommands = ''
echo "-B${targetGccLibraries.libgcc}/lib" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

gccNoLibc = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc;
extraPackages = [
targetGccLibraries.libgcc
];
extraBuildCommands = ''
echo "-B${targetGccLibraries.libgcc}/lib" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
};

gccNoLibgcc = wrapCCWith rec {
cc = tools.gcc-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc;
extraPackages = [ ];
extraBuildCommands = ''
echo "-nostartfiles" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands0 cc;
};

});

libraries = lib.makeExtensible (libraries: let
callPackage = newScope (libraries // buildGccTools // { inherit version gcc_libs_meta gcc_src; });
in {

libgcc = callPackage ./libgcc {
stdenv = overrideCC stdenv buildGccTools.gccNoLibgcc;
};

stdenv = overrideCC stdenv buildGccTools.gcc;

libstdcxxStdenv = overrideCC stdenv buildGccTools.libstdcxxGcc;

libada = callPackage ./libada { };

libatomic = callPackage ./libatomic {
# TODO should libatomic be built before or after libc?
stdenv = overrideCC stdenv buildGccTools.gccNoLibatomic;
};

libssp = callPackage ./libssp {
# TODO should libssp be built before or after libc?
stdenv = overrideCC stdenv buildGccTools.gccNoLibatomic;
};

libgfortran = callPackage ./libgfortran { };

libstdcxx = callPackage ./libstdcxx {
stdenv = overrideCC stdenv buildGccTools.gccNoLibstdcxx;
};

# TODO add (gnu) libunwind here? can already be built separately aiui
});

in { inherit tools libraries; } // libraries // tools
Loading