tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
Don't try to apply patchelf to non-ELF binaries
Eelco Dolstra
10 years ago
d71a4851
bf63de16
+23
-13
3 changed files
expand all
collapse all
unified
split
pkgs
build-support
setup-hooks
separate-debug-info.sh
development
tools
misc
patchelf
setup-hook.sh
stdenv
generic
setup.sh
+2
-6
pkgs/build-support/setup-hooks/separate-debug-info.sh
···
13
13
# Find executables and dynamic libraries.
14
14
local i magic
15
15
while IFS= read -r -d $'\0' i; do
16
16
-
# Skip non-ELF files.
17
17
-
exec {fd}< "$i"
18
18
-
read -n 4 -u $fd magic
19
19
-
exec {fd}<&-
20
20
-
if ! [[ "$magic" =~ ELF ]]; then continue; fi
16
16
+
if ! isELF "$i"; then continue; fi
21
17
22
18
# Extract the Build ID. FIXME: there's probably a cleaner way.
23
19
local id="$(readelf -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')"
···
34
30
35
31
# Also a create a symlink <original-name>.debug.
36
32
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
37
37
-
done < <(find "$prefix" -type f -a \( -perm /0100 -o -name "*.so" -o -name "*.so.*" \) -print0)
33
33
+
done < <(find "$prefix" -type f -print0)
38
34
}
39
35
40
36
# - We might prefer to compress the debug info during link-time already,
+10
-7
pkgs/development/tools/misc/patchelf/setup-hook.sh
···
5
5
fixupOutputHooks+=('if [ -z "$dontPatchELF" ]; then patchELF "$prefix"; fi')
6
6
7
7
patchELF() {
8
8
-
header "patching ELF executables and libraries in $prefix"
9
9
-
if [ -e "$prefix" ]; then
10
10
-
find "$prefix" \( \
11
11
-
\( -type f -a -name "*.so*" \) -o \
12
12
-
\( -type f -a -perm -0100 \) \
13
13
-
\) -print -exec patchelf --shrink-rpath '{}' \;
14
14
-
fi
8
8
+
header "shrinking RPATHs of ELF executables and libraries in $prefix"
9
9
+
10
10
+
local i
11
11
+
while IFS= read -r -d $'\0' i; do
12
12
+
if [[ "$i" =~ .build-id ]]; then continue; fi
13
13
+
if ! isELF "$i"; then continue; fi
14
14
+
echo "shrinking $i"
15
15
+
patchelf --shrink-rpath "$i" || true
16
16
+
done < <(find "$prefix" -type f -print0)
17
17
+
15
18
stopNest
16
19
}
+11
pkgs/stdenv/generic/setup.sh
···
180
180
}
181
181
182
182
183
183
+
# Return success if the specified file is an ELF object.
184
184
+
isELF() {
185
185
+
local fn="$1"
186
186
+
local magic
187
187
+
exec {fd}< "$fn"
188
188
+
read -n 4 -u $fd magic
189
189
+
exec {fd}<&-
190
190
+
if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
191
191
+
}
192
192
+
193
193
+
183
194
######################################################################
184
195
# Initialisation.
185
196