teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0024-no-recompute-build-id.patch

Mark Wielaard 9eaad7
commit 8edddd82f855d547bd68ba4d693db497bbbed7ab
Mark Wielaard 9eaad7
Author: Mark Wielaard <mark@klomp.org>
Mark Wielaard 9eaad7
Date:   Sat Apr 15 20:31:14 2017 +0200
Mark Wielaard 9eaad7
Mark Wielaard 9eaad7
    debugedit: Add -n, --no-recompute-build-id.
Mark Wielaard 9eaad7
    
Mark Wielaard 9eaad7
    Some packages depend on the build-ids as generated during the build
Mark Wielaard 9eaad7
    and cannot handle rpmbuild recomputing them before generating the
Mark Wielaard 9eaad7
    package file list. Add -n, --no-recompute-build-id to debugedit and
Mark Wielaard 9eaad7
    add -n to find-debuginfo.sh set by defining the %_no_recompute_build_ids
Mark Wielaard 9eaad7
    macro for such packages. %_no_recompute_build_ids can not be used together
Mark Wielaard 9eaad7
    with %_unique_build_ids.
Mark Wielaard 9eaad7
    
Mark Wielaard 9eaad7
    Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard 9eaad7
Mark Wielaard 9eaad7
diff --git a/macros.in b/macros.in
Mark Wielaard 9eaad7
index f7d16de..cf22628 100644
Mark Wielaard 9eaad7
--- a/macros.in
Mark Wielaard 9eaad7
+++ b/macros.in
Mark Wielaard 9eaad7
@@ -172,7 +172,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.
Mark Wielaard 9eaad7
@@ -498,6 +498,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
Mark Wielaard 9eaad7
index b52822e..86a248d 100755
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=
Mark Wielaard 9eaad7
@@ -110,6 +114,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
     ;;
Mark Wielaard 9eaad7
@@ -159,6 +166,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]}"
Mark Wielaard 9eaad7
@@ -310,8 +322,12 @@
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
Mark Wielaard 9eaad7
+	       $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
Mark Wielaard 9eaad7
index dc47b90..88ce226 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
Mark Wielaard 9eaad7
index b618dce..8444e03 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.  */