teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0002-Make-it-possible-to-have-unique-build-ids-across-bui.patch

Panu Matilainen 5b4d98
From 2a97fb48279af17049f96c661db040173185a650 Mon Sep 17 00:00:00 2001
Panu Matilainen 5b4d98
Message-Id: <2a97fb48279af17049f96c661db040173185a650.1488964568.git.pmatilai@redhat.com>
Panu Matilainen 5b4d98
In-Reply-To: <189b4f88c8e100155ec23a1e0b214bdc8473532a.1488964568.git.pmatilai@redhat.com>
Panu Matilainen 5b4d98
References: <189b4f88c8e100155ec23a1e0b214bdc8473532a.1488964568.git.pmatilai@redhat.com>
Panu Matilainen 5b4d98
From: Mark Wielaard <mjw@redhat.com>
Panu Matilainen 5b4d98
Date: Tue, 14 Jun 2016 17:07:13 +0200
Panu Matilainen 5b4d98
Subject: [PATCH 02/11] Make it possible to have unique build-ids across build
Panu Matilainen 5b4d98
 versions/releases.
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
Introduce a new macro _unique_build_ids that when set will pass the
Panu Matilainen 5b4d98
version and release to find-debuginfo.sh and debugedit to recalculate
Panu Matilainen 5b4d98
the build-id of ELF files.
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
Includes two new testcases to make sure the new setting works as expected
Panu Matilainen 5b4d98
both when set and unset.
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Panu Matilainen 5b4d98
---
Panu Matilainen 5b4d98
 macros.in                      |  8 +++-
Panu Matilainen 5b4d98
 scripts/find-debuginfo.sh      | 20 ++++++++-
Panu Matilainen 5b4d98
 tests/data/SPECS/hello-r2.spec | 58 +++++++++++++++++++++++++
Panu Matilainen 5b4d98
 tests/rpmbuildid.at            | 96 +++++++++++++++++++++++++++++++++++++++++-
Panu Matilainen 5b4d98
 tools/debugedit.c              | 24 ++++++++++-
Panu Matilainen 5b4d98
 5 files changed, 201 insertions(+), 5 deletions(-)
Panu Matilainen 5b4d98
 create mode 100644 tests/data/SPECS/hello-r2.spec
Panu Matilainen 5b4d98
Panu Matilainen 5b4d98
diff --git a/macros.in b/macros.in
Panu Matilainen 5b4d98
index e43d62b0..dcd0961 100644
Panu Matilainen 5b4d98
--- a/macros.in
Panu Matilainen 5b4d98
+++ b/macros.in
Panu Matilainen 5b4d98
@@ -180,7 +180,7 @@
Panu Matilainen 5b4d98
 #	the script.  See the script for details.
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
 %__debug_install_post   \
Panu Matilainen 5b4d98
-   %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_include_minidebuginfo:-m} %{?_find_debuginfo_dwz_opts} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"\
Panu Matilainen 5b4d98
+   %{_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}"\
Panu Matilainen 5b4d98
 %{nil}
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 #	Template for debug information sub-package.
Panu Matilainen 5b4d98
@@ -476,6 +476,12 @@ package or when debugging this package.\
Panu Matilainen 5b4d98
 #   ELF /usr/lib/debug/.build-id/xx/yyy -> /usr/lib/.build-id/xx/yyy
Panu Matilainen 5b4d98
 %_build_id_links compat
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
+# Whether build-ids should be made unique between package version/releases
Panu Matilainen 5b4d98
+# when generating debuginfo packages. If set to 1 this will pass
Panu Matilainen 5b4d98
+# --ver-rel "%{version}-%{release}" to find-debuginfo.sh which will pass it
Panu Matilainen 5b4d98
+# onto debugedit --build-id-seed to be used to prime the build-id note hash.
Panu Matilainen 5b4d98
+%_unique_build_ids	1
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
 # Use internal dependency generator rather than external helpers?
Panu Matilainen 5b4d98
 %_use_internal_dependency_generator	1
Panu Matilainen 5b4d98
diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
index c9e2293..2cb9570 100644
Panu Matilainen 5b4d98
--- a/scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
+++ b/scripts/find-debuginfo.sh
Panu Matilainen 5b4d98
@@ -6,6 +6,7 @@
Panu Matilainen 5b4d98
 #	 		   [-o debugfiles.list]
Panu Matilainen 5b4d98
 #			   [--run-dwz] [--dwz-low-mem-die-limit N]
Panu Matilainen 5b4d98
 #			   [--dwz-max-die-limit N]
Panu Matilainen 5b4d98
+#			   [--ver-rel VERSION-RELEASE]
Panu Matilainen 5b4d98
 #			   [[-l filelist]... [-p 'pattern'] -o debuginfo.list]
Panu Matilainen 5b4d98
 #			   [builddir]
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
@@ -26,6 +27,12 @@
Panu Matilainen 5b4d98
 # if available, and --dwz-low-mem-die-limit and --dwz-max-die-limit
Panu Matilainen 5b4d98
 # provide detailed limits.  See dwz(1) -l and -L option for details.
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
+# If --ver-rel VERSION-RELEASE is given then debugedit is called to
Panu Matilainen 5b4d98
+# update the build-ids it finds adding the VERSION-RELEASE string as
Panu Matilainen 5b4d98
+# seed to recalculate the build-id hash.  This makes sure the
Panu Matilainen 5b4d98
+# build-ids in the ELF files are unique between versions and releases
Panu Matilainen 5b4d98
+# of the same package.
Panu Matilainen 5b4d98
+#
Panu Matilainen 5b4d98
 # All file names in switches are relative to builddir (. if not given).
Panu Matilainen 5b4d98
 #
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
@@ -49,6 +56,9 @@ run_dwz=false
Panu Matilainen 5b4d98
 dwz_low_mem_die_limit=
Panu Matilainen 5b4d98
 dwz_max_die_limit=
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
+# Version and release of the spec. Given by --ver-rel
Panu Matilainen 5b4d98
+ver_rel=
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
 BUILDDIR=.
Panu Matilainen 5b4d98
 out=debugfiles.list
Panu Matilainen 5b4d98
 nout=0
Panu Matilainen 5b4d98
@@ -68,6 +78,10 @@ while [ $# -gt 0 ]; do
Panu Matilainen 5b4d98
     dwz_max_die_limit=$2
Panu Matilainen 5b4d98
     shift
Panu Matilainen 5b4d98
     ;;
Panu Matilainen 5b4d98
+  --ver-rel)
Panu Matilainen 5b4d98
+    ver_rel=$2
Panu Matilainen 5b4d98
+    shift
Panu Matilainen 5b4d98
+    ;;
Panu Matilainen 5b4d98
   -g)
Panu Matilainen 5b4d98
     strip_g=true
Panu Matilainen 5b4d98
     ;;
Panu Matilainen 5b4d98
@@ -249,8 +263,12 @@ while read nlinks inum f; do
Panu Matilainen 5b4d98
   fi
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
   echo "extracting debug info from $f"
Panu Matilainen 5b4d98
+  build_id_seed=
Panu Matilainen 5b4d98
+  if [ ! -z "$ver_rel" ]; then
Panu Matilainen 5b4d98
+    build_id_seed="--build-id-seed=$ver_rel"
Panu Matilainen 5b4d98
+  fi
Panu Matilainen 5b4d98
   id=$(${lib_rpm_dir}/debugedit -b "$RPM_BUILD_DIR" -d /usr/src/debug \
Panu Matilainen 5b4d98
-			      -i -l "$SOURCEFILE" "$f") || exit
Panu Matilainen 5b4d98
+			      -i $build_id_seed -l "$SOURCEFILE" "$f") || exit
Panu Matilainen 5b4d98
   if [ $nlinks -gt 1 ]; then
Panu Matilainen 5b4d98
     eval linkedid_$inum=\$id
Panu Matilainen 5b4d98
   fi
Panu Matilainen 5b4d98
diff --git a/tests/data/SPECS/hello-r2.spec b/tests/data/SPECS/hello-r2.spec
Panu Matilainen 5b4d98
new file mode 100644
Panu Matilainen 5b4d98
index 0000000..ca5091d
Panu Matilainen 5b4d98
--- /dev/null
Panu Matilainen 5b4d98
+++ b/tests/data/SPECS/hello-r2.spec
Panu Matilainen 5b4d98
@@ -0,0 +1,58 @@
Panu Matilainen 5b4d98
+Summary: hello -- hello, world rpm
Panu Matilainen 5b4d98
+Name: hello
Panu Matilainen 5b4d98
+Version: 1.0
Panu Matilainen 5b4d98
+Release: 2
Panu Matilainen 5b4d98
+Group: Utilities
Panu Matilainen 5b4d98
+License: GPL
Panu Matilainen 5b4d98
+Distribution: RPM test suite.
Panu Matilainen 5b4d98
+Vendor: Red Hat Software
Panu Matilainen 5b4d98
+Packager: Red Hat Software <bugs@redhat.com>
Panu Matilainen 5b4d98
+URL: http://www.redhat.com
Panu Matilainen 5b4d98
+Source0: hello-1.0.tar.gz
Panu Matilainen 5b4d98
+Patch0: hello-1.0-modernize.patch
Panu Matilainen 5b4d98
+Excludearch: lsi
Panu Matilainen 5b4d98
+Excludeos: cpm
Panu Matilainen 5b4d98
+Provides: hi
Panu Matilainen 5b4d98
+Conflicts: goodbye
Panu Matilainen 5b4d98
+Obsoletes: howdy
Panu Matilainen 5b4d98
+Prefix: /usr
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%description
Panu Matilainen 5b4d98
+Simple rpm demonstration.
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%prep
Panu Matilainen 5b4d98
+%setup -q
Panu Matilainen 5b4d98
+%patch0 -p1 -b .modernize
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%build
Panu Matilainen 5b4d98
+make
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%install
Panu Matilainen 5b4d98
+rm -rf $RPM_BUILD_ROOT
Panu Matilainen 5b4d98
+mkdir -p $RPM_BUILD_ROOT/usr/local/bin
Panu Matilainen 5b4d98
+make DESTDIR=$RPM_BUILD_ROOT install
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%clean
Panu Matilainen 5b4d98
+rm -rf $RPM_BUILD_ROOT
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%pre
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%post
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%preun
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%postun
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%files
Panu Matilainen 5b4d98
+%defattr(-,root,root)
Panu Matilainen 5b4d98
+%doc	FAQ
Panu Matilainen 5b4d98
+#%readme README
Panu Matilainen 5b4d98
+#%license COPYING
Panu Matilainen 5b4d98
+%attr(0751,root,root)	/usr/local/bin/hello
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+%changelog
Panu Matilainen 5b4d98
+* Wed Jun  8 2016 Mark Wielaard <mjw@redhat.com>
Panu Matilainen 5b4d98
+- Update release for unique build-id generation tests.
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+* Tue Oct 20 1998 Jeff Johnson <jbj@redhat.com>
Panu Matilainen 5b4d98
+- create.
Panu Matilainen 5b4d98
diff --git a/tests/rpmbuildid.at b/tests/rpmbuildid.at
Panu Matilainen 5b4d98
index eddca96..1da6302 100644
Panu Matilainen 5b4d98
--- a/tests/rpmbuildid.at
Panu Matilainen 5b4d98
+++ b/tests/rpmbuildid.at
Panu Matilainen 5b4d98
@@ -758,4 +758,98 @@ debug id in debug package
Panu Matilainen 5b4d98
 debug dup id in debug package
Panu Matilainen 5b4d98
 ],
Panu Matilainen 5b4d98
 [])
Panu Matilainen 5b4d98
-AT_CLEANUP
Panu Matilainen 5b4d98
\ No newline at end of file
Panu Matilainen 5b4d98
+AT_CLEANUP
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# ------------------------------
Panu Matilainen 5b4d98
+# Check build-ids are unique between versions/releases
Panu Matilainen 5b4d98
+# with _unique_build_ids defined.
Panu Matilainen 5b4d98
+AT_SETUP([rpmbuild buildid unique r1 r2])
Panu Matilainen 5b4d98
+AT_KEYWORDS([build] [debuginfo] [buildid])
Panu Matilainen 5b4d98
+AT_CHECK([
Panu Matilainen 5b4d98
+rm -rf ${TOPDIR}
Panu Matilainen 5b4d98
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# No warnings for hard links
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --define="_unique_build_ids 1" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-1.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+hello_file=./usr/local/bin/hello
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Extract the build-id from the main file
Panu Matilainen 5b4d98
+id1=$(file $hello_file | sed 's/.*, BuildID[.*]=\(.*\),.*/\1/')
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Build the "next" release, which has no changes except for the release update.
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --define="_unique_build_ids 1" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello-r2.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-2.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Extract the build-id from the main file
Panu Matilainen 5b4d98
+id2=$(file $hello_file | sed 's/.*, BuildID[.*]=\(.*\),.*/\1/')
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+if test "$id1" == "$id2"; then echo "equal $id1"; else echo "unequal"; fi
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[0],
Panu Matilainen 5b4d98
+[unequal
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[ignore])
Panu Matilainen 5b4d98
+AT_CLEANUP
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# ------------------------------
Panu Matilainen 5b4d98
+# Check build-ids are non-unique between versions/releases
Panu Matilainen 5b4d98
+# with _unique_build_ids undefined (and exact same sources).
Panu Matilainen 5b4d98
+AT_SETUP([rpmbuild buildid non-unique r1 r2])
Panu Matilainen 5b4d98
+AT_KEYWORDS([build] [debuginfo] [buildid])
Panu Matilainen 5b4d98
+AT_CHECK([
Panu Matilainen 5b4d98
+rm -rf ${TOPDIR}
Panu Matilainen 5b4d98
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-modernize.patch ${TOPDIR}/SOURCES
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# No warnings for hard links
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --undefine="_unique_build_ids" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-1.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+hello_file=./usr/local/bin/hello
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Extract the build-id from the main file
Panu Matilainen 5b4d98
+id1=$(file $hello_file | sed 's/.*, BuildID[.*]=\(.*\),.*/\1/')
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Build the "next" release, which has no changes except for the release update.
Panu Matilainen 5b4d98
+run rpmbuild --quiet \
Panu Matilainen 5b4d98
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Panu Matilainen 5b4d98
+  --rcfile=${abs_top_builddir}/rpmrc \
Panu Matilainen 5b4d98
+  --undefine="_unique_build_ids" \
Panu Matilainen 5b4d98
+  -ba "${abs_srcdir}"/data/SPECS/hello-r2.spec
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+rpm2cpio ${abs_builddir}/testing/build/RPMS/*/hello-1.0-2.*.rpm \
Panu Matilainen 5b4d98
+  | cpio -diu --quiet
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+# Extract the build-id from the main file
Panu Matilainen 5b4d98
+id2=$(file $hello_file | sed 's/.*, BuildID[.*]=\(.*\),.*/\1/')
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+if test "$id1" == "$id2"; then echo "equal"; else echo "unequal $id1 $id2"; fi
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[0],
Panu Matilainen 5b4d98
+[equal
Panu Matilainen 5b4d98
+],
Panu Matilainen 5b4d98
+[ignore])
Panu Matilainen 5b4d98
+AT_CLEANUP
Panu Matilainen 5b4d98
diff --git a/tools/debugedit.c b/tools/debugedit.c
Panu Matilainen 5b4d98
index cf89312..c0147f0 100644
Panu Matilainen 5b4d98
--- a/tools/debugedit.c
Panu Matilainen 5b4d98
+++ b/tools/debugedit.c
Panu Matilainen 5b4d98
@@ -1,4 +1,4 @@
Panu Matilainen 5b4d98
-/* Copyright (C) 2001, 2002, 2003, 2005, 2007, 2009, 2010, 2011 Red Hat, Inc.
Panu Matilainen 5b4d98
+/* Copyright (C) 2001-2003, 2005, 2007, 2009-2011, 2016 Red Hat, Inc.
Panu Matilainen 5b4d98
    Written by Alexander Larsson <alexl@redhat.com>, 2002
Panu Matilainen 5b4d98
    Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
@@ -54,6 +54,7 @@ char *dest_dir = NULL;
Panu Matilainen 5b4d98
 char *list_file = NULL;
Panu Matilainen 5b4d98
 int list_file_fd = -1;
Panu Matilainen 5b4d98
 int do_build_id = 0;
Panu Matilainen 5b4d98
+char *build_id_seed = NULL;
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
 typedef struct
Panu Matilainen 5b4d98
 {
Panu Matilainen 5b4d98
@@ -1296,6 +1297,8 @@ static struct poptOption optionsTable[] = {
Panu Matilainen 5b4d98
       "file where to put list of source and header file names", NULL },
Panu Matilainen 5b4d98
     { "build-id",  'i', POPT_ARG_NONE, &do_build_id, 0,
Panu Matilainen 5b4d98
       "recompute build ID note and print ID on stdout", NULL },
Panu Matilainen 5b4d98
+    { "build-id-seed", 's', POPT_ARG_STRING, &build_id_seed, 0,
Panu Matilainen 5b4d98
+      "if recomputing the build ID note use this string as hash seed", NULL },
Panu Matilainen 5b4d98
       POPT_AUTOHELP
Panu Matilainen 5b4d98
     { NULL, 0, 0, NULL, 0, NULL, NULL }
Panu Matilainen 5b4d98
 };
Panu Matilainen 5b4d98
@@ -1400,7 +1403,7 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
Panu Matilainen 5b4d98
       exit (1);
Panu Matilainen 5b4d98
     }
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
-  if (!dirty_elf)
Panu Matilainen 5b4d98
+  if (!dirty_elf && build_id_seed == NULL)
Panu Matilainen 5b4d98
     goto print;
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
   if (elf_update (dso->elf, ELF_C_NULL) < 0)
Panu Matilainen 5b4d98
@@ -1415,6 +1418,10 @@ handle_build_id (DSO *dso, Elf_Data *build_id,
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
   ctx = rpmDigestInit(algorithm, 0);
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
+  /* If a seed string was given use it to prime the hash.  */
Panu Matilainen 5b4d98
+  if (build_id_seed != NULL)
Panu Matilainen 5b4d98
+    rpmDigestUpdate(ctx, build_id_seed, strlen (build_id_seed));
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
   /* Slurp the relevant header bits and section contents and feed them
Panu Matilainen 5b4d98
      into the hash function.  The only bits we ignore are the offset
Panu Matilainen 5b4d98
      fields in ehdr and shdrs, since the semantically identical ELF file
Panu Matilainen 5b4d98
@@ -1541,6 +1548,19 @@ main (int argc, char *argv[])
Panu Matilainen 5b4d98
 	}
Panu Matilainen 5b4d98
     }
Panu Matilainen 5b4d98
 
Panu Matilainen 5b4d98
+  if (build_id_seed != NULL && do_build_id == 0)
Panu Matilainen 5b4d98
+    {
Panu Matilainen 5b4d98
+      fprintf (stderr, "--build-id-seed (-s) needs --build-id (-i)\n");
Panu Matilainen 5b4d98
+      exit (1);
Panu Matilainen 5b4d98
+    }
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
+  if (build_id_seed != NULL && strlen (build_id_seed) < 1)
Panu Matilainen 5b4d98
+    {
Panu Matilainen 5b4d98
+      fprintf (stderr,
Panu Matilainen 5b4d98
+	       "--build-id-seed (-s) string should be at least 1 char\n");
Panu Matilainen 5b4d98
+      exit (1);
Panu Matilainen 5b4d98
+    }
Panu Matilainen 5b4d98
+
Panu Matilainen 5b4d98
   /* Ensure clean paths, users can muck with these */
Panu Matilainen 5b4d98
   if (base_dir)
Panu Matilainen 5b4d98
     canonicalize_path(base_dir, base_dir);
Panu Matilainen 5b4d98
-- 
Panu Matilainen 5b4d98
2.9.3
Panu Matilainen 5b4d98