qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] configure: Poison (almost) all target-specific #defines
@ 2021-03-15 13:54 Thomas Huth
  2021-03-15 14:07 ` Claudio Fontana
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Thomas Huth @ 2021-03-15 13:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini

We are generating a lot of target-specific defines in the *-config-devices.h
and *-config-target.h files. Using them in common code is wrong and leads
to very subtle bugs since a "#ifdef CONFIG_SOMETHING" is not working there
as expected. To avoid these issues, we are already poisoning some of the
macros in include/exec/poison.h - but maintaining this list manually is
cumbersome. Thus let's generate the list of poisoned macros automatically
instead.
Note that CONFIG_TCG (which is also defined in config-host.h) and
CONFIG_USER_ONLY are special, so we have to filter these out.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 RFC since the shell stuff in "configure" is quite ugly ... maybe there's
 a better way to do this via meson, but my meson-foo is still lacking...

 Makefile              | 2 +-
 configure             | 5 +++++
 include/exec/poison.h | 2 ++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index bcbbec71a1..4cab10a2a4 100644
--- a/Makefile
+++ b/Makefile
@@ -213,7 +213,7 @@ qemu-%.tar.bz2:
 
 distclean: clean
 	-$(quiet-@)test -f build.ninja && $(NINJA) $(NINJAFLAGS) -t clean -g || :
-	rm -f config-host.mak config-host.h*
+	rm -f config-host.mak config-host.h* config-poison.h
 	rm -f tests/tcg/config-*.mak
 	rm -f config-all-disas.mak config.status
 	rm -f roms/seabios/config.mak roms/vgabios/config.mak
diff --git a/configure b/configure
index f7d022a5db..c7b5df3a5c 100755
--- a/configure
+++ b/configure
@@ -6441,6 +6441,11 @@ if test -n "${deprecated_features}"; then
     echo "  features: ${deprecated_features}"
 fi
 
+cat *-config-devices.h *-config-target.h | grep '^#define '  \
+    | grep -v CONFIG_TCG | grep -v CONFIG_USER_ONLY \
+    | sed -e 's/#define //' -e 's/ .*//' | sort -u \
+    | sed -e 's/^/#pragma GCC poison /' > config-poison.h
+
 # Save the configure command line for later reuse.
 cat <<EOD >config.status
 #!/bin/sh
diff --git a/include/exec/poison.h b/include/exec/poison.h
index 4cd3f8abb4..9e55d5aec2 100644
--- a/include/exec/poison.h
+++ b/include/exec/poison.h
@@ -4,6 +4,8 @@
 #ifndef HW_POISON_H
 #define HW_POISON_H
 
+#include "config-poison.h"
+
 #pragma GCC poison TARGET_I386
 #pragma GCC poison TARGET_X86_64
 #pragma GCC poison TARGET_AARCH64
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-16  5:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-15 13:54 [RFC PATCH] configure: Poison (almost) all target-specific #defines Thomas Huth
2021-03-15 14:07 ` Claudio Fontana
2021-03-15 15:08   ` Thomas Huth
2021-03-15 15:22     ` Claudio Fontana
2021-03-15 14:52 ` Philippe Mathieu-Daudé
2021-03-15 15:24   ` Thomas Huth
2021-03-15 15:37     ` Peter Maydell
2021-03-15 15:52       ` Thomas Huth
2021-03-15 18:24 ` Eric Blake
2021-03-16  5:28   ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).