Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 49 lines 1.7 kB view raw
1export NIX_SET_BUILD_ID=1 2export NIX_LDFLAGS+=" --compress-debug-sections=zlib" 3export NIX_CFLAGS_COMPILE+=" -ggdb -Wa,--compress-debug-sections" 4export RUSTFLAGS+=" -g" 5 6fixupOutputHooks+=(_separateDebugInfo) 7 8_separateDebugInfo() { 9 [ -e "$prefix" ] || return 0 10 11 local dst="${debug:-$out}" 12 if [ "$prefix" = "$dst" ]; then return 0; fi 13 14 # in case there is nothing to strip, don't fail the build 15 mkdir -p "$dst" 16 17 dst="$dst/lib/debug/.build-id" 18 19 # Find executables and dynamic libraries. 20 local i 21 while IFS= read -r -d $'\0' i; do 22 if ! isELF "$i"; then continue; fi 23 24 # Extract the Build ID. FIXME: there's probably a cleaner way. 25 local id="$($READELF -n "$i" | sed 's/.*Build ID: \([0-9a-f]*\).*/\1/; t; d')" 26 if [ "${#id}" != 40 ]; then 27 echo "could not find build ID of $i, skipping" >&2 28 continue 29 fi 30 31 # Extract the debug info. 32 echo "separating debug info from $i (build ID $id)" 33 mkdir -p "$dst/${id:0:2}" 34 35 # This may fail, e.g. if the binary is for a different 36 # architecture than we're building for. (This happens with 37 # firmware blobs in QEMU.) 38 ( 39 if [ -f "$dst/${id:0:2}/${id:2}.debug" ] 40 then 41 echo "separate-debug-info: warning: multiple files with build id $id found, overwriting" 42 fi 43 $OBJCOPY --only-keep-debug "$i" "$dst/${id:0:2}/${id:2}.debug" 44 45 # Also a create a symlink <original-name>.debug. 46 ln -sfn ".build-id/${id:0:2}/${id:2}.debug" "$dst/../$(basename "$i")" 47 ) || rmdir -p "$dst/${id:0:2}" 48 done < <(find "$prefix" -type f -print0 | sort -z) 49}