Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdbsupport: better detection of -Wmissing-prototypes support
@ 2021-09-24 12:29 Andrew Burgess
  2021-09-24 13:16 ` Andrew Burgess
  2021-09-24 15:14 ` [PATCHv2] " Andrew Burgess
  0 siblings, 2 replies; 10+ messages in thread
From: Andrew Burgess @ 2021-09-24 12:29 UTC (permalink / raw)
  To: gdb-patches

When building with GCC 9.3.1 I notice lots of warnings like this while
building GDB:

  cc1plus: warning: command line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++

This is a little strange as the configure macro, AM_GDB_WARNINGS,
should figure out which warning flags are valid, and which are not.

It turns out that there's a weird bug in some older version of GCC;
when performing only a compile, the -Wmissing-prototypes flag will
only ever produce a warning, even when -Werror is passed.  If a full
compile and link is performed then an error is produced (assuming
-Werror is passed).

Of course, the AM_GDB_WARNINGS macro only tests each flag during a
compile, not a compile and link, so the macro figures that the
-Wmissing-prototypes flag is valid (even though a warning is emitted),
and adds it to the set of flags to use.

In this commit I special case the -Wmissing-prototypes check inside
AM_GDB_WARNINGS, and for that flag only, we now perform a full compile
and link.  This means that the configure script can correctly detect
that the flag is not supported, and so the flag is no longer used.
---
 gdb/configure         | 25 +++++++++++++++++++++++++
 gdbserver/configure   | 25 +++++++++++++++++++++++++
 gdbsupport/configure  | 25 +++++++++++++++++++++++++
 gdbsupport/warning.m4 | 14 ++++++++++++++
 4 files changed, 89 insertions(+)

diff --git a/gdb/configure b/gdb/configure
index f0b1af4a6ea..1bd9a7698b7 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -17016,6 +17016,31 @@ if ac_fn_cxx_try_compile "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+            elif test "x$w" = "x-Wmissing-prototypes"; then
+              # On some versions of GCC, e.g. 9.3.1, even when -Werror
+              # is passed, the -Wmissing-prototypes flag will only
+              # ever produce a warning when compiling, but, will
+              # produce an error when a full link is performed.  This
+              # bug is fixed in later versions of GCC.
+              #
+              # To avoid this bug, and detect if -Wmissing-prototypes
+              # is supported, we do a compile and link here.
+	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  WARN_CFLAGS="${WARN_CFLAGS} $w"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    else
 	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
diff --git a/gdbserver/configure b/gdbserver/configure
index b227167e270..c12354f583c 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -9766,6 +9766,31 @@ if ac_fn_cxx_try_compile "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+            elif test "x$w" = "x-Wmissing-prototypes"; then
+              # On some versions of GCC, e.g. 9.3.1, even when -Werror
+              # is passed, the -Wmissing-prototypes flag will only
+              # ever produce a warning when compiling, but, will
+              # produce an error when a full link is performed.  This
+              # bug is fixed in later versions of GCC.
+              #
+              # To avoid this bug, and detect if -Wmissing-prototypes
+              # is supported, we do a compile and link here.
+	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  WARN_CFLAGS="${WARN_CFLAGS} $w"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    else
 	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
diff --git a/gdbsupport/configure b/gdbsupport/configure
index a9dd02c5b72..ff8eb517d9e 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -10251,6 +10251,31 @@ if ac_fn_cxx_try_compile "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+            elif test "x$w" = "x-Wmissing-prototypes"; then
+              # On some versions of GCC, e.g. 9.3.1, even when -Werror
+              # is passed, the -Wmissing-prototypes flag will only
+              # ever produce a warning when compiling, but, will
+              # produce an error when a full link is performed.  This
+              # bug is fixed in later versions of GCC.
+              #
+              # To avoid this bug, and detect if -Wmissing-prototypes
+              # is supported, we do a compile and link here.
+	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  WARN_CFLAGS="${WARN_CFLAGS} $w"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    else
 	      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
diff --git a/gdbsupport/warning.m4 b/gdbsupport/warning.m4
index 46036fa461e..7bb8176b50f 100644
--- a/gdbsupport/warning.m4
+++ b/gdbsupport/warning.m4
@@ -150,6 +150,20 @@ then
 		[WARN_CFLAGS="${WARN_CFLAGS} $w"],
 		[]
 	      )
+            elif test "x$w" = "x-Wmissing-prototypes"; then
+              # On some versions of GCC, e.g. 9.3.1, even when -Werror
+              # is passed, the -Wmissing-prototypes flag will only
+              # ever produce a warning when compiling, but, will
+              # produce an error when a full link is performed.  This
+              # bug is fixed in later versions of GCC.
+              #
+              # To avoid this bug, and detect if -Wmissing-prototypes
+              # is supported, we do a compile and link here.
+	      AC_LINK_IFELSE(
+		[AC_LANG_PROGRAM([],[])],
+		[WARN_CFLAGS="${WARN_CFLAGS} $w"],
+		[]
+	      )
 	    else
 	      AC_COMPILE_IFELSE(
 		[AC_LANG_PROGRAM([], [])],
-- 
2.25.4


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

end of thread, other threads:[~2021-10-25 14:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 12:29 [PATCH] gdbsupport: better detection of -Wmissing-prototypes support Andrew Burgess
2021-09-24 13:16 ` Andrew Burgess
2021-09-24 13:40   ` Simon Marchi via Gdb-patches
2021-09-24 14:06     ` Pedro Alves
2021-09-24 14:22       ` Simon Marchi via Gdb-patches
2021-09-24 14:30         ` Pedro Alves
2021-09-24 14:55           ` Simon Marchi via Gdb-patches
2021-09-24 15:09             ` Pedro Alves
2021-09-24 15:14 ` [PATCHv2] " Andrew Burgess
2021-10-25 14:50   ` Simon Marchi via Gdb-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox