about summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-11-26 01:58:36 +0100
committeraszlig <aszlig@nix.build>2018-11-26 01:58:36 +0100
commit4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4 (patch)
treecbba0b7cad12e985e76934f975fdd2e78a3dc577 /pkgs/build-support/setup-hooks
parent9f23a63f79e1a9d4a7f51444c12605d73ec770e1 (diff)
downloadnixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar.gz
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar.bz2
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar.lz
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar.xz
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.tar.zst
nixlib-4a6e3e4185dcbe53c3d5eceaf2570d51516ad2b4.zip
autoPatchelfHook: Skip on missing segment headers
If the file in question is not a shared object file but an ELF, we
really want to skip the file, because we won't have anything to patch
there.

For example if the file is created via "gcc -c -o foo.o foo.c", we don't
get a segment header and so far autoPatchelf was trying to patch such a
file.

By checking for missing segment headers, we're now no longer going to
attempt patching such a file.

Signed-off-by: aszlig <aszlig@nix.build>
Reported-by: Sander van der Burg <svanderburg@gmail.com>
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh5
1 files changed, 4 insertions, 1 deletions
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index 9a124f415b8c..5bedd1a9f9ca 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -205,9 +205,12 @@ autoPatchelf() {
     # outside of this function.
     while IFS= read -r -d $'\0' file; do
       isELF "$file" || continue
+      segmentHeaders="$(LANG=C readelf -l "$file")"
+      # Skip if the ELF file doesn't have segment headers (eg. object files).
+      echo "$segmentHeaders" | grep -q '^Program Headers:' || continue
       if isExecutable "$file"; then
           # Skip if the executable is statically linked.
-          LANG=C readelf -l "$file" | grep -q "^ *INTERP\\>" || continue
+          echo "$segmentHeaders" | grep -q "^ *INTERP\\>" || continue
       fi
       autoPatchelfFile "$file"
     done < <(find "$@" ${norecurse:+-maxdepth 1} -type f -print0)