extra-utils: Sync with Nixpkgs
This fixes a regression in which binaries weren't stripped anymore.
See also:
@@ -33,9 +33,12 @@ let
# A utility for enumerating the shared-library dependencies of a program
findLibs = buildPackages.writeShellScriptBin "find-libs" ''
set -euo pipefail
+
declare -A seen
- declare -a left
+ left=()
+
patchelf="${buildPackages.patchelf}/bin/patchelf"
+
function add_needed {
rpath="$($patchelf --print-rpath $1)"
dir="$(dirname $1)"
@@ -43,7 +46,9 @@ let
left+=("$lib" "$rpath" "$dir")
done
}
- add_needed $1
+
+ add_needed "$1"
+
while [ ''${#left[@]} -ne 0 ]; do
next=''${left[0]}
rpath=''${left[1]}
@@ -51,10 +56,12 @@ let
left=("''${left[@]:3}")
if [ -z ''${seen[$next]+x} ]; then
seen[$next]=1
+
# Ignore the dynamic linker which for some reason appears as a DT_NEEDED of glibc but isn't in glibc's RPATH.
case "$next" in
ld*.so.?) continue;;
esac
+
IFS=: read -ra paths <<< $rpath
res=
for path in "''${paths[@]}"; do
@@ -107,25 +114,21 @@ runCommandCC "extra-utils-${name}"
# Strip binaries further than normal.
chmod -R u+w $out
- stripDirs "$STRIP" "lib bin" "-s"
+ stripDirs "$STRIP" "$RANLIB" "lib bin" "-s"
+
# Run patchelf to make the programs refer to the copied libraries.
find $out/bin $out/lib -type f | while read i; do
- if ! test -L $i; then
- echo "nuking refs from $i..."
nuke-refs -e $out $i
- fi
done
+
find $out/bin -type f | while read i; do
- if ! test -L $i; then
echo "patching $i..."
patchelf --set-interpreter $out/lib/ld*.so.? --set-rpath $out/lib $i || true
- fi
done
- # TODO : make a test-case for this
- # # Make sure that the patchelf'ed binaries still work.
- # echo "testing patched programs..."
- # $out/bin/ash -c 'echo hello world' | grep "hello world"
- # export LD_LIBRARY_PATH=$out/lib
- # $out/bin/mount --help 2>&1 | grep -q "BusyBox"
+ find $out/lib -type f \! -name 'ld*.so.?' | while read i; do
+ echo "patching $i..."
+ patchelf --set-rpath $out/lib $i
+ done
+
''
