2015-09-17 15:24:32 +02:00
|
|
|
export NIX_LDFLAGS+=" --build-id"
|
|
|
|
export NIX_CFLAGS_COMPILE+=" -ggdb"
|
|
|
|
dontStrip=1
|
|
|
|
|
|
|
|
fixupOutputHooks+=(_separateDebugInfo)
|
|
|
|
|
|
|
|
_separateDebugInfo() {
|
|
|
|
local dst="${debug:-$out}"
|
|
|
|
if [ "$prefix" = "$dst" ]; then return; fi
|
|
|
|
|
|
|
|
dst="$dst/lib/debug/.build-id"
|
|
|
|
|
|
|
|
# Find executables and dynamic libraries.
|
|
|
|
local i magic
|
2016-02-18 22:30:42 +01:00
|
|
|
while IFS= read -r -d $'\0' i; do
|
2015-09-17 15:24:32 +02:00
|
|
|
# Skip non-ELF files.
|
2016-02-18 22:30:42 +01:00
|
|
|
exec {fd}< "$i"
|
|
|
|
read -n 4 -u $fd magic
|
|
|
|
exec {fd}<&-
|
2016-02-18 21:37:26 +01:00
|
|
|
if ! [[ "$magic" =~ ELF ]]; then continue; fi
|
2015-09-17 15:24:32 +02:00
|
|
|
|
|
|
|
# Extract the Build ID. FIXME: there's probably a cleaner way.
|
|
|
|
local id="$(readelf -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')"
|
|
|
|
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}"
|
2015-09-22 21:33:48 +02:00
|
|
|
objcopy --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug" --compress-debug-sections
|
2015-09-17 15:24:32 +02:00
|
|
|
strip --strip-debug "$i"
|
2016-01-15 16:12:05 +01:00
|
|
|
|
|
|
|
# Also a create a symlink <original-name>.debug.
|
|
|
|
ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")"
|
2016-02-18 22:30:42 +01:00
|
|
|
done < <(find "$prefix" -type f -a \( -perm /0100 -o -name "*.so" -o -name "*.so.*" \) -print0)
|
2015-09-17 15:24:32 +02:00
|
|
|
}
|
2015-09-22 21:33:48 +02:00
|
|
|
|
|
|
|
# - We might prefer to compress the debug info during link-time already,
|
|
|
|
# but our ld doesn't support --compress-debug-sections=zlib (yet).
|
2015-09-22 22:07:58 +02:00
|
|
|
# - Debug info may cause problems due to excessive memory usage during linking.
|
2015-09-22 21:33:48 +02:00
|
|
|
# Using -Wa,--compress-debug-sections should help with that;
|
|
|
|
# further interesting information: https://gcc.gnu.org/wiki/DebugFission
|
2015-09-22 22:33:18 +02:00
|
|
|
# - Another related tool: https://fedoraproject.org/wiki/Features/DwarfCompressor
|
2015-09-22 21:33:48 +02:00
|
|
|
|