diff options
author | Vladimír Čunát <vcunat@gmail.com> | 2015-09-17 20:07:20 +0200 |
---|---|---|
committer | Vladimír Čunát <vcunat@gmail.com> | 2015-09-17 20:07:20 +0200 |
commit | a418096d6a6a51913a7b940d1ff791e98d6181d4 (patch) | |
tree | 5745640d8c066e52b5e84c18181820af687fbf24 /pkgs/build-support/setup-hooks/separate-debug-info.sh | |
parent | bed1eb3260f82ee18ac66ec5c6266244967ceeed (diff) | |
parent | e8c1717ff488af06128210fba47d8ce917b53808 (diff) | |
download | nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar.gz nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar.bz2 nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar.lz nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar.xz nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.tar.zst nixlib-a418096d6a6a51913a7b940d1ff791e98d6181d4.zip |
Merge branch 'master' into staging
Diffstat (limited to 'pkgs/build-support/setup-hooks/separate-debug-info.sh')
-rw-r--r-- | pkgs/build-support/setup-hooks/separate-debug-info.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/separate-debug-info.sh b/pkgs/build-support/setup-hooks/separate-debug-info.sh new file mode 100644 index 000000000000..636918992090 --- /dev/null +++ b/pkgs/build-support/setup-hooks/separate-debug-info.sh @@ -0,0 +1,37 @@ +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 -a files=($(find "$prefix" -type f -a \( -perm /0100 -o -name "*.so" -o -name "*.so.*" \))) + + local i magic + for i in "${files[@]}"; do + # Skip non-ELF files. + exec 10< "$i" + read -n 4 -u 10 magic + if [[ "$magic" =~ ELF ]]; then echo FOO; fi + exec 10<&- + + # 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}" + objcopy --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug" + strip --strip-debug "$i" + done +} |