rpm/0003-Make-adding-GDB-index-...

215 lines
7.8 KiB
Diff

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