diff --git a/pkgs/development/compilers/gcc-ng/11/custom-threading-model.patch b/pkgs/development/compilers/gcc-ng/11/custom-threading-model.patch new file mode 100644 index 0000000000000..163a08c427432 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/custom-threading-model.patch @@ -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" diff --git a/pkgs/development/compilers/gcc-ng/11/default.nix b/pkgs/development/compilers/gcc-ng/11/default.nix new file mode 100644 index 0000000000000..948ca11286ef2 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/default.nix @@ -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; + }; + + 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 diff --git a/pkgs/development/compilers/gcc-ng/11/gcc/default.nix b/pkgs/development/compilers/gcc-ng/11/gcc/default.nix new file mode 100644 index 0000000000000..e023c1ee44a1c --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/gcc/default.nix @@ -0,0 +1,207 @@ +{ lib, stdenv, targetPackages, fetchurl, fetchpatch +, gcc_tools_meta, gcc_src, version + +, langAda ? false +, langC ? true +, langCC ? true +, langD ? false +, langFortran ? false +, langGo ? false +, langJava ? false +, langObjC ? stdenv.targetPlatform.isDarwin +, langObjCpp ? stdenv.targetPlatform.isDarwin + +, reproducibleBuild ? true +, profiledCompiler ? false +, langJit ? false +, texinfo ? null +, perl ? null # lib.optional, for texi2pod (then pod2man) +, gmp, mpfr, libmpc, gettext, which, patchelf +, libelf # lib.optional, for link-time optimizations (LTO) +, isl ? null +, zlib ? null +, name ? "gcc" +, gnused ? null +, nonRelease ? false, flex ? null, bison ? null # Convenience for working on GCC +, buildPackages +}: + +# LTO needs libelf and zlib. +assert libelf != null -> zlib != null; + +# Make sure we get GNU sed. +assert stdenv.hostPlatform.isDarwin -> gnused != null; + +# The go frontend is written in c++ +assert langGo -> langCC; + +# The source tree has less pregenerated code +assert nonRelease -> flex != null && bison != null; + +# profiledCompiler builds inject non-determinism in one of the compilation stages. +# If turned on, we can't provide reproducible builds anymore +assert reproducibleBuild -> profiledCompiler == false; + +let + inherit (stdenv) buildPlatform hostPlatform targetPlatform; + + targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; +in + +stdenv.mkDerivation ({ + pname = targetPrefix + name; + inherit version; + + src = gcc_src; + + patches = [ + ../../../gcc/no-sys-dirs.patch + ./find-prefixed-progs.patch + ] ++ lib.optional langFortran ../../gcc/gfortran-driving.patch + ++ lib.optional (stdenv.isDarwin && stdenv.isAarch64) (fetchpatch { + url = "https://github.com/fxcoudert/gcc/compare/releases/gcc-11.1.0...gcc-11.1.0-arm-20210504.diff"; + sha256 = "sha256-JqCGJAfbOxSmkNyq49aFHteK/RFsCSLQrL9mzUCnaD0="; + }) + + # Obtain latest patch with ../../gcc/update-mcfgthread-patches.sh + ++ lib.optional targetPlatform.isMinGW ../../gcc/11/Added-mcf-thread-model-support-from-mcfgthread.patch; + + # TODO someday avoid target-specific subdirs all over the place and split libs from binaries + outputs = [ "out" "dev" "man" "info" ]; + + strictDeps = true; + + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ texinfo which gettext ] + ++ lib.optional (perl != null) perl + ++ lib.optionals nonRelease [ flex bison ] + ; + + buildInputs = [ + gmp mpfr libmpc libelf + #libiberty # TODO use prebuilt + ] ++ lib.optional (isl != null) isl + ++ lib.optional (zlib != null) zlib + # The builder relies on GNU sed (for instance, Darwin's `sed' fails with + # "-i may not be used with stdin"), and `stdenvNative' doesn't provide it. + ++ lib.optional hostPlatform.isDarwin gnused + ; + + enableParallelBuilding = true; + + hardeningDisable = [ + "format" # Some macro-indirect formatting in e.g. libcpp + ]; + + postUnpack = '' + mkdir -p ./build + buildRoot=$(readlink -e "./build") + ''; + + postPatch = '' + configureScripts=$(find . -name configure) + for configureScript in $configureScripts; do + patchShebangs $configureScript + done + '' + # This should kill all the stdinc frameworks that gcc and friends like to + # insert into default search paths. + + lib.optionalString hostPlatform.isDarwin '' + substituteInPlace gcc/config/darwin-c.c \ + --replace 'if (stdinc)' 'if (0)' + ''; + + preConfigure = + # Don't built target libraries, because we want to build separately + '' + substituteInPlace configure \ + --replace 'noconfigdirs=""' 'noconfigdirs="$noconfigdirs $target_libraries"' + '' + # HACK: if host and target config are the same, but the platforms are + # actually different we need to convince the configure script that it + # is in fact building a cross compiler although it doesn't believe it. + + lib.optionalString (targetPlatform.config == hostPlatform.config && targetPlatform != hostPlatform) '' + substituteInPlace configure --replace is_cross_compiler=no is_cross_compiler=yes + '' + # Cannot configure from src dir + + '' + cd $buildRoot + configureScript=../$sourceRoot/configure + ''; + + # Don't store the configure flags in the resulting executables. + postConfigure = '' + sed -e '/TOPLEVEL_CONFIGURE_ARGUMENTS=/d' -i Makefile + ''; + + # These flags confusingly control the runtime with GCC. + dontDisableStatic = true; + + configurePlatforms = [ "build" "host" "target" ]; + + configureFlags = [ + # Force target prefix. The behavior if `--target` and `--host` are + # specified is inconsistent: Sometimes specifying `--target` always causes + # a prefix to be generated, sometimes it's only added if the `--host` and + # `--target` differ. This means that sometimes there may be a prefix even + # though nixpkgs doesn't expect one and sometimes there may be none even + # though nixpkgs expects one (since not all information is serialized into + # the config attribute). The easiest way out of these problems is to always + # set the program prefix, so gcc will conform to our expectations. + "--program-prefix=${targetPrefix}" + + "--disable-dependency-tracking" + "--enable-fast-install" + "--disable-serial-configure" + "--disable-bootstrap" + "--disable-decimal-float" + "--disable-install-libiberty" + "--disable-multilib" + "--disable-nls" + "--disable-shared" + "--enable-plugin" + "--enable-plugins" + "--enable-languages=${ + lib.concatStrings (lib.intersperse "," + ( lib.optional langC "c" + ++ lib.optional langCC "c++" + ++ lib.optional langD "d" + ++ lib.optional langFortran "fortran" + ++ lib.optional langJava "java" + ++ lib.optional langAda "ada" + ++ lib.optional langGo "go" + ++ lib.optional langObjC "objc" + ++ lib.optional langObjCpp "obj-c++" + ++ lib.optional langJit "jit" + ) + ) + }" + (lib.withFeature (isl != null) "isl") + "--without-headers" + "--with-gnu-as" + "--with-gnu-ld" + "--with-system-zlib" + "--without-included-gettext" + "--enable-linker-build-id" + "--with-multilib-list=" + ]; + + postInstall = '' + moveToOutput "lib/gcc/${targetPlatform.config}/${version}/plugin/include" "$dev" + ''; + + passthru = { + inherit langC langCC langObjC langObjCpp langAda langFortran langGo version; + isGNU = true; + }; + + meta = gcc_tools_meta // { + description = gcc_tools_meta.description + " - compiler proper"; + }; +} + +# // lib.optionalAttrs (targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt" && crossStageStatic) { +# makeFlags = [ "all-gcc" "all-target-libgcc" ]; +# installTargets = "install-gcc install-target-libgcc"; +# } +) diff --git a/pkgs/development/compilers/gcc-ng/11/gcc/find-prefixed-progs.patch b/pkgs/development/compilers/gcc-ng/11/gcc/find-prefixed-progs.patch new file mode 100644 index 0000000000000..77d1e7e62c63b --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/gcc/find-prefixed-progs.patch @@ -0,0 +1,213 @@ +diff --git a/gcc/gcc.c b/gcc/gcc.c +index 4d790f9dd4a..a99a6bfcba3 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -361,6 +361,7 @@ static void putenv_from_prefixes (const struct path_prefix *, const char *, + bool); + static int access_check (const char *, int); + static char *find_a_file (const struct path_prefix *, const char *, int, bool); ++static char *find_a_program (const char *); + static void add_prefix (struct path_prefix *, const char *, const char *, + int, int, int); + static void add_sysrooted_prefix (struct path_prefix *, const char *, +@@ -1575,6 +1576,11 @@ static const char *machine_suffix = 0; + + static const char *just_machine_suffix = 0; + ++/* Prefix to attach to *basename* of commands being searched. ++ This is just `MACHINE-'. */ ++ ++static const char *just_machine_prefix = 0; ++ + /* Adjusted value of GCC_EXEC_PREFIX envvar. */ + + static const char *gcc_exec_prefix; +@@ -3019,15 +3025,6 @@ file_at_path (char *path, void *data) + memcpy (path + len, info->name, info->name_len); + len += info->name_len; + +- /* Some systems have a suffix for executable files. +- So try appending that first. */ +- if (info->suffix_len) +- { +- memcpy (path + len, info->suffix, info->suffix_len + 1); +- if (access_check (path, info->mode) == 0) +- return path; +- } +- + path[len] = '\0'; + if (access_check (path, info->mode) == 0) + return path; +@@ -3046,6 +3043,75 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, + { + struct file_at_path_info info; + ++ /* Find the filename in question (special case for absolute paths). */ ++ ++ if (IS_ABSOLUTE_PATH (name)) ++ { ++ if (access (name, mode) == 0) ++ return xstrdup (name); ++ ++ return NULL; ++ } ++ ++ info.name = name; ++ info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : ""; ++ info.name_len = strlen (info.name); ++ info.suffix_len = strlen (info.suffix); ++ info.mode = mode; ++ ++ return (char*) for_each_path (pprefix, do_multi, ++ info.name_len + info.suffix_len, ++ file_at_path, &info); ++} ++ ++/* Callback for find_a_program. Appends the file name to the directory ++ path. Like file_at_path but tries machine prefix and exe suffix too. */ ++ ++static void * ++program_at_path (char *path, void *data) ++{ ++ /* try first with machine-prefixed name */ ++ struct file_at_path_info *info = (struct file_at_path_info *) data; ++ size_t path_len = strlen (path); ++ ++ for (auto prefix : { just_machine_prefix, "" }) ++ { ++ auto len = path_len; ++ ++ auto prefix_len = strlen(prefix); ++ memcpy (path + len, prefix, prefix_len); ++ len += prefix_len; ++ ++ memcpy (path + len, info->name, info->name_len); ++ len += info->name_len; ++ ++ /* Some systems have a suffix for executable files. ++ So try appending that first. */ ++ if (info->suffix_len) ++ { ++ memcpy (path + len, info->suffix, info->suffix_len + 1); ++ if (access_check (path, info->mode) == 0) ++ return path; ++ } ++ ++ path[len] = '\0'; ++ if (access_check (path, info->mode) == 0) ++ return path; ++ } ++ ++ return NULL; ++} ++ ++/* Specialization of find_a_file for programs that also takes into account ++ configure-specified default programs. */ ++ ++static char* ++find_a_program (const char *name) ++{ ++ const int mode = X_OK; ++ ++ /* Do not search if default matches query. */ ++ + #ifdef DEFAULT_ASSEMBLER + if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0) + return xstrdup (DEFAULT_ASSEMBLER); +@@ -3056,7 +3122,7 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, + return xstrdup (DEFAULT_LINKER); + #endif + +- /* Determine the filename to execute (special case for absolute paths). */ ++ /* Find the filename in question (special case for absolute paths). */ + + if (IS_ABSOLUTE_PATH (name)) + { +@@ -3066,15 +3132,18 @@ find_a_file (const struct path_prefix *pprefix, const char *name, int mode, + return NULL; + } + ++ struct file_at_path_info info; ++ + info.name = name; +- info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : ""; ++ info.suffix = HOST_EXECUTABLE_SUFFIX; + info.name_len = strlen (info.name); + info.suffix_len = strlen (info.suffix); + info.mode = mode; + +- return (char*) for_each_path (pprefix, do_multi, +- info.name_len + info.suffix_len, +- file_at_path, &info); ++ return (char*) for_each_path ( ++ &exec_prefixes, false, ++ info.name_len + info.suffix_len + strlen(just_machine_prefix), ++ program_at_path, &info); + } + + /* Ranking of prefixes in the sort list. -B prefixes are put before +@@ -3232,8 +3301,7 @@ execute (void) + + if (wrapper_string) + { +- string = find_a_file (&exec_prefixes, +- argbuf[0], X_OK, false); ++ string = find_a_program (argbuf[0]); + if (string) + argbuf[0] = string; + insert_wrapper (wrapper_string); +@@ -3258,7 +3326,7 @@ execute (void) + + if (!wrapper_string) + { +- string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); ++ string = find_a_program(commands[0].prog); + if (string) + commands[0].argv[0] = string; + } +@@ -3273,8 +3341,7 @@ execute (void) + commands[n_commands].prog = argbuf[i + 1]; + commands[n_commands].argv + = &(argbuf.address ())[i + 1]; +- string = find_a_file (&exec_prefixes, commands[n_commands].prog, +- X_OK, false); ++ string = find_a_program(commands[n_commands].prog); + if (string) + commands[n_commands].argv[0] = string; + n_commands++; +@@ -8226,6 +8293,7 @@ driver::set_up_specs () const + machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version, + accel_dir_suffix, dir_separator_str, NULL); + just_machine_suffix = concat (spec_machine, dir_separator_str, NULL); ++ just_machine_prefix = concat (spec_machine, "-", NULL); + + specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true); + /* Read the specs file unless it is a default one. */ +@@ -8466,8 +8534,7 @@ driver::maybe_putenv_COLLECT_LTO_WRAPPER () const + if (have_c) + lto_wrapper_file = NULL; + else +- lto_wrapper_file = find_a_file (&exec_prefixes, "lto-wrapper", +- X_OK, false); ++ lto_wrapper_file = find_a_program ("lto-wrapper"); + if (lto_wrapper_file) + { + lto_wrapper_file = convert_white_space (lto_wrapper_file); +@@ -8577,7 +8644,7 @@ driver::maybe_print_and_exit () const + #endif + print_prog_name = concat (print_prog_name, use_ld, NULL); + } +- char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0); ++ char *newname = find_a_program (print_prog_name); + printf ("%s\n", (newname ? newname : print_prog_name)); + return (0); + } +@@ -8976,7 +9043,7 @@ driver::maybe_run_linker (const char *argv0) const + /* We'll use ld if we can't find collect2. */ + if (! strcmp (linker_name_spec, "collect2")) + { +- char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false); ++ char *s = find_a_program ("collect2"); + if (s == NULL) + set_static_spec_shared (&linker_name_spec, "ld"); + } diff --git a/pkgs/development/compilers/gcc-ng/11/libatomic/default.nix b/pkgs/development/compilers/gcc-ng/11/libatomic/default.nix new file mode 100644 index 0000000000000..1d9b353b87a42 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libatomic/default.nix @@ -0,0 +1,45 @@ +{ lib, stdenv +, gcc_src, version, gcc_libs_meta +, autoreconfHook269 +}: + +stdenv.mkDerivation rec { + pname = "libatomic"; + inherit version; + + src = gcc_src; + + patches = [ + ../custom-threading-model.patch + ]; + + outputs = [ "out" "dev" ]; + + strictDeps = true; + + nativeBuildInputs = [ autoreconfHook269 ]; + + enableParallelBuilding = true; + + postPatch = '' + sourceRoot=$(readlink -e "./${pname}") + cd $sourceRoot + + sed -i \ + -e 's/AM_ENABLE_MULTILIB(/AM_ENABLE_MULTILIB(NOPE/' \ + configure.ac + ''; + + configurePlatforms = [ "build" "host" ]; + configureFlags = [ + "--disable-dependency-tracking" + "--with-toolexeclibdir=${builtins.placeholder "out" + "/lib"}" + #"--with-threads=posix" + "cross_compiling=true" + "--disable-multilib" + ]; + + meta = gcc_libs_meta // { + description = gcc_libs_meta.description + " - atomics support"; + }; +} diff --git a/pkgs/development/compilers/gcc-ng/11/libgcc/default.nix b/pkgs/development/compilers/gcc-ng/11/libgcc/default.nix new file mode 100644 index 0000000000000..28dcc12023835 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libgcc/default.nix @@ -0,0 +1,204 @@ +{ lib, stdenv, buildPackages +, gcc_src, version +, autoreconfHook269, libiberty +}: + +stdenv.mkDerivation rec { + pname = "libgcc"; + inherit version; + + src = gcc_src; + + patches = [ + ../custom-threading-model.patch + ]; + + outputs = [ "out" "dev" ]; + + strictDeps = true; + + depsBuildBuild = [ buildPackages.stdenv.cc ]; + nativeBuildInputs = [ autoreconfHook269 libiberty ]; + + enableParallelBuilding = true; + + postUnpack = '' + mkdir -p ./build + buildRoot=$(readlink -e "./build") + ''; + + postPatch = '' + sourceRoot=$(readlink -e "./libgcc") + ''; + + autoreconfFlags = "--install --force --verbose . libgcc"; + + preConfigure = '' + cd "$buildRoot" + '' + + # Drop in libiberty, as external builds are not expected + + '' + ( + mkdir -p build-${stdenv.buildPlatform.config}/libiberty/ + cd build-${stdenv.buildPlatform.config}/libiberty/ + ln -s ${buildPackages.libiberty}/lib/libiberty.a ./ + ) + '' + # A few misc bits of gcc need to be built. + # + # - We "shift" the tools over to fake platforms perspective from the previous + # stage. + # + # - We define GENERATOR_FILE so nothing bothers looking for GNU GMP. + # + # - We remove the `libgcc.mvar` deps so that the bootstrap xgcc isn't built. + + '' + mkdir -p "$buildRoot/gcc" + cd "$buildRoot/gcc" + ( + export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD + export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD + export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD + export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD + export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD + + export AS=$AS_FOR_BUILD + export CC=$CC_FOR_BUILD + export CPP=$CPP_FOR_BUILD + export CXX=$CXX_FOR_BUILD + export LD=$LD_FOR_BUILD + + export AS_FOR_TARGET=${stdenv.cc}/bin/$AS + export CC_FOR_TARGET=${stdenv.cc}/bin/$CC + export CPP_FOR_TARGET=${stdenv.cc}/bin/$CPP + export LD_FOR_TARGET=${stdenv.cc.bintools}/bin/$LD + + export NIX_CFLAGS_COMPILE_FOR_BUILD+=' -DGENERATOR_FILE=1' + + "$sourceRoot/../gcc/configure" $topLevelConfigureFlags + + sed -e 's,libgcc.mvars:.*$,libgcc.mvars:,' -i Makefile + + make \ + config.h \ + libgcc.mvars \ + tconfig.h \ + tm.h \ + options.h \ + insn-constants.h \ + insn-modes.h \ + gcov-iov.h + ) + mkdir -p "$buildRoot/gcc/include" + '' + # Preparing to configure + build libgcc itself + + '' + mkdir -p "$buildRoot/gcc/${stdenv.hostPlatform.config}/libgcc" + cd "$buildRoot/gcc/${stdenv.hostPlatform.config}/libgcc" + configureScript=$sourceRoot/configure + chmod +x "$configureScript" + + export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD + export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD + export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD + export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD + export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD + + export AS=${stdenv.cc}/bin/$AS + export CC=${stdenv.cc}/bin/$CC + export CPP=${stdenv.cc}/bin/$CPP + export CXX=${stdenv.cc}/bin/$CXX + export LD=${stdenv.cc.bintools}/bin/$LD + + export AS_FOR_TARGET=${stdenv.cc}/bin/$AS_FOR_TARGET + export CC_FOR_TARGET=${stdenv.cc}/bin/$CC_FOR_TARGET + export CPP_FOR_TARGET=${stdenv.cc}/bin/$CPP_FOR_TARGET + export LD_FOR_TARGET=${stdenv.cc.bintools}/bin/$LD_FOR_TARGET + '' + # Fix build for Musl (even though musl isn't built yet!) + # + # Here's the situation: GCC's default serach patch usual includes an + # "include-fixed" directory where various hheaders that are non-comformant + # are overridden with comformant ones. This was probably created for all the + # old proprietary Unices GNU software had to build on, but also used for + # glibc for at least limits.h. Musl, however, doesn't hit this problem, and + # so GCC doesn't bother putting the include-next files on the CLI even though + # it does ship with them. + # + # While libgcc is built prior to libc, it's configure script does check to + # see if the C pre-processor works, and does so via trying include---you + # guessed it---limits.h. This works with glibc because it picks up the + # include-fixed version. This doesn't work with Musl however because it + # doesn't pick up any limits.h, and thus thinks the C preprocessor is broken. + # + # BTW, we are just discovering this now this now because in a regular + # monolith build of GCC, the build-time include-fix is *unconditionally* + # added as an -isystem in CFLAGS_FOR_TARGET, even though it onluy + # conditionally becomes an installed default. People doing regular MUSL + # builds therefore haven't hit this issue. + # + # Our work-around is to manually add the -isystem ourselves, but only at + # configure time, by sneaking it in NIX_CLAGS_COMPILE behind the build + # system's back. While the include-fixed limits.h is probably safe to use, we + # rather use Musl's own for consistently with how GCC will be used + # "regularly". + + lib.optionalString stdenv.hostPlatform.isMusl '' + NIX_CFLAGS_COMPILE_OLD=$NIX_CFLAGS_COMPILE + NIX_CFLAGS_COMPILE+=' -isystem ${stdenv.cc.cc}/lib/gcc/${stdenv.hostPlatform.config}/${version}/include-fixed' + ''; + + topLevelConfigureFlags = [ + "--build=${stdenv.buildPlatform.config}" + "--host=${stdenv.buildPlatform.config}" + "--target=${stdenv.hostPlatform.config}" + + "--disable-bootstrap" + "--disable-multilib" "--with-multilib-list=" + "--enable-languages=c" + + "--disable-fixincludes" + "--disable-intl" + "--disable-lto" + "--disable-libatomic" + "--disable-libbacktrace" + "--disable-libcpp" + "--disable-libssp" + "--disable-libquadmath" + "--disable-libgomp" + "--disable-libvtv" + "--disable-vtable-verify" + + "--with-system-zlib" + ] ++ lib.optional (stdenv.hostPlatform.libc == "glibc") + # Cheat and use previous stage's glibc to avoid infinite recursion. As + # of GCC 11, libgcc only cares if the version is greater than 2.19, + # which is quite ancient, so this little lie should be fine. + "--with-glibc-version=${buildPackages.glibc.version}"; + + configurePlatforms = [ "build" "host" ]; + configureFlags = [ + "--disable-dependency-tracking" + "--with-threads=single" + # $CC cannot link binaries, let alone run then + "cross_compiling=true" + # Do not have dynamic linker without libc + "--enable-static" + "--disable-shared" + ]; + + # Set the variable back the way it was, see corresponding code in + # `preConfigure`. + postConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + NIX_CFLAGS_COMPILE=$NIX_CFLAGS_COMPILE_OLD + ''; + + makeFlags = [ "MULTIBUILDTOP:=../" ]; + + postInstall = '' + moveToOutput "lib/gcc/${stdenv.hostPlatform.config}/${version}/include" "$dev" + mkdir -p "$out/lib" "$dev/include" + ln -s "$out/lib/gcc/${stdenv.hostPlatform.config}/${version}"/* "$out/lib" + ln -s "$dev/lib/gcc/${stdenv.hostPlatform.config}/${version}/include"/* "$dev/include/" + ''; +} diff --git a/pkgs/development/compilers/gcc-ng/11/libssp/default.nix b/pkgs/development/compilers/gcc-ng/11/libssp/default.nix new file mode 100644 index 0000000000000..22d2327ea2cc1 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libssp/default.nix @@ -0,0 +1,44 @@ +{ lib, stdenv +, gcc_src, version, gcc_libs_meta +, autoreconfHook269 +}: + +stdenv.mkDerivation rec { + pname = "libssp"; + inherit version; + + src = gcc_src; + + patches = [ + ./fix-include-dir.patch + ]; + + outputs = [ "out" "dev" ]; + + strictDeps = true; + + nativeBuildInputs = [ autoreconfHook269 ]; + + enableParallelBuilding = true; + + postPatch = '' + sourceRoot=$(readlink -e "./${pname}") + cd $sourceRoot + + sed -i \ + -e 's/AM_ENABLE_MULTILIB(/AM_ENABLE_MULTILIB(NOPE/' \ + configure.ac + ''; + + configurePlatforms = [ "build" "host" ]; + configureFlags = [ + "--disable-dependency-tracking" + "--with-toolexeclibdir=${builtins.placeholder "out" + "/lib"}" + "cross_compiling=true" + "--disable-multilib" + ]; + + meta = gcc_libs_meta // { + description = gcc_libs_meta.description + " - stack smashing protector support"; + }; +} diff --git a/pkgs/development/compilers/gcc-ng/11/libssp/fix-include-dir.patch b/pkgs/development/compilers/gcc-ng/11/libssp/fix-include-dir.patch new file mode 100644 index 0000000000000..f183e76899dfc --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libssp/fix-include-dir.patch @@ -0,0 +1,13 @@ +diff --git a/libssp/Makefile.am b/libssp/Makefile.am +index 6045c320cfa..2a31d2805e7 100644 +--- a/libssp/Makefile.am ++++ b/libssp/Makefile.am +@@ -39,7 +39,7 @@ AM_CFLAGS += $(XCFLAGS) + toolexeclib_LTLIBRARIES = libssp.la libssp_nonshared.la + + target_noncanonical = @target_noncanonical@ +-libsubincludedir = $(libdir)/gcc/$(target_noncanonical)/$(gcc_version)/include ++libsubincludedir = $(includedir) + nobase_libsubinclude_HEADERS = ssp/ssp.h ssp/string.h ssp/stdio.h ssp/unistd.h + + libssp_la_SOURCES = \ diff --git a/pkgs/development/compilers/gcc-ng/11/libstdcxx/default.nix b/pkgs/development/compilers/gcc-ng/11/libstdcxx/default.nix new file mode 100644 index 0000000000000..f4c64ec1d4ba0 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libstdcxx/default.nix @@ -0,0 +1,51 @@ +{ lib, stdenv +, gcc_src, version +, autoreconfHook269, gettext +}: + +stdenv.mkDerivation rec { + pname = "libstdc++-v3"; + inherit version; + + src = gcc_src; + + patches = [ + ../custom-threading-model.patch + ./disable-multilib-harder.patch + ]; + + outputs = [ "out" "dev" ]; + + strictDeps = true; + + nativeBuildInputs = [ autoreconfHook269 gettext ]; + + enableParallelBuilding = true; + + postPatch = '' + sourceRoot=$(readlink -e "./${pname}") + cd $sourceRoot + + sed -i \ + -e 's/AM_ENABLE_MULTILIB(/AM_ENABLE_MULTILIB(NOPE/' \ + -e 's#glibcxx_toolexeclibdir=no#glibcxx_toolexeclibdir=${builtins.placeholder "out" + "/libexec"}#' \ + configure.ac + ''; + + configurePlatforms = [ "build" "host" ]; + configureFlags = [ + "--disable-dependency-tracking" + "--with-toolexeclibdir=${builtins.placeholder "out" + "/lib"}" + #"--with-threads=posix" + "cross_compiling=true" + "--disable-multilib" + + "--enable-clocale=gnu" + "--disable-libstdcxx-pch" + "--disable-vtable-verify" + "--enable-libstdcxx-visibility" + "--with-default-libstdcxx-abi=new" + ] ++ lib.optional stdenv.hostPlatform.isMusl [ + "libat_cv_have_ifunc=no" + ]; +} diff --git a/pkgs/development/compilers/gcc-ng/11/libstdcxx/disable-multilib-harder.patch b/pkgs/development/compilers/gcc-ng/11/libstdcxx/disable-multilib-harder.patch new file mode 100644 index 0000000000000..3cf72361b9f79 --- /dev/null +++ b/pkgs/development/compilers/gcc-ng/11/libstdcxx/disable-multilib-harder.patch @@ -0,0 +1,12 @@ +diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac +index 3c799be82b1..3e15198f2d9 100644 +--- a/libstdc++-v3/configure.ac ++++ b/libstdc++-v3/configure.ac +@@ -634,7 +634,6 @@ _EOF + rm vpsed$$ + echo 'MULTISUBDIR =' >> $ac_file + ml_norecursion=yes +- . ${multi_basedir}/config-ml.in + AS_UNSET([ml_norecursion]) + ]) + diff --git a/pkgs/development/libraries/gcc/libstdc++/no-sys-dirs.patch b/pkgs/development/compilers/gcc-ng/11/libstdcxx/no-sys-dirs.patch similarity index 100% rename from pkgs/development/libraries/gcc/libstdc++/no-sys-dirs.patch rename to pkgs/development/compilers/gcc-ng/11/libstdcxx/no-sys-dirs.patch diff --git a/pkgs/development/libraries/gcc/libstdc++/struct-ucontext.patch b/pkgs/development/compilers/gcc-ng/11/libstdcxx/struct-ucontext.patch similarity index 100% rename from pkgs/development/libraries/gcc/libstdc++/struct-ucontext.patch rename to pkgs/development/compilers/gcc-ng/11/libstdcxx/struct-ucontext.patch diff --git a/pkgs/development/libraries/gcc/libgcc/default.nix b/pkgs/development/libraries/gcc/libgcc/default.nix deleted file mode 100644 index ab62fdf3fa202..0000000000000 --- a/pkgs/development/libraries/gcc/libgcc/default.nix +++ /dev/null @@ -1,152 +0,0 @@ -{ lib, stdenvNoLibs, buildPackages -, gcc, glibc -, libiberty -}: - -stdenvNoLibs.mkDerivation rec { - name = "libgcc-${version}"; - inherit (gcc.cc) src version; - - outputs = [ "out" "dev" ]; - - strictDeps = true; - depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ libiberty ]; - - postUnpack = '' - mkdir -p ./build - buildRoot=$(readlink -e "./build") - ''; - - postPatch = '' - sourceRoot=$(readlink -e "./libgcc") - ''; - - preConfigure = '' - cd "$buildRoot" - '' - - # Drop in libiberty, as external builds are not expected - + '' - ( - mkdir -p build-${stdenvNoLibs.buildPlatform.config}/libiberty/ - cd build-${stdenvNoLibs.buildPlatform.config}/libiberty/ - ln -s ${buildPackages.libiberty}/lib/libiberty.a ./ - ) - '' - # A few misc bits of gcc need to be built. - # - # - We "shift" the tools over to fake platforms perspective from the previous - # stage. - # - # - We define GENERATOR_FILE so nothing bothers looking for GNU GMP. - # - # - We remove the `libgcc.mvar` deps so that the bootstrap xgcc isn't built. - + '' - mkdir -p "$buildRoot/gcc" - cd "$buildRoot/gcc" - ( - export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD - export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD - export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD - export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD - export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD - - export AS=$AS_FOR_BUILD - export CC=$CC_FOR_BUILD - export CPP=$CPP_FOR_BUILD - export CXX=$CXX_FOR_BUILD - export LD=$LD_FOR_BUILD - - export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS - export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC - export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP - export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD - - export NIX_CFLAGS_COMPILE_FOR_BUILD+=' -DGENERATOR_FILE=1' - - "$sourceRoot/../gcc/configure" $gccConfigureFlags - - sed -e 's,libgcc.mvars:.*$,libgcc.mvars:,' -i Makefile - - make \ - config.h \ - libgcc.mvars \ - tconfig.h \ - tm.h \ - options.h \ - insn-constants.h \ - insn-modes.h \ - gcov-iov.h - ) - mkdir -p "$buildRoot/gcc/include" - '' - # Preparing to configure + build libgcc itself - + '' - mkdir -p "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc" - cd "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc" - configureScript=$sourceRoot/configure - chmod +x "$configureScript" - - export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD - export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD - export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD - export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD - export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD - - export AS=${stdenvNoLibs.cc}/bin/$AS - export CC=${stdenvNoLibs.cc}/bin/$CC - export CPP=${stdenvNoLibs.cc}/bin/$CPP - export CXX=${stdenvNoLibs.cc}/bin/$CXX - export LD=${stdenvNoLibs.cc.bintools}/bin/$LD - - export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS_FOR_TARGET - export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC_FOR_TARGET - export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP_FOR_TARGET - export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD_FOR_TARGET - ''; - - gccConfigureFlags = [ - "--build=${stdenvNoLibs.buildPlatform.config}" - "--host=${stdenvNoLibs.buildPlatform.config}" - "--target=${stdenvNoLibs.hostPlatform.config}" - - "--disable-bootstrap" - "--disable-multilib" "--with-multilib-list=" - "--enable-languages=c" - - "--disable-fixincludes" - "--disable-intl" - "--disable-lto" - "--disable-libatomic" - "--disable-libbacktrace" - "--disable-libcpp" - "--disable-libssp" - "--disable-libquadmath" - "--disable-libgomp" - "--disable-libvtv" - "--disable-vtable-verify" - - "--with-system-zlib" - ] ++ lib.optional (stdenvNoLibs.hostPlatform.libc == "glibc") - "--with-glibc-version=${glibc.version}"; - - configurePlatforms = [ "build" "host" ]; - configureFlags = [ - "--disable-dependency-tracking" - # $CC cannot link binaries, let alone run then - "cross_compiling=true" - # Do not have dynamic linker without libc - "--enable-static" - "--disable-shared" - ]; - - makeFlags = [ "MULTIBUILDTOP:=../" ]; - - postInstall = '' - moveToOutput "lib/gcc/${stdenvNoLibs.hostPlatform.config}/${version}/include" "$dev" - mkdir -p "$out/lib" "$dev/include" - ln -s "$out/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${version}"/* "$out/lib" - ln -s "$dev/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${version}/include"/* "$dev/include/" - ''; -} diff --git a/pkgs/development/libraries/gcc/libstdc++/5.nix b/pkgs/development/libraries/gcc/libstdc++/5.nix deleted file mode 100644 index f963ae31e5c13..0000000000000 --- a/pkgs/development/libraries/gcc/libstdc++/5.nix +++ /dev/null @@ -1,117 +0,0 @@ -{ lib, stdenv, fetchurl, fetchpatch, flex, bison, file }: - -stdenv.mkDerivation rec { - pname = "libstdc++5"; - version = "3.3.6"; - - src = [ - (fetchurl { - url = "mirror://gcc/releases/gcc-${version}/gcc-core-${version}.tar.bz2"; - sha256 = "1dpyrpsgakilz2rnh5f8gvrzq5pwzvndacc0df6m04bpqn5fx6sg"; - }) - (fetchurl { - url = "mirror://gcc/releases/gcc-${version}/gcc-g++-${version}.tar.bz2"; - sha256 = "14lxl81f7adpc9jxfiwzdxsdzs5zv4piv8xh7f9w910hfzrgvsby"; - }) - ]; - - patches = [ - ./no-sys-dirs.patch - (fetchpatch { - name = "siginfo.patch"; - url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/e36ee8ed9bb5942db14cf6249a2ead14974a2bfa/trunk/siginfo.patch"; - sha256 = "15zldbm33yba293dgrgsbv3j332hkc3iqpyc8fa7zl42mh9qk22j"; - extraPrefix = ""; - }) - (fetchpatch { - name = "gcc-3.4.3-no_multilib_amd64.patch"; - url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/e36ee8ed9bb5942db14cf6249a2ead14974a2bfa/trunk/gcc-3.4.3-no_multilib_amd64.patch"; - sha256 = "11m5lc51b0addhc4yq4rz0dwpv6k73rrj73wya3lqdk8rly6cjpm"; - extraPrefix = ""; - }) - # Required because of glibc 2.26 - ./struct-ucontext.patch - ]; - - postPatch = '' - # fix build issue with recent gcc - sed -i "s#O_CREAT#O_CREAT, 0666#" gcc/collect2.c - - # No fixincludes - sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in - ''; - - preConfigure = '' - mkdir ../build - cd ../build - configureScript=../$sourceRoot/configure - ''; - - preBuild = '' - # libstdc++ needs this; otherwise it will use /lib/cpp, which is a Bad - # Thing. - export CPP="gcc -E" - - # Use *real* header files, otherwise a limits.h is generated - # that does not include Glibc's limits.h (notably missing - # SSIZE_MAX, which breaks the build). - export NIX_FIXINC_DUMMY="$(cat $NIX_CC/nix-support/orig-libc-dev)/include" - - # The path to the Glibc binaries such as `crti.o'. - glibc_libdir="$(cat $NIX_CC/nix-support/orig-libc)/lib" - - # Figure out what extra flags to pass to the gcc compilers - # being generated to make sure that they use our glibc. - EXTRA_FLAGS="-I$NIX_FIXINC_DUMMY $(cat $NIX_CC/nix-support/libc-crt1-cflags) $(cat $NIX_CC/nix-support/libc-cflags) -O2" - - extraLDFlags="-L$glibc_libdir -rpath $glibc_libdir $(cat $NIX_BINTOOLS/nix-support/libc-ldflags) $(cat $NIX_BINTOOLS/nix-support/libc-ldflags-before)" - for i in $extraLDFlags; do - EXTRA_FLAGS="$EXTRA_FLAGS -Wl,$i" - done - - # CFLAGS_FOR_TARGET are needed for the libstdc++ configure script to find - # the startfiles. - # FLAGS_FOR_TARGET are needed for the target libraries to receive the -Bxxx - # for the startfiles. - makeFlagsArray=( \ - "''${makeFlagsArray[@]}" \ - NATIVE_SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ - SYSTEM_HEADER_DIR="$NIX_FIXINC_DUMMY" \ - CFLAGS_FOR_BUILD="$EXTRA_FLAGS" \ - CFLAGS_FOR_TARGET="$EXTRA_FLAGS" \ - CXXFLAGS_FOR_BUILD="$EXTRA_FLAGS" \ - CXXFLAGS_FOR_TARGET="$EXTRA_FLAGS" \ - FLAGS_FOR_TARGET="$EXTRA_FLAGS" \ - LDFLAGS_FOR_BUILD="$EXTRA_FLAGS" \ - LDFLAGS_FOR_TARGET="$EXTRA_FLAGS" \ - BOOT_CFLAGS="$EXTRA_FLAGS" \ - BOOT_LDFLAGS="$EXTRA_FLAGS" - ) - ''; - - hardeningDisable = [ "format" ]; - - nativeBuildInputs = [ flex bison file ]; - - configureFlags = [ "--disable-multilib" "--enable-__cxa-atexit" "--enable-threads=posix" "--enable-languages=c++" "--enable-clocale=gnu" ]; - - buildFLags = [ "all-target-libstdc++-v3" ]; - - installFlags = [ "install-target-libstdc++-v3" ]; - - postInstall = '' - # Remove includefiles and libs provided by gcc - shopt -s extglob - rm -rf $out/{bin,include,share,man,info} - rm -f $out/lib/*.a - rm -rf $out/lib/!(libstdc++*) - ''; - - meta = with lib; { - homepage = "https://gcc.gnu.org/"; - license = licenses.lgpl3Plus; - description = "GNU Compiler Collection, version ${version} -- C++ standard library"; - platforms = platforms.linux; - maintainers = with maintainers; [ abbradar ]; - }; -} diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index 18a6e2a473727..9a0802e29c5c7 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -69,6 +69,8 @@ in lib.init bootStages ++ [ then buildPackages.llvmPackages.clang else if crossSystem.useLLVM or false then buildPackages.llvmPackages.clangUseLLVM + else if crossSystem.useGccNg or false + then buildPackages.gccNgPackages.gcc else buildPackages.gcc; extraNativeBuildInputs = old.extraNativeBuildInputs diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index c5a2414377327..f4e11fb6c3dae 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -107,7 +107,19 @@ let ''; }; + forEachTest = f: lib.mapAttrs (_: mapMultiPlatformTest f) tests; + in { - gcc = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = false;})) tests); - llvm = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = true;})) tests); + gcc = forEachTest (system: system // { + useLLVM = false; + useGccNg = false; + }); + gccNg = forEachTest (system: system // { + useLLVM = false; + useGccNg = true; + }); + llvm = forEachTest (system: system // { + useLLVM = true; + useGccNg = false; + }); } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 30db04579be19..1a25af714a5e2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -46,26 +46,6 @@ with pkgs; lib.mapNullable (rs: rs ++ [ bintools ]) (stdenv.allowedRequisites or null); }; - stdenvNoLibs = - if stdenv.hostPlatform != stdenv.buildPlatform && (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isDarwin.useLLVM or false) - then - # We cannot touch binutils or cc themselves, because that will cause - # infinite recursion. So instead, we just choose a libc based on the - # current platform. That means we won't respect whatever compiler was - # passed in with the stdenv stage argument. - # - # TODO It would be much better to pass the `stdenvNoCC` and *unwrapped* - # cc, bintools, compiler-rt equivalent, etc. and create all final stdenvs - # as part of the stage. Then we would never be tempted to override a - # later thing to to create an earlier thing (leading to infinite - # recursion) and we also would still respect the stage arguments choices - # for these things. - overrideCC stdenv buildPackages.llvmPackages.clangNoCompilerRt - else mkStdenvNoLibs stdenv; - - gccStdenvNoLibs = mkStdenvNoLibs gccStdenv; - clangStdenvNoLibs = mkStdenvNoLibs clangStdenv; - # For convenience, allow callers to get the path to Nixpkgs. path = ../..; @@ -11069,7 +11049,10 @@ with pkgs; stripped = false; })); - gccCrossLibcStdenv = overrideCC stdenv buildPackages.gccCrossStageStatic; + gccCrossLibcStdenv = + if stdenv.hostPlatform.useGccNg or false + then overrideCC stdenv buildPackages.gccNgPackages.gccNoLibc + else overrideCC stdenv buildPackages.gccCrossStageStatic; crossLibcStdenv = if stdenv.hostPlatform.useLLVM or false || stdenv.hostPlatform.isDarwin @@ -11382,6 +11365,17 @@ with pkgs; gnatboot = wrapCC (callPackage ../development/compilers/gnatboot { }); + gccNgPackages = gccNgPackages_11; + + gccNgPackages_11 = recurseIntoAttrs (callPackage ../development/compilers/gcc-ng/11 ({ + inherit (stdenvAdapters) overrideCC; + # These are the default arguments, but do this to avoid splicing which was + # causing infinite recursion. + inherit bintools bintoolsNoLibc; + buildGccTools = buildPackages.gccNgPackages_11.tools; + targetGccLibraries = targetPackages.gccNgPackages_11.libraries; + })); + gnu-smalltalk = callPackage ../development/compilers/gnu-smalltalk { }; gccgo = gccgo6; @@ -13595,9 +13589,8 @@ with pkgs; librarian-puppet-go = callPackage ../development/tools/librarian-puppet-go { }; - libgcc = callPackage ../development/libraries/gcc/libgcc { - stdenvNoLibs = gccStdenvNoLibs; # cannot be built with clang it seems - }; + # TODO move to aliases + libgcc = gccNgPackages.libgcc; # This is for e.g. LLVM libraries on linux. gccForLibs = @@ -13610,8 +13603,6 @@ with pkgs; then targetPackages.stdenv.cc.cc else gcc.cc; - libstdcxx5 = callPackage ../development/libraries/gcc/libstdc++/5.nix { }; - libsigrok = callPackage ../development/tools/libsigrok { }; # old version: libsigrok_0_3 = libsigrok.override {