diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 78ccd50ba79a..a3462d2d424b 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -86,7 +86,7 @@ rec { # choice. else "bfd"; extensions = rec { - sharedLibrary = + sharedLibrary = assert final.hasSharedLibraries; /**/ if final.isDarwin then ".dylib" else if final.isWindows then ".dll" else ".so"; @@ -132,6 +132,25 @@ rec { # uname -r release = null; }; + + # It is important that hasSharedLibraries==false when the platform has no + # dynamic library loader. Various tools (including the gcc build system) + # have knowledge of which platforms are incapable of dynamic linking, and + # will still build on/for those platforms with --enable-shared, but simply + # omit any `.so` build products such as libgcc_s.so. When that happens, + # it causes hard-to-troubleshoot build failures. + hasSharedLibraries = with final; + (isAndroid || isGnu || isMusl # Linux (allows multiple libcs) + || isDarwin || isSunOS || isOpenBSD || isFreeBSD || isNetBSD # BSDs + || isCygwin || isMinGW # Windows + ) && !isStatic; + + # The difference between `isStatic` and `hasSharedLibraries` is mainly the + # addition of the `staticMarker` (see make-derivation.nix). Some + # platforms, like embedded machines without a libc (e.g. arm-none-eabi) + # don't support dynamic linking, but don't get the `staticMarker`. + # `pkgsStatic` sets `isStatic=true`, so `pkgsStatic.hostPlatform` always + # has the `staticMarker`. isStatic = final.isWasm || final.isRedox; # Just a guess, based on `system` diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index c1f6f061f8cd..739b6d2e2c1d 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -22,7 +22,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog ? null # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -69,7 +69,7 @@ let majorVersion = "10"; ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch ++ optional (buildPlatform.system == "aarch64-darwin" && targetPlatform != buildPlatform) (fetchpatch { url = "https://raw.githubusercontent.com/richard-vd/musl-cross-make/5e9e87f06fc3220e102c29d3413fbbffa456fcd6/patches/gcc-${version}/0008-darwin-aarch64-self-host-driver.patch"; @@ -78,7 +78,7 @@ let majorVersion = "10"; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -99,7 +99,7 @@ let majorVersion = "10"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -214,7 +214,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -295,5 +298,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index 47662d5002c4..ca4540b8c713 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -22,7 +22,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -82,14 +82,14 @@ let majorVersion = "11"; ++ optional (stdenv.isDarwin && targetPlatform.isAvr) ./avr-gcc-11.3-darwin.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch # openjdk build fails without this on -march=opteron; is upstream in gcc12 ++ [ ./gcc-issue-103910.patch ]; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -110,7 +110,7 @@ let majorVersion = "11"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -227,7 +227,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -307,6 +310,6 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index e3ad55ae90ca..ebc1796ec385 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -23,7 +23,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -127,11 +127,11 @@ let majorVersion = "12"; ++ optional (stdenv.isDarwin && langAda) ../gnat-darwin-dylib-install-name.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch; + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -152,7 +152,7 @@ let majorVersion = "12"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc disableBootstrap disableGdbPlugin enableLTO @@ -271,7 +271,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; @@ -353,7 +356,7 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/13/default.nix b/pkgs/development/compilers/gcc/13/default.nix index b6f83f2662bf..5fb78cfd7b40 100644 --- a/pkgs/development/compilers/gcc/13/default.nix +++ b/pkgs/development/compilers/gcc/13/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -23,7 +23,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -125,7 +125,7 @@ let majorVersion = "13"; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -146,7 +146,7 @@ let majorVersion = "13"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc disableBootstrap disableGdbPlugin enableLTO @@ -265,7 +265,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; @@ -347,7 +350,7 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) (callPackage ../common/checksum.nix { inherit langC langCC; }) ] diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 27fa2160c129..3625257efe9a 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -8,8 +8,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man); required for Java , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -26,7 +26,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , buildPackages , callPackage @@ -109,7 +109,7 @@ let majorVersion = "4"; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -135,7 +135,7 @@ let majorVersion = "4"; boehmgc buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -232,7 +232,10 @@ lib.pipe (stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler langJava libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -323,5 +326,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 2477f53b9caa..e433e66b9f69 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -8,8 +8,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man); required for Java , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -26,7 +26,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , buildPackages , callPackage @@ -126,7 +126,7 @@ let majorVersion = "4"; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -152,7 +152,7 @@ let majorVersion = "4"; boehmgc buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -253,7 +253,10 @@ lib.pipe (stdenv.mkDerivation ({ '' else null; - inherit noSysDirs staticCompiler langJava crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler langJava libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -350,5 +353,5 @@ lib.pipe (stdenv.mkDerivation ({ '';} )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 61874359b2a3..f64963b906cf 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , flex , perl ? null # optional, for texi2pod (then pod2man); required for Java @@ -29,7 +29,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog ? null # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -78,7 +78,7 @@ let majorVersion = "6"; ++ optional langGo ./gogcc-workaround-glibc-2.36.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch ++ optional (targetPlatform.libc == "musl" && targetPlatform.isx86_32) (fetchpatch { url = "https://git.alpinelinux.org/aports/plain/main/gcc/gcc-6.1-musl-libssp.patch?id=5e4b96e23871ee28ef593b439f8c07ca7c7eb5bb"; sha256 = "1jf1ciz4gr49lwyh8knfhw6l5gvfkwzjy90m7qiwkcbsf4a3fqn2"; @@ -111,7 +111,7 @@ let majorVersion = "6"; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -137,7 +137,7 @@ let majorVersion = "6"; boehmgc buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -269,7 +269,10 @@ lib.pipe (stdenv.mkDerivation ({ )) ); - inherit noSysDirs staticCompiler langJava crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler langJava libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -368,5 +371,5 @@ lib.pipe (stdenv.mkDerivation ({ '';} )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 19010a578ac4..90785143f05e 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -7,8 +7,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -19,7 +19,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog ? null # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -81,13 +81,13 @@ let majorVersion = "7"; ++ optional (targetPlatform.libc == "musl") ../libgomp-dont-force-initial-exec.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch ++ [ ../libsanitizer-no-cyclades-9.patch ]; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -108,7 +108,7 @@ let majorVersion = "7"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -218,7 +218,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -302,5 +305,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index f06b60ba6df6..29f0a88c9551 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -7,8 +7,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -19,7 +19,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog ? null # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -63,12 +63,12 @@ let majorVersion = "8"; ++ optional (targetPlatform.libc == "musl") ../libgomp-dont-force-initial-exec.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch ++ [ ../libsanitizer-no-cyclades-9.patch ]; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -89,7 +89,7 @@ let majorVersion = "8"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -199,7 +199,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -277,5 +280,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } )) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index d022349c73a1..29e4117fc6a7 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -9,8 +9,8 @@ , profiledCompiler ? false , langJit ? false , staticCompiler ? false -, enableShared ? !stdenv.targetPlatform.isStatic -, enableLTO ? !stdenv.hostPlatform.isStatic +, enableShared ? stdenv.targetPlatform.hasSharedLibraries +, enableLTO ? stdenv.hostPlatform.hasSharedLibraries , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) , gmp, mpfr, libmpc, gettext, which, patchelf, binutils @@ -22,7 +22,7 @@ , name ? "gcc" , libcCross ? null , threadsCross ? null # for MinGW -, crossStageStatic ? false +, withoutTargetLibc ? false , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -74,12 +74,12 @@ let majorVersion = "9"; ++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch # Obtain latest patch with ../update-mcfgthread-patches.sh - ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch + ++ optional (!withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch ; /* Cross-gcc settings (build == host != target) */ crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt"; - stageNameAddon = if crossStageStatic then "stage-static" else "stage-final"; + stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final"; crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-"; callFile = lib.callPackageWith { @@ -100,7 +100,7 @@ let majorVersion = "9"; binutils buildPackages cloog - crossStageStatic + withoutTargetLibc enableLTO enableMultilib enablePlugin @@ -213,7 +213,10 @@ lib.pipe (stdenv.mkDerivation ({ ) ''; - inherit noSysDirs staticCompiler crossStageStatic + # kludge to prevent a mass-rebuild; will be removed in a PR sent to staging + crossStageStatic = withoutTargetLibc; + + inherit noSysDirs staticCompiler libcCross crossMingw; inherit (callFile ../common/dependencies.nix { }) @@ -292,5 +295,5 @@ lib.pipe (stdenv.mkDerivation ({ // optionalAttrs (enableMultilib) { dontMoveLib64 = true; } ) ) [ - (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform crossStageStatic; }) + (callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; }) ] diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index aa8ecc62e55a..a60a3380ea25 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -1,7 +1,7 @@ { lib, stdenv , targetPackages -, crossStageStatic, libcCross +, withoutTargetLibc, libcCross , threadsCross , version @@ -59,14 +59,14 @@ let "--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as" "--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld" ] - ++ (if crossStageStatic then [ + ++ (if withoutTargetLibc then [ "--disable-libssp" "--disable-nls" "--without-headers" "--disable-threads" "--disable-libgomp" "--disable-libquadmath" - "--disable-shared" + (lib.enableFeature enableShared "shared") "--disable-libatomic" # requires libc "--disable-decimal-float" # requires libc "--disable-libmpx" # requires libc @@ -112,7 +112,7 @@ let "--with-mpfr-lib=${mpfr.out}/lib" "--with-mpc=${libmpc}" ] - ++ lib.optionals (!crossStageStatic) [ + ++ lib.optionals (!withoutTargetLibc) [ (if libcCross == null then "--with-native-system-header-dir=${lib.getDev stdenv.cc.libc}/include" else "--with-native-system-header-dir=${lib.getDev libcCross}${libcCross.incdir or "/include"}") diff --git a/pkgs/development/compilers/gcc/common/dependencies.nix b/pkgs/development/compilers/gcc/common/dependencies.nix index 72aa0defcc6f..a38cdcb9e20f 100644 --- a/pkgs/development/compilers/gcc/common/dependencies.nix +++ b/pkgs/development/compilers/gcc/common/dependencies.nix @@ -30,7 +30,7 @@ , javaAwtGtk ? false , langAda ? false , langGo ? false -, crossStageStatic ? null +, withoutTargetLibc ? null , threadsCross ? null }: @@ -88,5 +88,5 @@ in ; # threadsCross.package after gcc6 so i assume its okay for 4.8 and 4.9 too - depsTargetTarget = optionals (!crossStageStatic && threadsCross != { } && threadsCross.package != null) [ threadsCross.package ]; + depsTargetTarget = optionals (!withoutTargetLibc && threadsCross != { } && threadsCross.package != null) [ threadsCross.package ]; } diff --git a/pkgs/development/compilers/gcc/common/extra-target-flags.nix b/pkgs/development/compilers/gcc/common/extra-target-flags.nix index 4dedd333b002..30a24185e3b4 100644 --- a/pkgs/development/compilers/gcc/common/extra-target-flags.nix +++ b/pkgs/development/compilers/gcc/common/extra-target-flags.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, crossStageStatic, langD ? false, libcCross, threadsCross }: +{ lib, stdenv, withoutTargetLibc, langD ? false, libcCross, threadsCross }: let inherit (stdenv) hostPlatform targetPlatform; @@ -11,23 +11,23 @@ in EXTRA_FLAGS_FOR_TARGET = let mkFlags = dep: langD: lib.optionals (targetPlatform != hostPlatform && dep != null && !langD) ([ "-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}" - ] ++ lib.optionals (! crossStageStatic) [ + ] ++ lib.optionals (! withoutTargetLibc) [ "-B${lib.getLib dep}${dep.libdir or "/lib"}" ]); in mkFlags libcCross langD - ++ lib.optionals (!crossStageStatic) (mkFlags (threadsCross.package or null) langD) + ++ lib.optionals (!withoutTargetLibc) (mkFlags (threadsCross.package or null) langD) ; EXTRA_LDFLAGS_FOR_TARGET = let mkFlags = dep: lib.optionals (targetPlatform != hostPlatform && dep != null) ([ "-Wl,-L${lib.getLib dep}${dep.libdir or "/lib"}" - ] ++ (if crossStageStatic then [ + ] ++ (if withoutTargetLibc then [ "-B${lib.getLib dep}${dep.libdir or "/lib"}" ] else [ "-Wl,-rpath,${lib.getLib dep}${dep.libdir or "/lib"}" "-Wl,-rpath-link,${lib.getLib dep}${dep.libdir or "/lib"}" ])); in mkFlags libcCross - ++ lib.optionals (!crossStageStatic) (mkFlags (threadsCross.package or null)) + ++ lib.optionals (!withoutTargetLibc) (mkFlags (threadsCross.package or null)) ; } diff --git a/pkgs/development/compilers/gcc/common/libgcc.nix b/pkgs/development/compilers/gcc/common/libgcc.nix index 2477a6811aa1..528d9d7d13ac 100644 --- a/pkgs/development/compilers/gcc/common/libgcc.nix +++ b/pkgs/development/compilers/gcc/common/libgcc.nix @@ -4,11 +4,14 @@ , langC , langCC , langJit +, enableShared , targetPlatform , hostPlatform -, crossStageStatic +, withoutTargetLibc }: +assert !stdenv.targetPlatform.hasSharedLibraries -> !enableShared; + drv: lib.pipe drv ([ @@ -16,8 +19,8 @@ drv: lib.pipe drv (pkg: pkg.overrideAttrs (previousAttrs: lib.optionalAttrs ( targetPlatform != hostPlatform && - targetPlatform.libc == "msvcrt" && - crossStageStatic + enableShared && + withoutTargetLibc ) { makeFlags = [ "all-gcc" "all-target-libgcc" ]; installTargets = "install-gcc install-target-libgcc"; @@ -31,11 +34,15 @@ drv: lib.pipe drv lib.optional (lib.versionAtLeast version "11.0") (let + targetPlatformSlash = + if hostPlatform.config == targetPlatform.config + then "" + else "${targetPlatform.config}/"; + enableLibGccOutput = - (with stdenv; targetPlatform == hostPlatform) && !langJit && !stdenv.hostPlatform.isDarwin && - !stdenv.hostPlatform.isStatic + enableShared ; in @@ -50,6 +57,10 @@ in lib.optionalString (!langC) '' rm -f $out/lib/libgcc_s.so* '' + + lib.optionalString (hostPlatform.config != targetPlatform.config) '' + mkdir -p $lib/lib/ + ln -s ${targetPlatformSlash}lib $lib/lib + '' # TODO(amjoseph): remove the `libgcc_s.so` symlinks below and replace them # with a `-L${gccForLibs.libgcc}/lib` in cc-wrapper's @@ -62,10 +73,10 @@ in + lib.optionalString enableLibGccOutput ('' # move libgcc from lib to its own output (libgcc) mkdir -p $libgcc/lib - mv $lib/lib/libgcc_s.so $libgcc/lib/ - mv $lib/lib/libgcc_s.so.1 $libgcc/lib/ - ln -s $libgcc/lib/libgcc_s.so $lib/lib/ - ln -s $libgcc/lib/libgcc_s.so.1 $lib/lib/ + mv $lib/${targetPlatformSlash}lib/libgcc_s.so $libgcc/lib/ + mv $lib/${targetPlatformSlash}lib/libgcc_s.so.1 $libgcc/lib/ + ln -s $libgcc/lib/libgcc_s.so $lib/${targetPlatformSlash}lib/ + ln -s $libgcc/lib/libgcc_s.so.1 $lib/${targetPlatformSlash}lib/ '' # # Nixpkgs ordinarily turns dynamic linking into pseudo-static linking: diff --git a/pkgs/development/compilers/gcc/common/pre-configure.nix b/pkgs/development/compilers/gcc/common/pre-configure.nix index 58e44b96b5d3..2561246a66f9 100644 --- a/pkgs/development/compilers/gcc/common/pre-configure.nix +++ b/pkgs/development/compilers/gcc/common/pre-configure.nix @@ -1,10 +1,13 @@ -{ lib, version, buildPlatform, hostPlatform, targetPlatform +{ lib +, stdenv +, version, buildPlatform, hostPlatform, targetPlatform , gnat-bootstrap ? null , langAda ? false , langJava ? false , langJit ? false , langGo -, crossStageStatic +, withoutTargetLibc +, enableShared , enableMultilib }: @@ -105,10 +108,21 @@ in lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) '' # gcc->clang "cross"-compilation manages to evade it: there # hostPlatform != targetPlatform, hostPlatform.config == targetPlatform.config. # We explicitly inhibit libc headers use in this case as well. -+ lib.optionalString (targetPlatform != hostPlatform && crossStageStatic) '' ++ lib.optionalString (targetPlatform != hostPlatform && withoutTargetLibc) '' export inhibit_libc=true '' +# Trick to build a gcc that is capable of emitting shared libraries *without* having the +# targetPlatform libc available beforehand. Taken from: +# https://web.archive.org/web/20170222224855/http://frank.harvard.edu/~coldwell/toolchain/ +# https://web.archive.org/web/20170224235700/http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff ++ lib.optionalString (targetPlatform != hostPlatform && withoutTargetLibc && enableShared) + (lib.optionalString (!stdenv.targetPlatform.isPower) '' + echo 'libgcc.a: crti.o crtn.o' >> libgcc/Makefile.in + '' + '' + echo 'SHLIB_LC=' >> libgcc/Makefile.in + '') + + lib.optionalString (!enableMultilib && hostPlatform.is64bit && !hostPlatform.isMips64n32) '' export linkLib64toLib=1 '' diff --git a/pkgs/os-specific/windows/default.nix b/pkgs/os-specific/windows/default.nix index 8d6dd50548e5..12859de8a20f 100644 --- a/pkgs/os-specific/windows/default.nix +++ b/pkgs/os-specific/windows/default.nix @@ -20,7 +20,7 @@ lib.makeScope newScope (self: with self; { crossThreadsStdenv = overrideCC crossLibcStdenv (if stdenv.hostPlatform.useLLVM or false then buildPackages.llvmPackages_8.clangNoLibcxx - else buildPackages.gccCrossStageStatic.override (old: { + else buildPackages.gccWithoutTargetLibc.override (old: { bintools = old.bintools.override { libc = libcCross; }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c585a3a0eeb4..1be627caecdb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14417,7 +14417,7 @@ with pkgs; xbursttools = callPackage ../tools/misc/xburst-tools { # It needs a cross compiler for mipsel to build the firmware it will # load into the Ben Nanonote - gccCross = pkgsCross.ben-nanonote.buildPackages.gccCrossStageStatic; + gccCross = pkgsCross.ben-nanonote.buildPackages.gccWithoutTargetLibc; autoconf = buildPackages.autoconf269; }; @@ -15339,7 +15339,7 @@ with pkgs; dontStrip = true; })); - gccCrossLibcStdenv = overrideCC stdenv buildPackages.gccCrossStageStatic; + gccCrossLibcStdenv = overrideCC stdenv buildPackages.gccWithoutTargetLibc; crossLibcStdenv = if stdenv.hostPlatform.useLLVM or false || stdenv.hostPlatform.isDarwin @@ -15348,7 +15348,7 @@ with pkgs; # The GCC used to build libc for the target platform. Normal gccs will be # built with, and use, that cross-compiled libc. - gccCrossStageStatic = assert stdenv.targetPlatform != stdenv.hostPlatform; let + gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let libcCross1 = binutilsNoLibc.libc; in wrapCCWith { cc = gccFun { @@ -15360,12 +15360,10 @@ with pkgs; isl = if !stdenv.isDarwin then isl_0_20 else null; - # just for stage static - crossStageStatic = true; + withoutTargetLibc = true; langCC = false; libcCross = libcCross1; targetPackages.stdenv.cc.bintools = binutilsNoLibc; - enableShared = false; }; bintools = binutilsNoLibc; libc = libcCross1;