ENABLE_CHECKING in bfd, opcodes, binutils, ld

Message ID 20210412150534.GE5425@bubble.grove.modra.org
State New
Headers show
Series
  • ENABLE_CHECKING in bfd, opcodes, binutils, ld
Related show

Commit Message

Luis Machado via Binutils April 12, 2021, 3:05 p.m.
gas already has this.  Here it enables checking hash table type passed
to elf_link_hash_lookup and elf_link_hash_traverse.

bfd/
	* elf-bfd.h (ENABLE_CHECKING): Define.
	(elf_link_hash_lookup): Abort if wrong type of hash table.
	(elf_link_hash_traverse): Likewise.
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
binutils/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
ld/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.
opcodes/
	* configure.ac (--enable-checking): Add support.
	* config.in: Regenerate.
	* configure: Regenerate.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/configure.ac b/bfd/configure.ac
index c016fd087a4..07a75ed1626 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -69,6 +69,19 @@  esac
 
 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
 
+ac_checking=
+. ${srcdir}/development.sh
+test "$development" = true && ac_checking=yes
+AC_ARG_ENABLE(checking,
+[  --enable-checking       enable run-time checks],
+[case "${enableval}" in
+  no|none)  ac_checking= ;;
+  *)	    ac_checking=yes ;;
+esac])dnl
+if test x$ac_checking != x ; then
+  AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want run-time sanity checks.])
+fi
+
 AC_ARG_ENABLE(64-bit-bfd,
 [  --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)],
 [case "${enableval}" in
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index e0b7e5759ad..5a2f64233f9 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -27,6 +27,10 @@ 
 #include "elf/internal.h"
 #include "bfdlink.h"
 
+#ifndef ENABLE_CHECKING
+#define ENABLE_CHECKING 0
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -721,6 +725,8 @@  static inline struct elf_link_hash_entry *
 elf_link_hash_lookup (struct elf_link_hash_table *table, const char *string,
 		      bool create, bool copy, bool follow)
 {
+  if (ENABLE_CHECKING && !is_elf_hash_table (&table->root))
+    abort ();
   return (struct elf_link_hash_entry *)
     bfd_link_hash_lookup (&table->root, string, create, copy, follow);
 }
@@ -732,6 +738,8 @@  elf_link_hash_traverse (struct elf_link_hash_table *table,
 			bool (*f) (struct elf_link_hash_entry *, void *),
 			void *info)
 {
+  if (ENABLE_CHECKING && !is_elf_hash_table (&table->root))
+    abort ();
   bfd_link_hash_traverse (&table->root,
 			  (bool (*) (struct bfd_link_hash_entry *, void *)) f,
 			  info);
diff --git a/binutils/configure.ac b/binutils/configure.ac
index ad6d2aaefad..2553b809e6c 100644
--- a/binutils/configure.ac
+++ b/binutils/configure.ac
@@ -33,6 +33,19 @@  AC_USE_SYSTEM_EXTENSIONS
 LT_INIT
 ACX_LARGEFILE
 
+ac_checking=
+. ${srcdir}/../bfd/development.sh
+test "$development" = true && ac_checking=yes
+AC_ARG_ENABLE(checking,
+[  --enable-checking       enable run-time checks],
+[case "${enableval}" in
+  no|none)  ac_checking= ;;
+  *)	    ac_checking=yes ;;
+esac])dnl
+if test x$ac_checking != x ; then
+  AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want run-time sanity checks.])
+fi
+
 AC_ARG_ENABLE(targets,
 [  --enable-targets        alternative target configurations],
 [case "${enableval}" in
diff --git a/ld/configure.ac b/ld/configure.ac
index 5429f22ac23..8ea97c43cd4 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -37,6 +37,19 @@  AC_PROG_INSTALL
 LT_INIT
 ACX_LARGEFILE
 
+ac_checking=
+. ${srcdir}/../bfd/development.sh
+test "$development" = true && ac_checking=yes
+AC_ARG_ENABLE(checking,
+[  --enable-checking       enable run-time checks],
+[case "${enableval}" in
+  no|none)  ac_checking= ;;
+  *)	    ac_checking=yes ;;
+esac])dnl
+if test x$ac_checking != x ; then
+  AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want run-time sanity checks.])
+fi
+
 AC_ARG_WITH(lib-path, [  --with-lib-path=dir1:dir2...  set default LIB_PATH],LIB_PATH=$withval)
 AC_ARG_ENABLE(targets,
 [  --enable-targets        alternative target configurations],
diff --git a/opcodes/configure.ac b/opcodes/configure.ac
index 7cf0d2968b2..911c9c6f082 100644
--- a/opcodes/configure.ac
+++ b/opcodes/configure.ac
@@ -40,6 +40,19 @@  AC_DISABLE_SHARED
 
 LT_INIT
 
+ac_checking=
+. ${srcdir}/../bfd/development.sh
+test "$development" = true && ac_checking=yes
+AC_ARG_ENABLE(checking,
+[  --enable-checking       enable run-time checks],
+[case "${enableval}" in
+  no|none)  ac_checking= ;;
+  *)	    ac_checking=yes ;;
+esac])dnl
+if test x$ac_checking != x ; then
+  AC_DEFINE(ENABLE_CHECKING, 1, [Define if you want run-time sanity checks.])
+fi
+
 AC_ARG_ENABLE(targets,
 [  --enable-targets        alternative target configurations],
 [case "${enableval}" in