2016-02-28 04:57:37 +03:00
|
|
|
export NIX_SET_BUILD_ID=1
|
|
|
|
export NIX_LDFLAGS+=" --compress-debug-sections=zlib"
|
2016-02-28 03:54:55 +03:00
|
|
|
export NIX_CFLAGS_COMPILE+=" -ggdb -Wa,--compress-debug-sections"
|
2015-09-17 16:24:32 +03:00
|
|
|
dontStrip=1
|
|
|
|
|
|
|
|
fixupOutputHooks+=(_separateDebugInfo)
|
|
|
|
|
|
|
|
_separateDebugInfo() {
|
2016-05-12 13:18:59 +03:00
|
|
|
[ -e "$prefix" ] || return 0
|
|
|
|
|
2015-09-17 16:24:32 +03:00
|
|
|
local dst="${debug:-$out}"
|
2016-05-12 13:18:59 +03:00
|
|
|
if [ "$prefix" = "$dst" ]; then return 0; fi
|
2015-09-17 16:24:32 +03:00
|
|
|
|
|
|
|
dst="$dst/lib/debug/.build-id"
|
|
|
|
|
|
|
|
# Find executables and dynamic libraries.
|
|
|
|
local i magic
|
2016-02-19 00:30:42 +03:00
|
|
|
while IFS= read -r -d $'\0' i; do
|
2016-02-19 00:52:44 +03:00
|
|
|
if ! isELF "$i"; then continue; fi
|
2015-09-17 16:24:32 +03:00
|
|
|
|
|
|
|
# Extract the Build ID. FIXME: there's probably a cleaner way.
|
2017-09-21 08:33:00 +03:00
|
|
|
local id="$($READELF -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')"
|
2015-09-17 16:24:32 +03:00
|
|
|
if [ "${#id}" != 40 ]; then
|
|
|
|
echo "could not find build ID of $i, skipping" >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract the debug info.
|
|
|
|
header "separating debug info from $i (build ID $id)"
|
|
|
|
mkdir -p "$dst/${id:0:2}"
|
2017-09-21 08:33:00 +03:00
|
|
|
$OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
|
|
|
|
$STRIP --strip-debug "$i"
|
2016-01-15 18:12:05 +03:00
|
|
|
|
|
|
|
# Also a create a symlink <original-name>.debug.
|
|
|
|
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
|
2016-02-19 00:52:44 +03:00
|
|
|
done < <(find "$prefix" -type f -print0)
|
2015-09-17 16:24:32 +03:00
|
|
|
}
|