Skip to content

Commit

Permalink
gcc: withoutTargetLibc: build libgcc_s.so
Browse files Browse the repository at this point in the history
We want a `libgcc_s.so` to be built by the first stage
cross-compiler (withoutTargetLibc), since that is the compiler which
will compile the target libc.

This commit accomplishes that, by making three changes:

1. Replacing the `targetPlatform.libc == "msvcrt" &&` conditional
   with `enableShared`, so that the code which cross-build
   `libgcc_s.so` is used for all cross compilers capable of emitting
   shared libraries.

2. Removing the `targetPlatform == hostPlatform` guard from the code
   which produces the `libgcc` output.

3. Looking for build products in in "lib/${targetPlatform.config}/"
   rather than "lib/", so we will find them when cross compiling.
  • Loading branch information
Adam Joseph committed Jul 1, 2023
1 parent 443dfc4 commit 63305d0
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/10/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,5 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,6 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
(callPackage ../common/checksum.nix { inherit langC langCC; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/12/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
(callPackage ../common/checksum.nix { inherit langC langCC; })
]

2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/13/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
(callPackage ../common/checksum.nix { inherit langC langCC; })
]

2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/4.8/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/4.9/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,5 @@ lib.pipe (stdenv.mkDerivation ({
'';}
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,5 @@ lib.pipe (stdenv.mkDerivation ({
'';}
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/7/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,5 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/8/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,5 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
))
[
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/9/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,5 @@ lib.pipe (stdenv.mkDerivation ({
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
)
) [
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc; })
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
]
1 change: 1 addition & 0 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ let
"--disable-threads"
"--disable-libgomp"
"--disable-libquadmath"
(lib.enableFeature enableShared "shared")
"--disable-libatomic" # requires libc
"--disable-decimal-float" # requires libc
"--disable-libmpx" # requires libc
Expand Down
23 changes: 16 additions & 7 deletions pkgs/development/compilers/gcc/common/libgcc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
, langC
, langCC
, langJit
, enableShared
, targetPlatform
, hostPlatform
, withoutTargetLibc
Expand All @@ -18,7 +19,7 @@ drv: lib.pipe drv
(pkg: pkg.overrideAttrs (previousAttrs:
lib.optionalAttrs (
targetPlatform != hostPlatform &&
targetPlatform.libc == "msvcrt" &&
enableShared &&
withoutTargetLibc
) {
makeFlags = [ "all-gcc" "all-target-libgcc" ];
Expand All @@ -33,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
Expand All @@ -52,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
Expand All @@ -64,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:
Expand Down

0 comments on commit 63305d0

Please sign in to comment.