From 6980e6b35aacccd4e75a76a384f9dec30f31fa55 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 28 Jun 2023 23:49:38 -0700 Subject: [PATCH 1/2] lib.systems: introduce hasSharedLibraries This commit adds `hasSharedLibraries` to `lib.systems`. We need `plat.hasSharedLibraries` in order to know whether or not to expect `gcc` (and many other tools) to emit shared libraries (like `libgcc_s.so`). Many of the GNU build scripts are smart enough that if you configure them with `--enable-shared` on a platform (such as `arm-none-eabi`) that doesn't support dynamic linking, they will simply skip the shared libraries instead of aborting the `configurePhase`. Unfortunately the missing shared libraries in the final build product cause very hard-to-troubleshoot problems later on. The alternative to introducing `hasSharedLibraries` would be to set `isStatic` in these situations. However doing so causes `make-derivation.nix` to insert `-static` between the `pname` and `hostPlatform` suffix, which is undesirable. If at some point in the future we eliminate the `-static` suffix, then `hasSharedLibraries` can be made equal to `!isStatic`. --- lib/systems/default.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 78ccd50ba79a5..a3462d2d424b2 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` From e41f217257cf34d1328cad141cfb01c6f8093b37 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 28 Jun 2023 23:59:59 -0700 Subject: [PATCH 2/2] gcc: use hasSharedLibraries instead of isStatic --- pkgs/development/compilers/gcc/10/default.nix | 6 +++--- pkgs/development/compilers/gcc/11/default.nix | 6 +++--- pkgs/development/compilers/gcc/12/default.nix | 6 +++--- pkgs/development/compilers/gcc/13/default.nix | 6 +++--- pkgs/development/compilers/gcc/4.8/default.nix | 6 +++--- pkgs/development/compilers/gcc/4.9/default.nix | 6 +++--- pkgs/development/compilers/gcc/6/default.nix | 6 +++--- pkgs/development/compilers/gcc/7/default.nix | 6 +++--- pkgs/development/compilers/gcc/8/default.nix | 6 +++--- pkgs/development/compilers/gcc/9/default.nix | 6 +++--- pkgs/development/compilers/gcc/common/libgcc.nix | 3 +++ 11 files changed, 33 insertions(+), 30 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index c1f6f061f8cd1..d384298993728 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 @@ -295,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index 47662d5002c43..14073c6a05bcc 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 @@ -307,6 +307,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 enableShared crossStageStatic; }) (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 e3ad55ae90ca8..be3fde0649e15 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 @@ -353,7 +353,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 enableShared crossStageStatic; }) (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 b6f83f2662bfa..c1834ead11eee 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 @@ -347,7 +347,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 enableShared crossStageStatic; }) (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 27fa2160c1299..36359b213c78d 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 @@ -323,5 +323,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 2477f53b9caa0..d708d0d442449 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 @@ -350,5 +350,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 61874359b2a31..ba8bcf5342a32 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 @@ -368,5 +368,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 19010a578ac4f..a93d3c491b584 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 @@ -302,5 +302,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index f06b60ba6df6d..1f913fe57d359 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 @@ -277,5 +277,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index d022349c73a1f..79ca57e2f72c3 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 @@ -292,5 +292,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 enableShared crossStageStatic; }) ] diff --git a/pkgs/development/compilers/gcc/common/libgcc.nix b/pkgs/development/compilers/gcc/common/libgcc.nix index 2477a6811aa11..29ec421555ed0 100644 --- a/pkgs/development/compilers/gcc/common/libgcc.nix +++ b/pkgs/development/compilers/gcc/common/libgcc.nix @@ -7,8 +7,11 @@ , targetPlatform , hostPlatform , crossStageStatic +, enableShared }: +assert !stdenv.targetPlatform.hasSharedLibraries -> !enableShared; + drv: lib.pipe drv ([