1 export NIX_SET_BUILD_ID
=1
2 export NIX_LDFLAGS
+=" --compress-debug-sections=zlib"
3 export NIX_CFLAGS_COMPILE
+=" -ggdb -Wa,--compress-debug-sections"
4 export NIX_RUSTFLAGS
+=" -g -C strip=none"
6 fixupOutputHooks
+=(_separateDebugInfo
)
9 [ -e "$prefix" ] ||
return 0
11 local dst
="${debug:-$out}"
12 if [ "$prefix" = "$dst" ]; then return 0; fi
14 # in case there is nothing to strip, don't fail the build
17 dst
="$dst/lib/debug/.build-id"
19 # Find executables and dynamic libraries.
21 while IFS
= read -r -d $
'\0' i
; do
22 if ! isELF
"$i"; then continue; fi
24 [ -z "${READELF:-}" ] && echo "_separateDebugInfo: '\$READELF' variable is empty, skipping." 1>&2 && break
25 [ -z "${OBJCOPY:-}" ] && echo "_separateDebugInfo: '\$OBJCOPY' variable is empty, skipping." 1>&2 && break
27 # Extract the Build ID. FIXME: there's probably a cleaner way.
28 local id
="$($READELF -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')"
29 if [ "${#id}" != 40 ]; then
30 echo "could not find build ID of $i, skipping" >&2
34 # Extract the debug info.
35 echo "separating debug info from $i (build ID $id)"
36 mkdir
-p "$dst/${id:0:2}"
38 # This may fail, e.g. if the binary is for a different
39 # architecture than we're building for. (This happens with
40 # firmware blobs in QEMU.)
42 if [ -f "$dst/${id:0:2}/${id:2}.debug" ]
44 echo "separate-debug-info: warning: multiple files with build id $id found, overwriting"
46 $OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
48 # Also a create a symlink <original-name>.debug.
49 ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
50 ) ||
rmdir -p "$dst/${id:0:2}"
51 done < <(find "$prefix" -type f
-print0 |
sort -z)