From 534fae47e4d05fd27c277c9e04ad238e608289f5 Mon Sep 17 00:00:00 2001 From: Michal Marek Date: Sat, 10 Sep 2016 23:13:24 +0200 Subject: [PATCH] find-debuginfo.sh: Split directory traversal and debuginfo extraction This siplifies the handling of hardlinks a bit and allows a later patch to parallelize the debuginfo extraction. Signed-off-by: Michal Marek (cherry picked from commit 038bfe01796f751001e02de41c5d8678f511f366) Conflicts: scripts/find-debuginfo.sh --- scripts/find-debuginfo.sh | 53 ++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) mode change 100755 => 100644 scripts/find-debuginfo.sh diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh old mode 100755 new mode 100644 index 5087c4050..097b749bb --- a/scripts/find-debuginfo.sh +++ b/scripts/find-debuginfo.sh @@ -283,32 +283,36 @@ set -o pipefail strict_error=ERROR $strict || strict_error=WARNING -# Strip ELF binaries +temp=$(mktemp -d ${TMPDIR:-/tmp}/find-debuginfo.XXXXXX) +trap 'rm -rf "$temp"' EXIT + +# Build a list of unstripped ELF files and their hardlinks +touch "$temp/primary" find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \ \( -perm -0100 -or -perm -0010 -or -perm -0001 \) \ -print | file -N -f - | sed -n -e 's/^\(.*\):[ ]*.*ELF.*, not stripped.*/\1/p' | xargs --no-run-if-empty stat -c '%h %D_%i %n' | while read nlinks inum f; do - get_debugfn "$f" - [ -f "${debugfn}" ] && continue - - # If this file has multiple links, keep track and make - # the corresponding .debug files all links to one file too. if [ $nlinks -gt 1 ]; then - eval linked=\$linked_$inum - if [ -n "$linked" ]; then - eval id=\$linkedid_$inum - link=$debugfn - get_debugfn "$linked" - echo "hard linked $link to $debugfn" - mkdir -p "$(dirname "$link")" && ln -nf "$debugfn" "$link" + var=seen_$inum + if test -n "${!var}"; then + echo "$inum $f" >>"$temp/linked" continue else - eval linked_$inum=\$f - echo "file $f has $[$nlinks - 1] other hard links" + read "$var" < <(echo 1) fi fi + echo "$nlinks $inum $f" >>"$temp/primary" +done + +# Strip ELF binaries +do_file() +{ + local nlinks=$1 inum=$2 f=$3 id link linked + + get_debugfn "$f" + [ -f "${debugfn}" ] && return echo "extracting debug info from $f" build_id_seed= @@ -328,9 +332,6 @@ while read nlinks inum f; do fi id=$(${lib_rpm_dir}/debugedit -b $debug_base_name -d $debug_dest_name \ $no_recompute -i $build_id_seed -l "$SOURCEFILE" "$f") || exit - if [ $nlinks -gt 1 ]; then - eval linkedid_$inum=\$id - fi if [ -z "$id" ]; then echo >&2 "*** ${strict_error}: No build ID note found in $f" $strict && exit 2 @@ -376,7 +377,21 @@ while read nlinks inum f; do echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE" -done || exit + # If this file has multiple links, make the corresponding .debug files + # all links to one file too. + if [ $nlinks -gt 1 ]; then + grep "^$inum " "$temp/linked" | while read inum linked; do + link=$debugfn + get_debugfn "$linked" + echo "hard linked $link to $debugfn" + mkdir -p "$(dirname "$debugfn")" && ln -nf "$link" "$debugfn" + done + fi +} + +while read nlinks inum f; do + do_file "$nlinks" "$inum" "$f" +done <"$temp/primary" # Invoke the DWARF Compressor utility. if $run_dwz \