From 459c60dda2406d2207d2afd90f210ffc87efde54 Mon Sep 17 00:00:00 2001 From: Gaelan Steele Date: Tue, 26 May 2020 03:16:03 -0700 Subject: [PATCH] gcc: fix building darwin->linux cross compiler This reverts d9feea5 with some slight modifications to work with other changes since then. Fixes #88213. --- pkgs/development/compilers/gcc/4.8/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/4.9/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/6/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/7/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/8/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/9/default.nix | 15 +++++++++------ pkgs/development/compilers/gcc/builder.sh | 12 +++++++++++- 7 files changed, 65 insertions(+), 37 deletions(-) diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index ef697b74bbe3..b96f16aebb29 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -10,7 +10,7 @@ , enableLTO ? true , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man); required for Java -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , cloog ? null, isl ? null # optional, for the Graphite optimization framework. , zlib ? null, boehmgc ? null @@ -159,11 +159,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 270d118f97eb..4b30e3d83d4e 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -10,7 +10,7 @@ , enableLTO ? true , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man); required for Java -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , cloog ? null, isl ? null # optional, for the Graphite optimization framework. , zlib ? null, boehmgc ? null @@ -171,11 +171,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index b1a981cfdf7f..9772c9aa33a0 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -11,7 +11,7 @@ , texinfo ? null , flex , perl ? null # optional, for texi2pod (then pod2man); required for Java -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , isl ? null # optional, for the Graphite optimization framework. , zlib ? null, boehmgc ? null @@ -184,11 +184,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 22d772cff6d6..174d441c67e3 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -9,7 +9,7 @@ , enableLTO ? true , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , isl ? null # optional, for the Graphite optimization framework. , zlib ? null @@ -155,11 +155,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 58248093d24d..0187a73d8131 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -9,7 +9,7 @@ , enableLTO ? true , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , isl ? null # optional, for the Graphite optimization framework. , zlib ? null @@ -147,11 +147,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index f660a59a790a..bb97c79351af 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -9,7 +9,7 @@ , enableLTO ? true , texinfo ? null , perl ? null # optional, for texi2pod (then pod2man) -, gmp, mpfr, libmpc, gettext, which +, gmp, mpfr, libmpc, gettext, which, patchelf , libelf # optional, for link-time optimizations (LTO) , isl ? null # optional, for the Graphite optimization framework. , zlib ? null @@ -146,11 +146,14 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = - if hostPlatform == buildPlatform then [ - targetPackages.stdenv.cc.bintools # newly-built gcc will be used - ] else assert targetPlatform == hostPlatform; [ # build != host == target - stdenv.cc - ]; + ( + if hostPlatform == buildPlatform then [ + targetPackages.stdenv.cc.bintools # newly-built gcc will be used + ] else assert targetPlatform == hostPlatform; [ # build != host == target + stdenv.cc + ] + ) + ++ optional targetPlatform.isLinux patchelf; buildInputs = [ gmp mpfr libmpc libelf diff --git a/pkgs/development/compilers/gcc/builder.sh b/pkgs/development/compilers/gcc/builder.sh index b153687980a0..d17ad7bf747e 100644 --- a/pkgs/development/compilers/gcc/builder.sh +++ b/pkgs/development/compilers/gcc/builder.sh @@ -240,7 +240,7 @@ postInstall() { # More dependencies with the previous gcc or some libs (gccbug stores the build command line) rm -rf $out/bin/gccbug - if type "patchelf"; then + if [[ buildConfig == *"linux"* ]]; then # Take out the bootstrap-tools from the rpath, as it's not needed at all having $out for i in $(find "$out"/libexec/gcc/*/*/* -type f -a \! -name '*.la'); do PREV_RPATH=`patchelf --print-rpath "$i"` @@ -249,6 +249,16 @@ postInstall() { done fi + if [[ targetConfig == *"linux"* ]]; then + # For some reason, when building for linux on darwin, the libs retain + # RPATH to $out. + for i in "$lib"/"$targetConfig"/lib/{libtsan,libasan,libubsan}.so.*.*.*; do + PREV_RPATH=`patchelf --print-rpath "$i"` + NEW_RPATH=`echo "$PREV_RPATH" | sed "s,:${out}[^:]*,,g"` + patchelf --set-rpath "$NEW_RPATH" "$i" && echo OK + done + fi + if type "install_name_tool"; then for i in "$lib"/lib/*.*.dylib; do install_name_tool -id "$i" "$i" || true