Skip to content

Commit

Permalink
setup-hooks/strip: resolve/uniq symlinks before stripping
Browse files Browse the repository at this point in the history
Before the change the hook had a chance to run `strip` against the same
file using multiple link paths. In case of `gcc` `libgcc.a` was stripped
multiple times in parallel and produces corrupted archive.

The change runs inputs via `realpath | uniq` to make sure we don't
attempt to strip the same files multiple times.
  • Loading branch information
trofi committed Jul 30, 2023
1 parent a934dd5 commit 7adf0a4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkgs/build-support/setup-hooks/strip.sh
Expand Up @@ -68,6 +68,11 @@ stripDirs() {
striperr="$(mktemp 'striperr.XXXXXX')"
# Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 |
# Make sure we process files under symlinks only once. Otherwise
# 'strip` can corrupt files when writes to them in parallel:
# https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039
xargs -r -0 -n1 -- realpath -z | sort -u -z |

xargs -r -0 -n1 -P "$NIX_BUILD_CORES" -- $cmd $stripFlags 2>"$striperr" || exit_code=$?
# xargs exits with status code 123 if some but not all of the
# processes fail. We don't care if some of the files couldn't
Expand Down

0 comments on commit 7adf0a4

Please sign in to comment.