summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergei Trofimovich <slyich@gmail.com>2022-08-07 09:05:33 +0100
committerSergei Trofimovich <slyich@gmail.com>2022-08-07 12:49:37 +0100
commitb3b672d5a16a0e99dc112b9f65436555b11c3ab7 (patch)
tree0742d0f2240ca07aa5482e6106401b4dce5823c4
parentcfd4ea64f48a846525e3b7bc0e2074ffbce6b1ce (diff)
downloadnixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar.gz
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar.bz2
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar.lz
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar.xz
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.tar.zst
nixpkgs-b3b672d5a16a0e99dc112b9f65436555b11c3ab7.zip
setup-hooks/separate-debug-info.sh: don't inhibit strip hook
Before the change separate-debug-info.sh did the stripping itself.
This scheme has a few problems:
1. Stripping happens only on ELF files. *.a and *.o files are skipped.
   Derivations have to do it manually. Usually incorrectly
   as they don't run $RANLIB (true for `glibc` and `musl`).
2. Stripping happens on all paths. Ideally only `stripDebugList` paths
   should be considered.
3. Host strip is called on Target files.

This change offloads stripping logic to strip hook. This strips more
files for `glibc` and `musl`. Now we can remove most $STRIP calls
from individual derivations.

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
-rw-r--r--pkgs/applications/networking/browsers/firefox/common.nix1
-rw-r--r--pkgs/build-support/setup-hooks/separate-debug-info.sh2
-rw-r--r--pkgs/build-support/setup-hooks/strip.sh23
-rw-r--r--pkgs/development/interpreters/python/cpython/default.nix5
-rw-r--r--pkgs/development/libraries/glibc/default.nix9
-rw-r--r--pkgs/os-specific/linux/musl/default.nix8
6 files changed, 14 insertions, 34 deletions
diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix
index fb4c326be5b..f0fe6e1551b 100644
--- a/pkgs/applications/networking/browsers/firefox/common.nix
+++ b/pkgs/applications/networking/browsers/firefox/common.nix
@@ -531,7 +531,6 @@ buildStdenv.mkDerivation ({
             header "separating debug info from $i (build ID $id)"
             mkdir -p "$dst/''${id:0:2}"
             $OBJCOPY --only-keep-debug "$i" "$dst/''${id:0:2}/''${id:2}.debug"
-            $STRIP --strip-debug "$i"
 
             # Also a create a symlink <original-name>.debug.
             ln -sfn ".build-id/''${id:0:2}/''${id:2}.debug" "$dst/../$(basename "$i")"
diff --git a/pkgs/build-support/setup-hooks/separate-debug-info.sh b/pkgs/build-support/setup-hooks/separate-debug-info.sh
index 593a5f64862..be94af545be 100644
--- a/pkgs/build-support/setup-hooks/separate-debug-info.sh
+++ b/pkgs/build-support/setup-hooks/separate-debug-info.sh
@@ -2,7 +2,6 @@ export NIX_SET_BUILD_ID=1
 export NIX_LDFLAGS+=" --compress-debug-sections=zlib"
 export NIX_CFLAGS_COMPILE+=" -ggdb -Wa,--compress-debug-sections"
 export RUSTFLAGS+=" -g"
-dontStrip=1
 
 fixupOutputHooks+=(_separateDebugInfo)
 
@@ -35,7 +34,6 @@ _separateDebugInfo() {
         # firmware blobs in QEMU.)
         (
             $OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
-            $STRIP --strip-debug "$i"
 
             # Also a create a symlink <original-name>.debug.
             ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh
index b2d0841888f..9bd7b24cab5 100644
--- a/pkgs/build-support/setup-hooks/strip.sh
+++ b/pkgs/build-support/setup-hooks/strip.sh
@@ -38,26 +38,27 @@ _doStrip() {
 stripDirs() {
     local cmd="$1"
     local ranlibCmd="$2"
-    local dirs="$3"
+    local paths="$3"
     local stripFlags="$4"
-    local dirsNew=
+    local pathsNew=
 
-    local d
-    for d in ${dirs}; do
-        if [ -e "$prefix/$d" ]; then
-            dirsNew="${dirsNew} $prefix/$d "
+    local p
+    for p in ${paths}; do
+        if [ -e "$prefix/$p" ]; then
+            pathsNew="${pathsNew} $prefix/$p"
         fi
     done
-    dirs=${dirsNew}
+    paths=${pathsNew}
 
-    if [ -n "${dirs}" ]; then
-        echo "stripping (with command $cmd and flags $stripFlags) in$dirs"
-        find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null
+    if [ -n "${paths}" ]; then
+        echo "stripping (with command $cmd and flags $stripFlags) in $paths"
+        # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
+        find $paths -type f -a '!' -wholename "$prefix/lib/debug/*" -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
+        find $paths -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null
     fi
 }
diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix
index dca7d9bb0db..44cf836fc9c 100644
--- a/pkgs/development/interpreters/python/cpython/default.nix
+++ b/pkgs/development/interpreters/python/cpython/default.nix
@@ -430,11 +430,6 @@ in with passthru; stdenv.mkDerivation {
     # This allows build Python to import host Python's sysconfigdata
     mkdir -p "$out/${sitePackages}"
     ln -s "$out/lib/${libPrefix}/"_sysconfigdata*.py "$out/${sitePackages}/"
-
-    # debug info can't be separated from a static library and would otherwise be
-    # left in place by a separateDebugInfo build. force its removal here to save
-    # space in output.
-    $STRIP -S $out/lib/${libPrefix}/config-*/libpython*.a || true
     '' + optionalString stripConfig ''
     rm -R $out/bin/python*-config $out/lib/python*/config-*
     '' + optionalString stripIdlelib ''
diff --git a/pkgs/development/libraries/glibc/default.nix b/pkgs/development/libraries/glibc/default.nix
index ba782321559..f815e1eaa47 100644
--- a/pkgs/development/libraries/glibc/default.nix
+++ b/pkgs/development/libraries/glibc/default.nix
@@ -127,15 +127,6 @@ callPackage ./common.nix { inherit stdenv; } {
       ln -sf $out/lib/libdl.so.2 $out/lib/libdl.so
       ln -sf $out/lib/libutil.so.1 $out/lib/libutil.so
       touch $out/lib/libpthread.a
-    ''
-      # For some reason these aren't stripped otherwise and retain reference
-      # to bootstrap-tools; on cross-arm this stripping would break objects.
-    + lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
-
-      for i in "$out"/lib/*.a; do
-          [ "$i" = "$out/lib/libm.a" ] || $STRIP -S "$i"
-      done
-    '' + ''
 
       # Put libraries for static linking in a separate output.  Note
       # that libc_nonshared.a and libpthread_nonshared.a are required
diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix
index fb0d19115da..b73c0ae04cd 100644
--- a/pkgs/os-specific/linux/musl/default.nix
+++ b/pkgs/os-specific/linux/musl/default.nix
@@ -102,15 +102,11 @@ stdenv.mkDerivation rec {
     # Apparently glibc provides scsi itself?
     (cd $dev/include && ln -s $(ls -d ${linuxHeaders}/include/* | grep -v "scsi$") .)
 
-    # Strip debug out of the static library
-    $STRIP -S $out/lib/libc.a
     mkdir -p $out/bin
 
 
-    ${if (stdenv.targetPlatform.libc == "musl" && stdenv.targetPlatform.isx86_32) then
-      "install -D libssp_nonshared.a $out/lib/libssp_nonshared.a
-      $STRIP -S $out/lib/libssp_nonshared.a"
-      else ""
+    ${lib.optionalString (stdenv.targetPlatform.libc == "musl" && stdenv.targetPlatform.isx86_32)
+      "install -D libssp_nonshared.a $out/lib/libssp_nonshared.a"
     }
 
     # Create 'ldd' symlink, builtin