]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Allow assertions to be globally enabled or disabled
authorMichael Brown <mcb30@ipxe.org>
Tue, 5 Jul 2016 12:28:51 +0000 (13:28 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 5 Jul 2016 12:28:51 +0000 (13:28 +0100)
Assertions are enabled for objects built with any debug level
(including an explicit debug level of zero).  It is sometimes useful
to be able to enable assertions across all objects; this currently
requires manually hacking include/assert.h.

Allow assertions to be globally enabled by adding ASSERT=1 to the
build command line.  For example:

  make bin/8086100e.mrom ASSERT=1

Similarly, allow assertions to be globally disabled by adding ASSERT=0
to the build command line.  If no ASSERT=... is specified on the
build command line, then only objects mentioned in DEBUG=... will have
assertions enabled (as is currently the case).

Note than globally enabling assertions imposes a relatively heavy
runtime penalty, primarily due to the various sanity checks performed
by list_add(), list_for_each_entry(), etc.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/Makefile.housekeeping
src/include/assert.h

index 264b9d0f949020fda568119caf72b7babc00685e..a02acc8ddcdaf7ebc439b50b0ab6410c9c55d289 100644 (file)
@@ -720,6 +720,33 @@ config/named.h : $(CONFIG_LIST)
 
 .PRECIOUS : config/named.h
 
+# (Single-element) list of assertion configuration
+#
+ASSERT_LIST := $(BIN)/.assert.list
+ifeq ($(wildcard $(ASSERT_LIST)),)
+ASSERT_OLD := <invalid>
+else
+ASSERT_OLD := $(shell cat $(ASSERT_LIST))
+endif
+ifneq ($(ASSERT_OLD),$(ASSERT))
+$(shell $(ECHO) "$(ASSERT)" > $(ASSERT_LIST))
+endif
+
+$(ASSERT_LIST) : $(MAKEDEPS)
+
+VERYCLEANUP += $(ASSERT_LIST)
+
+# Assertion configuration
+#
+ifneq ($(ASSERT),)
+CFLAGS += -DASSERTING=$(ASSERT)
+endif
+
+include/assert.h : $(ASSERT_LIST)
+       $(Q)$(TOUCH) $@
+
+.PRECIOUS : include/assert.h
+
 # These files use .incbin inline assembly to include a binary file.
 # Unfortunately ccache does not detect this dependency and caches
 # builds even when the binary file has changed.
index 07f3ecb8c96f68721141963dbc7094febc90da4d..dd71fa7137c3fbbb5139424b82b4d52c04e54b31 100644 (file)
 
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
+#ifndef ASSERTING
 #ifdef NDEBUG
 #define ASSERTING 0
 #else
 #define ASSERTING 1
 #endif
+#endif
 
 extern unsigned int assertion_failures;