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