teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0006-Make-adding-GDB-index-sections-configurable.patch

Igor Gnatenko 082d5d
From 68a0323ab1738aee40f9f5a60a7fb3163162bf39 Mon Sep 17 00:00:00 2001
Panu Matilainen 5b4d98
From: Mark Wielaard <mjw@redhat.com>
Panu Matilainen 5b4d98
Date: Tue, 14 Jun 2016 17:07:14 +0200
Mark Wielaard 284dc3
Subject: [PATCH] Make adding GDB index sections configurable.
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
Introduces _include_gdb_index macro and -i flag to find-debuginfo.sh to
Panu Matilainen 5b4d98
enable or disable adding a .gdb_index section to debug files. Adds tests
Panu Matilainen 5b4d98
to make sure the .gdb_index is really added (or not) when requested.
Panu Matilainen 5b4d98
Checks that gdb-add-index is actually installed instead of silently
Panu Matilainen 5b4d98
failing if not. Similar for dwz.
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Igor Gnatenko 082d5d
(cherry picked from commit 67d3df338875ad5d9601e360bfdbd4289f271bc1)
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Conflicts:
Igor Gnatenko 082d5d
	scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
---
Panu Matilainen 5b4d98
 macros.debug              |  1 +
Panu Matilainen 5b4d98
 macros.in                 |  8 ++++++-
Panu Matilainen 5b4d98
 scripts/find-debuginfo.sh | 29 ++++++++++++++++++----
Panu Matilainen 5b4d98
 tests/rpmbuild.at         | 61 +++++++++++++++++++++++++++++++++++++++++++++++
Panu Matilainen 5b4d98
 4 files changed, 94 insertions(+), 5 deletions(-)
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
diff --git a/macros.debug b/macros.debug
Igor Gnatenko 082d5d
index 6a8432eb7..d273c0876 100644
Panu Matilainen 5b4d98
--- a/macros.debug
Panu Matilainen 5b4d98
+++ b/macros.debug
Panu Matilainen 5b4d98
@@ -2,6 +2,7 @@
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 %_enable_debug_packages 1
Panu Matilainen 5b4d98
 %_include_minidebuginfo 1
Panu Matilainen 5b4d98
+%_include_gdb_index    	1
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 # Expanded at end of %install scriptlet
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
diff --git a/macros.in b/macros.in
Igor Gnatenko 082d5d
index dcd09612c..c845f5841 100644
Panu Matilainen 5b4d98
--- a/macros.in
Panu Matilainen 5b4d98
+++ b/macros.in
Panu Matilainen 5b4d98
@@ -180,7 +180,7 @@
Panu Matilainen 5b4d98
 #	the script.  See the script for details.
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
 %__debug_install_post   \
Panu Matilainen 5b4d98
-   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_unique_build_ids:--ver-rel "%{version}-%{release}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Panu Matilainen 5b4d98
+   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_include_gdb_index:-i} %{?_unique_build_ids:--ver-rel "%{version}-%{release}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Panu Matilainen 5b4d98
 %{nil}
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 #	Template for debug information sub-package.
Panu Matilainen 5b4d98
@@ -449,6 +449,12 @@ package or when debugging this package.\
Panu Matilainen 5b4d98
 #%_include_minidebuginfo	1
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
+# Include a .gdb_index section in the .debug files.
Panu Matilainen 5b4d98
+# Requires _enable_debug_packages and gdb-add-index installed.
Panu Matilainen 5b4d98
+#
Panu Matilainen 5b4d98
+#%_include_gdb_index	1
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+#
Panu Matilainen 5b4d98
 # Defines how and if build_id links are generated for ELF files.
Panu Matilainen 5b4d98
 # The following settings are supported:
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
index 2cb9570ba..8e608134f 100644
Panu Matilainen 5b4d98
--- a/scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
+++ b/scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
@@ -2,7 +2,7 @@
Panu Matilainen 5b4d98
 #find-debuginfo.sh - automagically generate debug info and file list
Panu Matilainen 5b4d98
 #for inclusion in an rpm spec file.
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
-# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m]
Panu Matilainen 5b4d98
+# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] [-i]
Panu Matilainen 5b4d98
 #	 		   [-o debugfiles.list]
Panu Matilainen 5b4d98
 #			   [--run-dwz] [--dwz-low-mem-die-limit N]
Panu Matilainen 5b4d98
 #			   [--dwz-max-die-limit N]
Panu Matilainen 5b4d98
@@ -14,6 +14,8 @@
Panu Matilainen 5b4d98
 # The --strict-build-id flag says to exit with failure status if
Panu Matilainen 5b4d98
 # any ELF binary processed fails to contain a build-id note.
Panu Matilainen 5b4d98
 # The -r flag says to use eu-strip --reloc-debug-sections.
Panu Matilainen 5b4d98
+# The -m flag says to include a .gnu_debugdata section in the main binary.
Panu Matilainen 5b4d98
+# The -i flag says to include a .gdb_index section in the .debug file.
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
 # A single -o switch before any -l or -p switches simply renames
Panu Matilainen 5b4d98
 # the primary output file from debugfiles.list to something else.
Panu Matilainen 5b4d98
@@ -48,6 +50,9 @@ strip_r=false
Panu Matilainen 5b4d98
 # with -m arg, add minimal debuginfo to binary.
Panu Matilainen 5b4d98
 include_minidebug=false
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
+# with -i arg, add GDB index to .debug file.
Panu Matilainen 5b4d98
+include_gdb_index=false
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
 # Barf on missing build IDs.
Panu Matilainen 5b4d98
 strict=false
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
@@ -88,6 +93,9 @@ while [ $# -gt 0 ]; do
Panu Matilainen 5b4d98
   -m)
Panu Matilainen 5b4d98
     include_minidebug=true
Panu Matilainen 5b4d98
     ;;
Panu Matilainen 5b4d98
+  -i)
Panu Matilainen 5b4d98
+    include_gdb_index=true
Panu Matilainen 5b4d98
+    ;;
Panu Matilainen 5b4d98
   -o)
Panu Matilainen 5b4d98
     if [ -z "${lists[$nout]}" -a -z "${ptns[$nout]}" ]; then
Panu Matilainen 5b4d98
       out=$2
Panu Matilainen 5b4d98
@@ -277,7 +285,15 @@ while read nlinks inum f; do
Panu Matilainen 5b4d98
     $strict && exit 2
Panu Matilainen 5b4d98
   fi
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
-  type gdb-add-index >/dev/null 2>&1 && gdb-add-index "$f" > /dev/null 2>&1
Panu Matilainen 5b4d98
+  # Add .gdb_index if requested.
Panu Matilainen 5b4d98
+  if $include_gdb_index; then
Panu Matilainen 5b4d98
+    if type gdb-add-index >/dev/null 2>&1; then
Panu Matilainen 5b4d98
+      gdb-add-index "$f"
Panu Matilainen 5b4d98
+    else
Panu Matilainen 5b4d98
+      echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
Panu Matilainen 5b4d98
+      exit 2
Panu Matilainen 5b4d98
+    fi
Panu Matilainen 5b4d98
+  fi
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
   # A binary already copied into /usr/lib/debug doesn't get stripped,
Panu Matilainen 5b4d98
   # just has its file names collected and adjusted.
Panu Matilainen 5b4d98
@@ -303,7 +319,7 @@ while read nlinks inum f; do
Panu Matilainen 5b4d98
 done || exit
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 # Invoke the DWARF Compressor utility.
Panu Matilainen 5b4d98
-if $run_dwz && type dwz >/dev/null 2>&1 \
Panu Matilainen 5b4d98
+if $run_dwz \
Panu Matilainen 5b4d98
    && [ -d "${RPM_BUILD_ROOT}/usr/lib/debug" ]; then
Panu Matilainen 5b4d98
   dwz_files="`cd "${RPM_BUILD_ROOT}/usr/lib/debug"; find -type f -name \*.debug`"
Panu Matilainen 5b4d98
   if [ -n "${dwz_files}" ]; then
Panu Matilainen 5b4d98
@@ -321,7 +337,12 @@ if $run_dwz && type dwz >/dev/null 2>&1 \
Panu Matilainen 5b4d98
       && dwz_opts="${dwz_opts} -l ${dwz_low_mem_die_limit}"
Panu Matilainen 5b4d98
     [ -n "${dwz_max_die_limit}" ] \
Panu Matilainen 5b4d98
       && dwz_opts="${dwz_opts} -L ${dwz_max_die_limit}"
Panu Matilainen 5b4d98
-    ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts $dwz_files )
Panu Matilainen 5b4d98
+    if type dwz >/dev/null 2>&1; then
Panu Matilainen 5b4d98
+      ( cd "${RPM_BUILD_ROOT}/usr/lib/debug" && dwz $dwz_opts $dwz_files )
Panu Matilainen 5b4d98
+    else
Panu Matilainen 5b4d98
+      echo >&2 "*** ERROR: DWARF compression requested, but no dwz installed"
Panu Matilainen 5b4d98
+      exit 2
Panu Matilainen 5b4d98
+    fi
Panu Matilainen 5b4d98
     # Remove .dwz directory if empty
Panu Matilainen 5b4d98
     rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null
Panu Matilainen 5b4d98
     if [ -f "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz/${dwz_multifile_name}" ]; then
Panu Matilainen 5b4d98
diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at
Igor Gnatenko 082d5d
index 1531700e1..a3123244c 100644
Panu Matilainen 5b4d98
--- a/tests/rpmbuild.at
Panu Matilainen 5b4d98
+++ b/tests/rpmbuild.at
Panu Matilainen 5b4d98
@@ -532,3 +532,64 @@ usr/local/bin/hello2
Panu Matilainen 5b4d98
 ],
Panu Matilainen 5b4d98
 [ignore])
Panu Matilainen 5b4d98
 AT_CLEANUP
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# ------------------------------
Panu Matilainen 5b4d98
+# Check that a GDB index is included when requested.
Panu Matilainen 5b4d98
+AT_SETUP([rpmbuild debuginfo gdb index included])
Panu Matilainen 5b4d98
+AT_KEYWORDS([build] [debuginfo] [gdb])
Panu Matilainen 5b4d98
+AT_CHECK([
Panu Matilainen 5b4d98
+rm -rf ${TOPDIR}
Panu Matilainen 5b4d98
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Build a package that has some debuginfo
Panu Matilainen 5b4d98
+cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --define "_include_gdb_index 1" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello2.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Unpack the debuginfo rpms so we can check the .debug files.
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello2-debuginfo-1.0-1.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Check that gdb-add-index has ran and a .gdb_index section has been added
Panu Matilainen 5b4d98
+readelf -S ./usr/lib/debug/usr/local/bin/hello2*.debug \
Panu Matilainen 5b4d98
+  | grep gdb_index | cut -c8-17
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[0],
Panu Matilainen 5b4d98
+[.gdb_index
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[ignore])
Panu Matilainen 5b4d98
+AT_CLEANUP
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# ------------------------------
Panu Matilainen 5b4d98
+# Check that a GDB index is NOT included when not requested.
Panu Matilainen 5b4d98
+AT_SETUP([rpmbuild debuginfo no gdb index included])
Panu Matilainen 5b4d98
+AT_KEYWORDS([build] [debuginfo] [gdb])
Panu Matilainen 5b4d98
+AT_CHECK([
Panu Matilainen 5b4d98
+rm -rf ${TOPDIR}
Panu Matilainen 5b4d98
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Build a package that has some debuginfo
Panu Matilainen 5b4d98
+cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --undefine "_include_gdb_index" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello2.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Unpack the debuginfo rpms so we can check the .debug files.
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello2-debuginfo-1.0-1.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Check that gdb-add-index has not ran and no .gdb_index section has been added
Panu Matilainen 5b4d98
+readelf -S ./usr/lib/debug/usr/local/bin/hello2*.debug \
Panu Matilainen 5b4d98
+  | grep gdb_index | cut -c8-17
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[0],
Panu Matilainen 5b4d98
+[],
Panu Matilainen 5b4d98
+[ignore])
Panu Matilainen 5b4d98
+AT_CLEANUP