chantra / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
5523e9
--- rpm-4.11.3/scripts/find-debuginfo.sh.old	2019-01-02 13:14:10.283068553 +0100
5523e9
+++ rpm-4.11.3/scripts/find-debuginfo.sh	2019-03-21 09:36:06.196400883 +0100
5523e9
@@ -3,6 +3,7 @@
5523e9
 #for inclusion in an rpm spec file.
5523e9
 #
5523e9
 # Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m]
5523e9
+#			   [--g-libs]
5523e9
 #	 		   [-o debugfiles.list]
5523e9
 #			   [--run-dwz] [--dwz-low-mem-die-limit N]
5523e9
 #			   [--dwz-max-die-limit N]
5523e9
@@ -10,6 +11,8 @@
5523e9
 #			   [builddir]
5523e9
 #
5523e9
 # The -g flag says to use strip -g instead of full strip on DSOs or EXEs.
5523e9
+# The --g-libs flag says to use strip -g instead of full strip ONLY on DSOs.
5523e9
+# Options -g and --g-libs are mutually exclusive.
5523e9
 # The --strict-build-id flag says to exit with failure status if
5523e9
 # any ELF binary processed fails to contain a build-id note.
5523e9
 # The -r flag says to use eu-strip --reloc-debug-sections.
5523e9
@@ -32,6 +35,9 @@
5523e9
 # With -g arg, pass it to strip on libraries or executables.
5523e9
 strip_g=false
5523e9
 
5523e9
+# With --g-libs arg, pass it to strip on libraries.
5523e9
+strip_glibs=false
5523e9
+
5523e9
 # with -r arg, pass --reloc-debug-sections to eu-strip.
5523e9
 strip_r=false
5523e9
 
5523e9
@@ -65,6 +71,9 @@
5523e9
     dwz_max_die_limit=$2
5523e9
     shift
5523e9
     ;;
5523e9
+  --g-libs)
5523e9
+    strip_glibs=true
5523e9
+    ;;
5523e9
   -g)
5523e9
     strip_g=true
5523e9
     ;;
5523e9
@@ -100,6 +109,11 @@
5523e9
   shift
5523e9
 done
5523e9
 
5523e9
+if ("$strip_g" = "true") && ("$strip_glibs" = "true"); then
5523e9
+  echo >&2 "*** ERROR: -g  and --g-libs cannot be used together"
5523e9
+  exit 2
5523e9
+fi
5523e9
+
5523e9
 i=0
5523e9
 while ((i < nout)); do
5523e9
   outs[$i]="$BUILDDIR/${outs[$i]}"
5523e9
@@ -132,6 +146,9 @@
5523e9
   application/x-sharedlib*) g=-g ;;
5523e9
   application/x-executable*) g=-g ;;
5523e9
   esac
5523e9
+  $strip_glibs && case "$(file -bi "$2")" in
5523e9
+    application/x-sharedlib*) g=-g ;;
5523e9
+  esac
5523e9
   eu-strip --remove-comment $r $g -f "$1" "$2" || exit
5523e9
   chmod 444 "$1" || exit
5523e9
 }
5523e9
@@ -317,7 +334,23 @@
5523e9
     chmod u-w "$f"
5523e9
   fi
5523e9
 
5523e9
-  $include_minidebug && add_minidebug "${debugfn}" "$f"
5523e9
+  # strip -g implies we have full symtab, don't add mini symtab in that case.
5523e9
+  # It only makes sense to add a minisymtab for executables and shared
5523e9
+  # libraries. Other executable ELF files (like kernel modules) don't need it.
5523e9
+  if [ "$include_minidebug" = "true" -a "$strip_g" = "false" ]; then
5523e9
+    skip_mini=true
5523e9
+    if [ "$strip_glibs" = "false" ]; then
5523e9
+      case "$(file -bi "$f")" in
5523e9
+        application/x-sharedlib*) skip_mini=false ;;
5523e9
+      esac
5523e9
+    fi
5523e9
+    case "$(file -bi "$f")" in
5523e9
+      application/x-sharedlib*) skip_mini=false ;;
5523e9
+      application/x-executable*) skip_mini=false ;;
5523e9
+      application/x-pie-executable*) skip_mini=false ;;
5523e9
+    esac
5523e9
+    $skip_mini || add_minidebug "${debugfn}" "$f"
5523e9
+  fi
5523e9
 
5523e9
   echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE"
5523e9