Igor Gnatenko 082d5d
From 525282b9a8b78c2890c752e45c4dc7dcf25f42cb Mon Sep 17 00:00:00 2001
Igor Gnatenko 082d5d
From: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
Date: Sun, 16 Apr 2017 18:16:46 +0200
Igor Gnatenko 3992a6
Subject: [PATCH 29/54] debugedit: Add -n, --no-recompute-build-id.
Mark Wielaard 9eaad7
Igor Gnatenko 082d5d
Some packages depend on the build-ids as generated during the build
Igor Gnatenko 082d5d
and cannot handle rpmbuild recomputing them before generating the
Igor Gnatenko 082d5d
package file list. Add -n, --no-recompute-build-id to debugedit and
Igor Gnatenko 082d5d
add -n to find-debuginfo.sh set by defining the %_no_recompute_build_ids
Igor Gnatenko 082d5d
macro for such packages. %_no_recompute_build_ids can not be used together
Igor Gnatenko 082d5d
with %_unique_build_ids.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Signed-off-by: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
(cherry picked from commit 6e9fd97f6dba9e04cfd33225b610272b964cc5fc)
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Conflicts:
Igor Gnatenko 082d5d
	macros.in
Igor Gnatenko 082d5d
	scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
---
Igor Gnatenko 082d5d
 macros.in                 |   7 ++-
Igor Gnatenko 082d5d
 scripts/find-debuginfo.sh |  20 +++++++-
Igor Gnatenko 082d5d
 tests/rpmbuildid.at       | 122 ++++++++++++++++++++++++++++++++++++++++++++++
Igor Gnatenko 082d5d
 tools/debugedit.c         |   6 ++-
Igor Gnatenko 082d5d
 4 files changed, 151 insertions(+), 4 deletions(-)
Mark Wielaard 9eaad7
Mark Wielaard 9eaad7
diff --git a/macros.in b/macros.in
Igor Gnatenko 082d5d
index e48ef60c8..c5b1a0b26 100644
Mark Wielaard 9eaad7
--- a/macros.in
Mark Wielaard 9eaad7
+++ b/macros.in
Igor Gnatenko 082d5d
@@ -180,7 +180,7 @@
Mark Wielaard 9eaad7
 #	the script.  See the script for details.
Mark Wielaard 9eaad7
 #
Mark Wielaard 9eaad7
 %__debug_install_post   \
Mark Wielaard 9eaad7
-   %{_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}"} %{?_unique_debug_names:--unique-debug-arch "%{_arch}"} %{?_unique_debug_srcs:--unique-debug-src-base "%{name}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Mark Wielaard 9eaad7
+   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_no_recompute_build_ids:-n} %{?_include_minidebuginfo:-m} %{?_include_gdb_index:-i} %{?_unique_build_ids:--ver-rel "%{VERSION}-%{RELEASE}"} %{?_unique_debug_names:--unique-debug-arch "%{_arch}"} %{?_unique_debug_srcs:--unique-debug-src-base "%{name}"} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Mark Wielaard 9eaad7
 %{nil}
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
 #	Template for debug information sub-package.
Igor Gnatenko 082d5d
@@ -488,6 +488,11 @@ package or when debugging this package.\
Mark Wielaard 9eaad7
 # onto debugedit --build-id-seed to be used to prime the build-id note hash.
Mark Wielaard 9eaad7
 %_unique_build_ids	1
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
+# Do not recompute build-ids but keep whatever is in the ELF file already.
Mark Wielaard 9eaad7
+# Cannot be used together with _unique_build_ids (which forces recomputation).
Mark Wielaard 9eaad7
+# Defaults to undefined (unset).
Mark Wielaard 9eaad7
+#%_no_recompute_build_ids 1
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
 # Whether .debug files should be made unique between package version,
Mark Wielaard 9eaad7
 # release and architecture. If set to 1 this will pass
Mark Wielaard 9eaad7
 # --unique-debug-arch "%{_arch}" to find-debuginfo.sh to create
Mark Wielaard 9eaad7
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
Igor Gnatenko 082d5d
index f1ffcd7d8..1d3dc0623 100644
Mark Wielaard 9eaad7
--- a/scripts/find-debuginfo.sh
Mark Wielaard 9eaad7
+++ b/scripts/find-debuginfo.sh
Mark Wielaard 9eaad7
@@ -2,7 +2,7 @@
Mark Wielaard 9eaad7
 #find-debuginfo.sh - automagically generate debug info and file list
Mark Wielaard 9eaad7
 #for inclusion in an rpm spec file.
Mark Wielaard 9eaad7
 #
Mark Wielaard 9eaad7
-# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] [-i]
Mark Wielaard 9eaad7
+# Usage: find-debuginfo.sh [--strict-build-id] [-g] [-r] [-m] [-i] [-n]
Mark Wielaard 9eaad7
 #	 		   [-o debugfiles.list]
Mark Wielaard 9eaad7
 #			   [--run-dwz] [--dwz-low-mem-die-limit N]
Mark Wielaard 9eaad7
 #			   [--dwz-max-die-limit N]
Mark Wielaard 9eaad7
@@ -16,6 +16,7 @@
Mark Wielaard 9eaad7
 # The -r flag says to use eu-strip --reloc-debug-sections.
Mark Wielaard 9eaad7
 # The -m flag says to include a .gnu_debugdata section in the main binary.
Mark Wielaard 9eaad7
 # The -i flag says to include a .gdb_index section in the .debug file.
Mark Wielaard 9eaad7
+# The -n flag says to not recompute the build-id.
Mark Wielaard 9eaad7
 #
Mark Wielaard 9eaad7
 # A single -o switch before any -l or -p switches simply renames
Mark Wielaard 9eaad7
 # the primary output file from debugfiles.list to something else.
Mark Wielaard 9eaad7
@@ -56,6 +57,9 @@ include_gdb_index=false
Mark Wielaard 9eaad7
 # Barf on missing build IDs.
Mark Wielaard 9eaad7
 strict=false
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
+# Do not recompute build IDs.
Mark Wielaard 9eaad7
+no_recompute_build_id=false
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
 # DWZ parameters.
Mark Wielaard 9eaad7
 run_dwz=false
Mark Wielaard 9eaad7
 dwz_low_mem_die_limit=
Igor Gnatenko 082d5d
@@ -107,6 +111,9 @@ while [ $# -gt 0 ]; do
Mark Wielaard 9eaad7
   -m)
Mark Wielaard 9eaad7
     include_minidebug=true
Mark Wielaard 9eaad7
     ;;
Mark Wielaard 9eaad7
+  -n)
Mark Wielaard 9eaad7
+    no_recompute_build_id=true
Mark Wielaard 9eaad7
+    ;;
Mark Wielaard 9eaad7
   -i)
Mark Wielaard 9eaad7
     include_gdb_index=true
Mark Wielaard 9eaad7
     ;;
Igor Gnatenko 082d5d
@@ -149,6 +156,11 @@ if test -z "$unique_debug_arch" -a -n "$unique_debug_src_base"; then
Mark Wielaard 9eaad7
   exit 2
Mark Wielaard 9eaad7
 fi
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
+if test -n "$ver_rel" -a "$no_recompute_build_id" = "true"; then
Mark Wielaard 9eaad7
+  echo >&2 "*** ERROR: --ver-rel (unique build-ids) and -n (do not recompute build-id cannot be used together"
Mark Wielaard 9eaad7
+  exit 2
Mark Wielaard 9eaad7
+fi
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
 i=0
Mark Wielaard 9eaad7
 while ((i < nout)); do
Mark Wielaard 9eaad7
   outs[$i]="$BUILDDIR/${outs[$i]}"
Igor Gnatenko 082d5d
@@ -310,8 +322,12 @@ while read nlinks inum f; do
Mark Wielaard 9eaad7
     debug_base_name="$BUILDDIR"
Mark Wielaard 9eaad7
     debug_dest_name="/usr/src/debug/${unique_debug_src_base}-${ver_rel}.${unique_debug_arch}"
Mark Wielaard 9eaad7
   fi
Mark Wielaard 9eaad7
+  no_recompute=
Mark Wielaard 9eaad7
+  if [ "$no_recompute_build_id" = "true" ]; then
Mark Wielaard 9eaad7
+    no_recompute="-n"
Mark Wielaard 9eaad7
+  fi
Mark Wielaard 9eaad7
   id=$(${lib_rpm_dir}/debugedit -b $debug_base_name -d $debug_dest_name \
Mark Wielaard 9eaad7
-			      -i $build_id_seed -l "$SOURCEFILE" "$f") || exit
Igor Gnatenko 082d5d
+		$no_recompute -i $build_id_seed -l "$SOURCEFILE" "$f") || exit
Mark Wielaard 9eaad7
   if [ $nlinks -gt 1 ]; then
Mark Wielaard 9eaad7
     eval linkedid_$inum=\$id
Mark Wielaard 9eaad7
   fi
Mark Wielaard 9eaad7
diff --git a/tests/rpmbuildid.at b/tests/rpmbuildid.at
Igor Gnatenko 082d5d
index 158ce122d..4fab3d5dc 100644
Mark Wielaard 9eaad7
--- a/tests/rpmbuildid.at
Mark Wielaard 9eaad7
+++ b/tests/rpmbuildid.at
Mark Wielaard 9eaad7
@@ -1060,6 +1060,128 @@ debug dup id in debug package
Mark Wielaard 9eaad7
 AT_CLEANUP
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
 # ------------------------------
Mark Wielaard 9eaad7
+# Check build-ids are recomputed with unique_build_ids,
Mark Wielaard 9eaad7
+# but not with _no_recompute_build_ids
Mark Wielaard 9eaad7
+AT_SETUP([rpmbuild buildid recompute])
Mark Wielaard 9eaad7
+AT_KEYWORDS([build] [debuginfo] [buildid])
Mark Wielaard 9eaad7
+AT_CHECK([
Mark Wielaard 9eaad7
+rm -rf ${TOPDIR}
Mark Wielaard 9eaad7
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Make sure we get debuginfo
Mark Wielaard 9eaad7
+export CFLAGS="-g"
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Unique 1
Mark Wielaard 9eaad7
+run rpmbuild --quiet \
Mark Wielaard 9eaad7
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Mark Wielaard 9eaad7
+  --rcfile=${abs_top_builddir}/rpmrc \
Mark Wielaard 9eaad7
+  --define="_unique_build_ids 1" \
Mark Wielaard 9eaad7
+  --undefine="_no_recompute_build_ids" \
Mark Wielaard 9eaad7
+  -ba "${abs_srcdir}"/data/SPECS/hello.spec
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-1.*.rpm \
Mark Wielaard 9eaad7
+  | cpio -diu --quiet
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+hello_file=./usr/local/bin/hello
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Extract the build-id from the main file
Mark Wielaard 9eaad7
+test -f $hello_file || echo "No $hello_file"
Mark Wielaard 9eaad7
+id1=$(file $hello_file | sed 's/.*, BuildID\[[.*\]]=\([[0-9a-f]]*\),.*/\1/')
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Make sure we generate a new one
Mark Wielaard 9eaad7
+rm $hello_file
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Unique 2
Mark Wielaard 9eaad7
+# Build the "next" release, which has no changes except for the release update.
Mark Wielaard 9eaad7
+run rpmbuild --quiet \
Mark Wielaard 9eaad7
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Mark Wielaard 9eaad7
+  --rcfile=${abs_top_builddir}/rpmrc \
Mark Wielaard 9eaad7
+  --define="_unique_build_ids 1" \
Mark Wielaard 9eaad7
+  --undefine="_no_recompute_build_ids" \
Mark Wielaard 9eaad7
+  -ba "${abs_srcdir}"/data/SPECS/hello-r2.spec
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-2.*.rpm \
Mark Wielaard 9eaad7
+  | cpio -diu --quiet
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Extract the build-id from the main file
Mark Wielaard 9eaad7
+test -f $hello_file || echo "No $hello_file"
Mark Wielaard 9eaad7
+id2=$(file $hello_file | sed 's/.*, BuildID\[[.*\]]=\([[0-9a-f]]*\),.*/\1/')
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Two unique builds should not be equal
Mark Wielaard 9eaad7
+if test "$id1" == "$id2"; then
Mark Wielaard 9eaad7
+  echo "uniques equal";
Mark Wielaard 9eaad7
+else
Mark Wielaard 9eaad7
+  echo "uniques unequal";
Mark Wielaard 9eaad7
+fi
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Make sure we generate a new one
Mark Wielaard 9eaad7
+rm $hello_file
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# no-recompute 1
Mark Wielaard 9eaad7
+run rpmbuild --quiet \
Mark Wielaard 9eaad7
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Mark Wielaard 9eaad7
+  --rcfile=${abs_top_builddir}/rpmrc \
Mark Wielaard 9eaad7
+  --undefine="_unique_build_ids" \
Mark Wielaard 9eaad7
+  --undefine="_unique_debug_names" \
Mark Wielaard 9eaad7
+  --undefine="_unique_debug_srcs" \
Mark Wielaard 9eaad7
+  --define="_no_recompute_build_ids 1" \
Mark Wielaard 9eaad7
+  -ba "${abs_srcdir}"/data/SPECS/hello.spec
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-1.*.rpm \
Mark Wielaard 9eaad7
+  | cpio -diu --quiet
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+hello_file=./usr/local/bin/hello
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Extract the build-id from the main file
Mark Wielaard 9eaad7
+test -f $hello_file || echo "No $hello_file"
Mark Wielaard 9eaad7
+id3=$(file $hello_file | sed 's/.*, BuildID\[[.*\]]=\([[0-9a-f]]*\),.*/\1/')
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# An unique and no-recompute build should be unequal
Mark Wielaard 9eaad7
+if test "$id2" == "$id3"; then
Mark Wielaard 9eaad7
+  echo "no-recompute unique equal";
Mark Wielaard 9eaad7
+else
Mark Wielaard 9eaad7
+  echo "no-recompute unique unequal";
Mark Wielaard 9eaad7
+fi
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Make sure we generate a new one
Mark Wielaard 9eaad7
+rm $hello_file
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# no-recompute 2
Mark Wielaard 9eaad7
+# Build the "next" release, which has no changes except for the release update.
Mark Wielaard 9eaad7
+run rpmbuild --quiet \
Mark Wielaard 9eaad7
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Mark Wielaard 9eaad7
+  --rcfile=${abs_top_builddir}/rpmrc \
Mark Wielaard 9eaad7
+  --undefine="_unique_build_ids" \
Mark Wielaard 9eaad7
+  --undefine="_unique_debug_names" \
Mark Wielaard 9eaad7
+  --undefine="_unique_debug_srcs" \
Mark Wielaard 9eaad7
+  --define="_no_recompute_build_ids 1" \
Mark Wielaard 9eaad7
+  -ba "${abs_srcdir}"/data/SPECS/hello-r2.spec
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-2.*.rpm \
Mark Wielaard 9eaad7
+  | cpio -diu --quiet
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Extract the build-id from the main file
Mark Wielaard 9eaad7
+test -f $hello_file || echo "No $hello_file"
Mark Wielaard 9eaad7
+id4=$(file $hello_file | sed 's/.*, BuildID\[[.*\]]=\([[0-9a-f]]*\),.*/\1/')
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# Two no-recompute builds should be equal. Even for different "releases".
Mark Wielaard 9eaad7
+if test "$id3" == "$id4"; then
Mark Wielaard 9eaad7
+  echo "no-recomputes equal";
Mark Wielaard 9eaad7
+else
Mark Wielaard 9eaad7
+  echo "no-recomputes unequal";
Mark Wielaard 9eaad7
+fi
Mark Wielaard 9eaad7
+],
Mark Wielaard 9eaad7
+[0],
Mark Wielaard 9eaad7
+[uniques unequal
Mark Wielaard 9eaad7
+no-recompute unique unequal
Mark Wielaard 9eaad7
+no-recomputes equal
Mark Wielaard 9eaad7
+],
Mark Wielaard 9eaad7
+[ignore])
Mark Wielaard 9eaad7
+AT_CLEANUP
Mark Wielaard 9eaad7
+
Mark Wielaard 9eaad7
+# ------------------------------
Mark Wielaard 9eaad7
 # Check build-ids are unique between versions/releases
Mark Wielaard 9eaad7
 # with _unique_build_ids defined.
Mark Wielaard 9eaad7
 AT_SETUP([rpmbuild buildid unique r1 r2])
Mark Wielaard 9eaad7
diff --git a/tools/debugedit.c b/tools/debugedit.c
Igor Gnatenko 082d5d
index b618dceb5..8444e030e 100644
Mark Wielaard 9eaad7
--- a/tools/debugedit.c
Mark Wielaard 9eaad7
+++ b/tools/debugedit.c
Mark Wielaard 9eaad7
@@ -85,6 +85,7 @@ char *dest_dir = NULL;
Mark Wielaard 9eaad7
 char *list_file = NULL;
Mark Wielaard 9eaad7
 int list_file_fd = -1;
Mark Wielaard 9eaad7
 int do_build_id = 0;
Mark Wielaard 9eaad7
+int no_recompute_build_id = 0;
Mark Wielaard 9eaad7
 char *build_id_seed = NULL;
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
 /* We go over the debug sections in two phases. In phase zero we keep
Mark Wielaard 9eaad7
@@ -2261,6 +2262,8 @@ static struct poptOption optionsTable[] = {
Mark Wielaard 9eaad7
       "recompute build ID note and print ID on stdout", NULL },
Mark Wielaard 9eaad7
     { "build-id-seed", 's', POPT_ARG_STRING, &build_id_seed, 0,
Mark Wielaard 9eaad7
       "if recomputing the build ID note use this string as hash seed", NULL },
Mark Wielaard 9eaad7
+    { "no-recompute-build-id",  'n', POPT_ARG_NONE, &no_recompute_build_id, 0,
Mark Wielaard 9eaad7
+      "do not recompute build ID note even when -i or -s are given", NULL },
Mark Wielaard 9eaad7
       POPT_AUTOHELP
Mark Wielaard 9eaad7
     { NULL, 0, 0, NULL, 0, NULL, NULL }
Mark Wielaard 9eaad7
 };
Mark Wielaard 9eaad7
@@ -2380,7 +2383,8 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
Mark Wielaard 9eaad7
       exit (1);
Mark Wielaard 9eaad7
     }
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
-  if (!dirty_elf && build_id_seed == NULL)
Mark Wielaard 9eaad7
+  if (no_recompute_build_id
Mark Wielaard 9eaad7
+      || (! dirty_elf && build_id_seed == NULL))
Mark Wielaard 9eaad7
     goto print;
Mark Wielaard 9eaad7
 
Mark Wielaard 9eaad7
   /* Clear the old bits so they do not affect the new hash.  */
Igor Gnatenko 082d5d
-- 
Igor Gnatenko 082d5d
2.13.2
Igor Gnatenko 082d5d