[PATCH] Make sure to always build with build-ids.

Mark Wielaard mark@klomp.org
Fri Dec 6 16:25:00 GMT 2019


We really need build-ids for various things.  If the system compiler
doesn't generate build-ids warn and generate them anyway for both the
binaries and the tests.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog                    | 4 ++++
 configure.ac                 | 9 +++++++++
 tests/ChangeLog              | 4 ++++
 tests/run-debuginfod-find.sh | 4 ++--
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0e229622..ed5f5866 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-06  Mark Wielaard  <mark@klomp.org>
+
+	* configure.ac: Add ac_cv_buildid check.
+
 2019-11-26  Mark Wielaard  <mark@klomp.org>
 
 	* configure.ac: Set version to 0.178.
diff --git a/configure.ac b/configure.ac
index 5a2dc373..9defe9fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -197,6 +197,15 @@ if test "$ac_cv_zdefs" = "yes"; then
 	dso_LDFLAGS="$dso_LDFLAGS $ZDEFS_LDFLAGS"
 fi
 
+# We really want build-ids. Warn and force generating them if gcc was
+# configure without --enable-linker-build-id
+AC_CACHE_CHECK([whether the compiler generates build-ids], ac_cv_buildid, [dnl
+AC_LINK_IFELSE([AC_LANG_PROGRAM()],[ac_cv_buildid=yes; readelf -n conftest$EXEEXT | grep -q NT_GNU_BUILD_ID || ac_cv_buildid=no],AC_MSG_FAILURE([unexpected compile failure]))])
+if test "$ac_cv_buildid" = "no"; then
+	AC_MSG_WARN([compiler doesn't generate build-id by default])
+	CFLAGS="$CFLAGS -Wl,--build-id"
+fi
+
 ZRELRO_LDFLAGS="-Wl,-z,relro"
 AC_CACHE_CHECK([whether gcc supports $ZRELRO_LDFLAGS], ac_cv_zrelro, [dnl
 save_LDFLAGS="$LDFLAGS"
diff --git a/tests/ChangeLog b/tests/ChangeLog
index ffa4ef51..ce67ce55 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-06  Mark Wielaard  <mark@klomp.org>
+
+	* run-debuginfod-find.sh: Force -Wl,--build-id.
+
 2019-12-05  Mark Wielaard  <mark@klomp.org>
 
 	* run-findinfod-find.sh: Run strip under testrun.
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 6f92fbf1..6533996a 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -101,7 +101,7 @@ export DEBUGINFOD_TIMEOUT=10
 # cannot find it without debuginfod.
 echo "int main() { return 0; }" > ${PWD}/prog.c
 tempfiles prog.c
-gcc -g -o prog ${PWD}/prog.c
+gcc -Wl,--build-id -g -o prog ${PWD}/prog.c
 testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
 BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
           -a prog | grep 'Build ID' | cut -d ' ' -f 7`
@@ -138,7 +138,7 @@ cmp $filename  ${PWD}/prog.c
 # Build another, non-stripped binary
 echo "int main() { return 0; }" > ${PWD}/prog2.c
 tempfiles prog2.c
-gcc -g -o prog2 ${PWD}/prog2.c
+gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
 BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
           -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
 
-- 
2.20.1



More information about the Elfutils-devel mailing list