From 17f413f2930f90d0f5de1121f310693c31a7cd0e Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 22 Jul 2022 18:38:02 +0100 Subject: [PATCH 1/4] setup-hooks/strip.sh: use STRIP_FOR_TARGET, not TARGET_STRIP Since 1ac53985 "*-wrapper; Switch from `infixSalt` to `suffixSalt`" (2020) 'TARGET_' prefix (and infix) is no more. '_FOR_TARGET' suffix is the only used suffix for target-specific tools and flags. Use that in stip instead of always-empty variable. --- pkgs/build-support/setup-hooks/strip.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index 2d8e66a89fa3..a23b203aff56 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -7,10 +7,10 @@ _doStrip() { # to $out anyways---if it does, that's a bigger problem that a lack of # stripping will help catch. local -ra flags=(dontStripHost dontStripTarget) - local -ra stripCmds=(STRIP TARGET_STRIP) + local -ra stripCmds=(STRIP STRIP_FOR_TARGET) # Optimization - if [[ "${STRIP-}" == "${TARGET_STRIP-}" ]]; then + if [[ "${STRIP-}" == "${STRIP_FOR_TARGET-}" ]]; then dontStripTarget+=1 fi From 0f45ce6e777e2cca2ade01176c19bc66cfe4b5c7 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 22 Jul 2022 21:22:50 +0100 Subject: [PATCH 2/4] setup-hooks/strip.sh: add strip{All,Debug}ListTarget variables This change mimics existing strip{All,Debug}List variables to allow special stripping directories just for Target. The primary use case in mind is gcc where package has to install both host and target ELFs. They have to be stripped by their own strip tools accordingly. Co-authored-by: Rick van Schijndel Co-authored-by: Sandro --- doc/stdenv/stdenv.chapter.md | 8 ++++++++ pkgs/build-support/setup-hooks/strip.sh | 27 +++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index 5f7f45dc4437..958747d34046 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -731,6 +731,10 @@ If set, files in `$out/sbin` are not moved to `$out/bin`. By default, they are. List of directories to search for libraries and executables from which *all* symbols should be stripped. By default, it’s empty. Stripping all symbols is risky, since it may remove not just debug symbols but also ELF information necessary for normal execution. +##### `stripAllListTarget` {#var-stdenv-stripAllListTarget} + +Like `stripAllList`, but only applies to packages’ target platform. By default, it’s empty. Useful when supporting cross compilation. + ##### `stripAllFlags` {#var-stdenv-stripAllFlags} Flags passed to the `strip` command applied to the files in the directories listed in `stripAllList`. Defaults to `-s` (i.e. `--strip-all`). @@ -739,6 +743,10 @@ Flags passed to the `strip` command applied to the files in the directories list List of directories to search for libraries and executables from which only debugging-related symbols should be stripped. It defaults to `lib lib32 lib64 libexec bin sbin`. +##### `stripDebugListTarget` {#var-stdenv-stripDebugListTarget} + +Like `stripDebugList`, but only applies to packages’ target platform. By default, it’s empty. Useful when supporting cross compilation. + ##### `stripDebugFlags` {#var-stdenv-stripDebugFlags} Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`). diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index a23b203aff56..9d0b163f4c46 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -7,31 +7,29 @@ _doStrip() { # to $out anyways---if it does, that's a bigger problem that a lack of # stripping will help catch. local -ra flags=(dontStripHost dontStripTarget) + local -ra debugDirs=(stripDebugList stripDebugListTarget) + local -ra allDirs=(stripAllList stripAllListTarget) local -ra stripCmds=(STRIP STRIP_FOR_TARGET) - # Optimization - if [[ "${STRIP-}" == "${STRIP_FOR_TARGET-}" ]]; then - dontStripTarget+=1 - fi + # Strip only host paths by default. Leave targets as is. + stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} + stripDebugListTarget=${stripDebugListTarget:-} + stripAllList=${stripAllList:-} + stripAllListTarget=${stripAllListTarget:-} local i for i in ${!stripCmds[@]}; do local -n flag="${flags[$i]}" + local -n debugDirList="${debugDirs[$i]}" + local -n allDirList="${allDirs[$i]}" local -n stripCmd="${stripCmds[$i]}" # `dontStrip` disables them all if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null then continue; fi - stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} - if [ -n "$stripDebugList" ]; then - stripDirs "$stripCmd" "$stripDebugList" "${stripDebugFlags:--S}" - fi - - stripAllList=${stripAllList:-} - if [ -n "$stripAllList" ]; then - stripDirs "$stripCmd" "$stripAllList" "${stripAllFlags:--s}" - fi + stripDirs "$stripCmd" "$debugDirList" "${stripDebugFlags:--S}" + stripDirs "$stripCmd" "$allDirList" "${stripAllFlags:--s}" done } @@ -50,8 +48,7 @@ stripDirs() { dirs=${dirsNew} if [ -n "${dirs}" ]; then - header "stripping (with command $cmd and flags $stripFlags) in$dirs" + echo "stripping (with command $cmd and flags $stripFlags) in$dirs" find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null - stopNest fi } From 05077250615fa33003eada31a76b36c0717d8ca4 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sat, 23 Jul 2022 10:02:51 +0100 Subject: [PATCH 3/4] setup-hooks/strip.sh: run RANLIB on static archives after stripping 'strip' does not normally preserve archive index in .a files. This usually causes linking failures against static libs like: $ nix build --no-link -f. pkgsCross.mingw32.re2c > ...-i686-w64-mingw32-binutils-2.38/bin/i686-w64-mingw32-ld: /nix/store/...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a: error adding symbols: archive has no index; run ranlib to add one We restore the index by running ranlib explicitly. --- pkgs/build-support/setup-hooks/strip.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index 9d0b163f4c46..80bc064ced7d 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -10,6 +10,7 @@ _doStrip() { local -ra debugDirs=(stripDebugList stripDebugListTarget) local -ra allDirs=(stripAllList stripAllListTarget) local -ra stripCmds=(STRIP STRIP_FOR_TARGET) + local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET) # Strip only host paths by default. Leave targets as is. stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} @@ -23,20 +24,22 @@ _doStrip() { local -n debugDirList="${debugDirs[$i]}" local -n allDirList="${allDirs[$i]}" local -n stripCmd="${stripCmds[$i]}" + local -n ranlibCmd="${ranlibCmds[$i]}" # `dontStrip` disables them all if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null then continue; fi - stripDirs "$stripCmd" "$debugDirList" "${stripDebugFlags:--S}" - stripDirs "$stripCmd" "$allDirList" "${stripAllFlags:--s}" + stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags:--S}" + stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags:--s}" done } stripDirs() { local cmd="$1" - local dirs="$2" - local stripFlags="$3" + local ranlibCmd="$2" + local dirs="$3" + local stripFlags="$4" local dirsNew= local d @@ -50,5 +53,11 @@ stripDirs() { if [ -n "${dirs}" ]; then echo "stripping (with command $cmd and flags $stripFlags) in$dirs" find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null + # 'strip' does not normally preserve archive index in .a files. + # This usually causes linking failures against static libs like: + # ld: ...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a: + # error adding symbols: archive has no index; run ranlib to add one + # Restore the index by running 'ranlib'. + find $dirs -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null fi } From eece5d0dc0bbd7eaab1f09e608f89449f745003b Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 22 Jul 2022 21:40:08 +0100 Subject: [PATCH 4/4] gcc: enable stripping for cross-compilers With explicit support for distinction between Host and Target strip paths we can now safely strip ELF binaries with their according strip tools without fear of damaging binaries due to architecture mismatch. Closure size change for `pkgsCross.mingwW64.gcc12Stdenv.cc.cc`: # before: $ nix path-info -Sh $(nix-build -A pkgsCross.mingwW64.gcc12Stdenv.cc.cc) | unnix /<>/x86_64-w64-mingw32-stage-final-gcc-debug-12.1.0 2.5G # after: $ nix path-info -Sh $(nix-build -A pkgsCross.mingwW64.gcc12Stdenv.cc.cc) | unnix /<>/x86_64-w64-mingw32-stage-final-gcc-12.1.0 1.5G --- pkgs/development/compilers/gcc/10/default.nix | 16 +++--- pkgs/development/compilers/gcc/11/default.nix | 16 +++--- pkgs/development/compilers/gcc/12/default.nix | 16 +++--- .../development/compilers/gcc/4.8/default.nix | 16 +++--- .../development/compilers/gcc/4.9/default.nix | 16 +++--- pkgs/development/compilers/gcc/6/default.nix | 16 +++--- pkgs/development/compilers/gcc/7/default.nix | 16 +++--- pkgs/development/compilers/gcc/8/default.nix | 16 +++--- pkgs/development/compilers/gcc/9/default.nix | 16 +++--- pkgs/development/compilers/gcc/builder.sh | 5 -- .../compilers/gcc/common/strip-attributes.nix | 53 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 6 +-- 12 files changed, 119 insertions(+), 89 deletions(-) create mode 100644 pkgs/development/compilers/gcc/common/strip-attributes.nix diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index 1b9f542894e0..fed9194e7c1c 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -24,9 +24,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -86,7 +83,7 @@ let majorVersion = "10"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -231,9 +228,11 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; - - installTargets = optional stripped "install-strip"; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -274,8 +273,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index 1dc9ed0a2679..e6b910a3edff 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -24,9 +24,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -92,7 +89,7 @@ let majorVersion = "11"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -239,9 +236,11 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; - - installTargets = optional stripped "install-strip"; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -282,8 +281,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/12/default.nix b/pkgs/development/compilers/gcc/12/default.nix index 20bc9dcf44bb..f8eaf8f73437 100644 --- a/pkgs/development/compilers/gcc/12/default.nix +++ b/pkgs/development/compilers/gcc/12/default.nix @@ -24,9 +24,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -89,7 +86,7 @@ let majorVersion = "12"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -234,9 +231,11 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; - - installTargets = optional stripped "install-strip"; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -277,8 +276,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 8cd0d3c9ce80..bd42252c32f9 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -28,9 +28,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform == stdenv.buildPlatform - && stdenv.targetPlatform == stdenv.hostPlatform , gnused ? null , buildPackages }: @@ -124,7 +121,7 @@ in assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -238,12 +235,14 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv - installTargets = optional stripped "install-strip"; - # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -297,8 +296,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 571d0b023124..0f1947c6364e 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -28,9 +28,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform == stdenv.buildPlatform - && stdenv.targetPlatform == stdenv.hostPlatform , gnused ? null , buildPackages }: @@ -140,7 +137,7 @@ in assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -258,12 +255,14 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv - installTargets = optional stripped "install-strip"; - # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -316,8 +315,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 62b46df1ab00..a45b940a8611 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -31,9 +31,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -121,7 +118,7 @@ in assert x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []; stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -270,12 +267,14 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv - installTargets = optional stripped "install-strip"; - # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -328,8 +327,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 1abf14c8a8c7..c9b09ce31c5e 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -21,9 +21,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -94,7 +91,7 @@ let majorVersion = "7"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -237,12 +234,14 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv - installTargets = optional stripped "install-strip"; - # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -282,8 +281,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 2dd265b648ce..8109586cd3ec 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -21,9 +21,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -78,7 +75,7 @@ let majorVersion = "8"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -218,9 +215,11 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; - - installTargets = optional stripped "install-strip"; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -261,8 +260,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 30ae18e49173..12c67df68803 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -24,9 +24,6 @@ , libcCross ? null , threadsCross ? null # for MinGW , crossStageStatic ? false -, # Strip kills static libs of other archs (hence no cross) - stripped ? stdenv.hostPlatform.system == stdenv.buildPlatform.system - && stdenv.targetPlatform.system == stdenv.hostPlatform.system , gnused ? null , cloog # unused; just for compat with gcc4, as we override the parameter on some places , buildPackages @@ -89,7 +86,7 @@ let majorVersion = "9"; in stdenv.mkDerivation ({ - pname = "${crossNameAddon}${name}${if stripped then "" else "-debug"}"; + pname = "${crossNameAddon}${name}"; inherit version; builder = ../builder.sh; @@ -233,9 +230,11 @@ stdenv.mkDerivation ({ (targetPlatform == hostPlatform && hostPlatform == buildPlatform) (if profiledCompiler then "profiledbootstrap" else "bootstrap"); - dontStrip = !stripped; - - installTargets = optional stripped "install-strip"; + inherit + (import ../common/strip-attributes.nix { inherit stdenv; }) + stripDebugList + stripDebugListTarget + preFixup; # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; @@ -276,8 +275,7 @@ stdenv.mkDerivation ({ meta = { homepage = "https://gcc.gnu.org/"; license = lib.licenses.gpl3Plus; # runtime support libraries are typically LGPLv3+ - description = "GNU Compiler Collection, version ${version}" - + (if stripped then "" else " (with debugging info)"); + description = "GNU Compiler Collection, version ${version}"; longDescription = '' The GNU Compiler Collection includes compiler front ends for C, C++, diff --git a/pkgs/development/compilers/gcc/builder.sh b/pkgs/development/compilers/gcc/builder.sh index 9d0514f17590..89f3f562ee83 100644 --- a/pkgs/development/compilers/gcc/builder.sh +++ b/pkgs/development/compilers/gcc/builder.sh @@ -147,11 +147,6 @@ if test "$noSysDirs" = "1"; then fi fi -if [ -n "${targetConfig-}" ]; then - # if stripping gcc, include target directory too - stripDebugList="${stripDebugList-lib lib32 lib64 libexec bin sbin} $targetConfig" -fi - eval "$oldOpts" providedPreConfigure="$preConfigure"; diff --git a/pkgs/development/compilers/gcc/common/strip-attributes.nix b/pkgs/development/compilers/gcc/common/strip-attributes.nix new file mode 100644 index 000000000000..997c068cba62 --- /dev/null +++ b/pkgs/development/compilers/gcc/common/strip-attributes.nix @@ -0,0 +1,53 @@ +{ stdenv }: + +{ + # Note [Cross-compiler stripping] + # gcc requires delicate stripping as it installs ELF files for both + # HOST and TARGET platforms. It requires according strip tool otherwise + # strip could remove sections it's not aware of. + # Example ARM breakage by x86_64 strip: https://bugs.gentoo.org/697428 + # + # Let's recap the file layout for directories with object files for a + # cross-compiler (host != target): + # `- bin: HOST + # lib/*.{a,o}: HOST + # `- gcc///*.{a,o}: TARGET + # `- plugin/: HOST + # `- lib{,32,64,x32}: symlink to lib or identical layout + # `- libexec/: HOST + # `- /: TARGET + # + # (host == target) has identical directory layout. + + # The rest of stripDebugList{Host,Target} will be populated in + # postInstall. + stripDebugList = [ "bin" "libexec" ]; + stripDebugListTarget = [ stdenv.targetPlatform.config ]; + + preFixup = '' + # Populate most delicated lib/ part of stripDebugList{,Target} + updateDebugListPaths() { + local oldOpts + oldOpts="$(shopt -p nullglob)" || true + shopt -s nullglob + + pushd $out + + local -ar hostFiles=( + lib{,32,64}/*.{a.o} + lib{,32,64}/gcc/${stdenv.targetPlatform.config}/*/plugin + ) + local -ar targetFiles=( + lib{,32,64}/gcc/${stdenv.targetPlatform.config}/*/*.{a.o} + ) + + stripDebugList="$stripDebugList ''${hostFiles[*]}" + stripDebugListTarget="$stripDebugListTarget ''${targetFiles[*]}" + + popd + + eval "$oldOpts" + } + updateDebugListPaths + ''; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 480c5ab77043..45ab884f4234 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12955,9 +12955,9 @@ with pkgs; clangMultiStdenv = overrideCC stdenv buildPackages.clang_multi; multiStdenv = if stdenv.cc.isClang then clangMultiStdenv else gccMultiStdenv; - gcc_debug = lowPrio (wrapCC (gcc.cc.override { - stripped = false; - })); + gcc_debug = lowPrio (wrapCC (gcc.cc.overrideAttrs (_: { + dontStrip = true; + }))); gccCrossLibcStdenv = overrideCC stdenv buildPackages.gccCrossStageStatic;