From d71a4851e8a2ef52f6d806d65822290cdbae8804 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 18 Feb 2016 22:52:44 +0100 Subject: Don't try to apply patchelf to non-ELF binaries --- pkgs/build-support/setup-hooks/separate-debug-info.sh | 8 ++------ pkgs/development/tools/misc/patchelf/setup-hook.sh | 17 ++++++++++------- pkgs/stdenv/generic/setup.sh | 11 +++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'pkgs') diff --git a/pkgs/build-support/setup-hooks/separate-debug-info.sh b/pkgs/build-support/setup-hooks/separate-debug-info.sh index cf3d7b07a499..37753d9ce406 100644 --- a/pkgs/build-support/setup-hooks/separate-debug-info.sh +++ b/pkgs/build-support/setup-hooks/separate-debug-info.sh @@ -13,11 +13,7 @@ _separateDebugInfo() { # Find executables and dynamic libraries. local i magic while IFS= read -r -d $'\0' i; do - # Skip non-ELF files. - exec {fd}< "$i" - read -n 4 -u $fd magic - exec {fd}<&- - if ! [[ "$magic" =~ ELF ]]; then continue; fi + if ! isELF "$i"; then continue; fi # Extract the Build ID. FIXME: there's probably a cleaner way. local id="$(readelf -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')" @@ -34,7 +30,7 @@ _separateDebugInfo() { # Also a create a symlink .debug. ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")" - done < <(find "$prefix" -type f -a \( -perm /0100 -o -name "*.so" -o -name "*.so.*" \) -print0) + done < <(find "$prefix" -type f -print0) } # - We might prefer to compress the debug info during link-time already, diff --git a/pkgs/development/tools/misc/patchelf/setup-hook.sh b/pkgs/development/tools/misc/patchelf/setup-hook.sh index a76fbfbd509c..03b6f362a779 100644 --- a/pkgs/development/tools/misc/patchelf/setup-hook.sh +++ b/pkgs/development/tools/misc/patchelf/setup-hook.sh @@ -5,12 +5,15 @@ fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi') patchELF() { - header "patching ELF executables and libraries in $prefix" - if [ -e "$prefix" ]; then - find "$prefix" \( \ - \( -type f -a -name "*.so*" \) -o \ - \( -type f -a -perm -0100 \) \ - \) -print -exec patchelf --shrink-rpath '{}' \; - fi + header "shrinking RPATHs of ELF executables and libraries in $prefix" + + local i + while IFS= read -r -d $'\0' i; do + if [[ "$i" =~ .build-id ]]; then continue; fi + if ! isELF "$i"; then continue; fi + echo "shrinking $i" + patchelf --shrink-rpath "$i" || true + done < <(find "$prefix" -type f -print0) + stopNest } diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 7d25472993c5..8081b69bffd3 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -180,6 +180,17 @@ installBin() { } +# Return success if the specified file is an ELF object. +isELF() { + local fn="$1" + local magic + exec {fd}< "$fn" + read -n 4 -u $fd magic + exec {fd}<&- + if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi +} + + ###################################################################### # Initialisation. -- cgit 1.4.1