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