2016-02-28 01:57:37 +00:00
|
|
|
export NIX_SET_BUILD_ID=1
|
|
|
|
export NIX_LDFLAGS+=" --compress-debug-sections=zlib"
|
2016-02-28 00:54:55 +00:00
|
|
|
export NIX_CFLAGS_COMPILE+=" -ggdb -Wa,--compress-debug-sections"
|
2024-07-11 16:54:13 +00:00
|
|
|
export NIX_RUSTFLAGS+=" -g -C strip=none"
|
2015-09-17 13:24:32 +00:00
|
|
|
|
|
|
|
fixupOutputHooks+=(_separateDebugInfo)
|
|
|
|
|
|
|
|
_separateDebugInfo() {
|
2016-05-12 10:18:59 +00:00
|
|
|
[ -e "$prefix" ] || return 0
|
|
|
|
|
2015-09-17 13:24:32 +00:00
|
|
|
local dst="${debug:-$out}"
|
2016-05-12 10:18:59 +00:00
|
|
|
if [ "$prefix" = "$dst" ]; then return 0; fi
|
2015-09-17 13:24:32 +00:00
|
|
|
|
2023-03-12 12:00:00 +00:00
|
|
|
# in case there is nothing to strip, don't fail the build
|
|
|
|
mkdir -p "$dst"
|
|
|
|
|
2015-09-17 13:24:32 +00:00
|
|
|
dst="$dst/lib/debug/.build-id"
|
|
|
|
|
|
|
|
# Find executables and dynamic libraries.
|
2021-08-05 15:44:25 +00:00
|
|
|
local i
|
2016-02-18 21:30:42 +00:00
|
|
|
while IFS= read -r -d $'\0' i; do
|
2016-02-18 21:52:44 +00:00
|
|
|
if ! isELF "$i"; then continue; fi
|
2015-09-17 13:24:32 +00:00
|
|
|
|
2023-07-28 20:03:13 +00:00
|
|
|
[ -z "${READELF:-}" ] && echo "_separateDebugInfo: '\$READELF' variable is empty, skipping." 1>&2 && break
|
|
|
|
[ -z "${OBJCOPY:-}" ] && echo "_separateDebugInfo: '\$OBJCOPY' variable is empty, skipping." 1>&2 && break
|
|
|
|
|
2015-09-17 13:24:32 +00:00
|
|
|
# Extract the Build ID. FIXME: there's probably a cleaner way.
|
2017-09-21 05:33:00 +00:00
|
|
|
local id="$($READELF -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')"
|
2015-09-17 13:24:32 +00:00
|
|
|
if [ "${#id}" != 40 ]; then
|
|
|
|
echo "could not find build ID of $i, skipping" >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract the debug info.
|
2023-01-15 22:08:12 +00:00
|
|
|
echo "separating debug info from $i (build ID $id)"
|
2015-09-17 13:24:32 +00:00
|
|
|
mkdir -p "$dst/${id:0:2}"
|
2016-01-15 15:12:05 +00:00
|
|
|
|
2021-11-21 14:58:14 +00:00
|
|
|
# This may fail, e.g. if the binary is for a different
|
|
|
|
# architecture than we're building for. (This happens with
|
|
|
|
# firmware blobs in QEMU.)
|
|
|
|
(
|
2023-04-23 09:53:47 +00:00
|
|
|
if [ -f "$dst/${id:0:2}/${id:2}.debug" ]
|
|
|
|
then
|
|
|
|
echo "separate-debug-info: warning: multiple files with build id $id found, overwriting"
|
|
|
|
fi
|
2021-11-21 14:58:14 +00:00
|
|
|
$OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
|
|
|
|
|
|
|
|
# Also a create a symlink <original-name>.debug.
|
|
|
|
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
|
|
|
|
) || rmdir -p "$dst/${id:0:2}"
|
2023-04-23 09:53:47 +00:00
|
|
|
done < <(find "$prefix" -type f -print0 | sort -z)
|
2015-09-17 13:24:32 +00:00
|
|
|
}
|