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