dcavalca / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
648606
--- rpm-4.10.0/macros.in	2012-06-11 11:16:21.216952339 +0200
648606
+++ rpm-4.10.0/macros.in.minidebug	2012-06-11 11:16:23.686912455 +0200
648606
@@ -175,7 +175,7 @@ 
648606
 #	the script.  See the script for details.
648606
 #
648606
 %__debug_install_post   \
648606
-   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
648606
+   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
648606
 %{nil}
648606
 
648606
 #	Template for debug information sub-package.
648606
@@ -418,6 +418,12 @@ package or when debugging this package.\
648606
 #%_missing_build_ids_terminate_build	1
648606
 
648606
 #
648606
+# Include minimal debug information in build binaries.
648606
+# Requires _enable_debug_packages.
648606
+#
648606
+#%_include_minidebuginfo	1
648606
+
648606
+#
648606
 # Use internal dependency generator rather than external helpers?
648606
 %_use_internal_dependency_generator	1
648606
 
648606
--- rpm-4.10.0/scripts/find-debuginfo.sh	2012-06-11 11:16:09.698138273 +0200
648606
+++ rpm-4.10.0/scripts/find-debuginfo.sh.minidebug	2012-06-11 11:16:13.399078526 +0200
648606
@@ -2,7 +2,7 @@ 
648606
 #find-debuginfo.sh - automagically generate debug info and file list
648606
 #for inclusion in an rpm spec file.
648606
 #
648606
-# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r]
648606
+# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m]
648606
 #	 		   [-o debugfiles.list]
648606
 #			   [--run-dwz] [--dwz-low-mem-die-limit N]
648606
 #			   [--dwz-max-die-limit N]
648606
@@ -29,6 +29,9 @@ strip_g=false
648606
 # with -r arg, pass --reloc-debug-sections to eu-strip.
648606
 strip_r=false
648606
 
648606
+# with -m arg, add minimal debuginfo to binary.
648606
+include_minidebug=false
648606
+
648606
 # Barf on missing build IDs.
648606
 strict=false
648606
 
648606
@@ -43,6 +46,9 @@ while [ $# -gt 0 ]; do
648606
   -g)
648606
     strip_g=true
648606
     ;;
648606
+  -m)
648606
+    include_minidebug=true
648606
+    ;;
648606
   -o)
648606
     if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then
648606
       out=$2
648606
@@ -105,6 +111,32 @@ strip_to_debug()
648606
   chmod 444 "$1" || exit
648606
 }
648606
 
648606
+add_minidebug()
648606
+{
648606
+  local debuginfo="$1"
648606
+  local binary="$2"
648606
+
648606
+  local dynsyms=`mktemp`
648606
+  local funcsyms=`mktemp`
648606
+  local keep_symbols=`mktemp`
648606
+  local mini_debuginfo=`mktemp`
648606
+
648606
+  # Extract the dynamic symbols from the main binary, there is no need to also have these
648606
+  # in the normal symbol table
648606
+  nm -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort > "$dynsyms"
648606
+  # Extract all the text (i.e. function) symbols from the debuginfo 
648606
+  nm "$debuginfo" --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t") print $1 }' | sort > "$funcsyms"
648606
+  # Keep all the function symbols not already in the dynamic symbol table
648606
+  comm -13 "$dynsyms" "$funcsyms" > "$keep_symbols"
648606
+  # Copy the full debuginfo, keeping only a minumal set of symbols and removing some unnecessary sections
648606
+  objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null
648606
+  #Inject the compressed data into the .gnu_debugdata section of the original binary
648606
+  xz "$mini_debuginfo"
648606
+  mini_debuginfo="${mini_debuginfo}.xz"
648606
+  objcopy --add-section .gnu_debugdata="$mini_debuginfo" "$binary"
648606
+  rm -f "$dynsyms" "$funcsyms" "$keep_symbols" "$mini_debuginfo"
648606
+}
648606
+
648606
 # Make a relative symlink to $1 called $3$2
648606
 shopt -s extglob
648606
 link_relative()
648606
@@ -260,6 +292,9 @@ while read nlinks inum f; do
648606
     chmod u-w "$f"
648606
   fi
648606
 
648606
+  $include_minidebug && add_minidebug "${debugfn}" "$f"
648606
+
648606
+  
648606
   if [ -n "$id" ]; then
648606
     make_id_link "$id" "$dn/$(basename $f)"
648606
     make_id_link "$id" "/usr/lib/debug$dn/$bn" .debug