Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions pkgs/build-support/setup-hooks/separate-debug-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,40 @@ _separateDebugInfo() {
# Find executables and dynamic libraries.
local i
while IFS= read -r -d $'\0' i; do
if ! isELF "$i"; then continue; fi

# 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
if isELF "$i"; then

# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should strip .so without Build IDs as well, they could be unexpected bloat.

Copy link
Contributor Author

@risicle risicle Apr 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Yes, interesting. The more I think about this, the more it feels what we should actually be doing is falling through to allow the regular strip setup hook to do its job afterwards instead of disabling it with dontStrip. Because surely after this hook's run all the outputs other than debug are safe to strip. Should this setup hook perhaps just concern itself with pulling the debug info out to debug and leave the existing stripping mechanisms to continue operating as normal?

Though that would be a bigger change and I'm not confident I'd understand all the ramifications of that.

fi

# Extract the debug info.
header "separating debug info from $i (build ID $id)"
mkdir -p "$dst/${id:0:2}"

# 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.)
(
$OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
$STRIP --strip-debug "$i"

# 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}"

elif isAR "$i" && [ "${i##*.}" = "a" ]; then
# possibly a static library - build will likely have
# added debugging symbols to any static libraries produced
# too, making them huge. separate debug outputs have limited
# value for static libraries, so attempt to strip any
# found. a user can just use a `dontStrip` build if they
# need a static library with debug info.

header "stripping $i"
$STRIP --strip-debug -D "$i" || true
fi

# Extract the debug info.
header "separating debug info from $i (build ID $id)"
mkdir -p "$dst/${id:0:2}"

# 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.)
(
$OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug"
$STRIP --strip-debug "$i"

# 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}"
done < <(find "$prefix" -type f -print0)
}
5 changes: 0 additions & 5 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,6 @@ in with passthru; stdenv.mkDerivation {
# This allows build Python to import host Python's sysconfigdata
mkdir -p "$out/${sitePackages}"
ln -s "$out/lib/${libPrefix}/"_sysconfigdata*.py "$out/${sitePackages}/"

# debug info can't be separated from a static library and would otherwise be
# left in place by a separateDebugInfo build. force its removal here to save
# space in output.
$STRIP -S $out/lib/${libPrefix}/config-*/libpython*.a || true
'' + optionalString stripConfig ''
rm -R $out/bin/python*-config $out/lib/python*/config-*
'' + optionalString stripIdlelib ''
Expand Down
11 changes: 11 additions & 0 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ isELF() {
if [ "$magic" = $'\177ELF' ]; then return 0; else return 1; fi
}

# Return success if the specified file is an AR archive
isAR() {
local fn="$1"
local fd
local magic
exec {fd}< "$fn"
read -r -N 8 -u "$fd" magic
exec {fd}<&-
if [ "$magic" = $'!<arch>\n' ]; then return 0; else return 1; fi
}

# Return success if the specified file is a Mach-O object.
isMachO() {
local fn="$1"
Expand Down