From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdbsupport: better detection of -Wmissing-prototypes support
Date: Fri, 24 Sep 2021 13:29:33 +0100 [thread overview]
Message-ID: <20210924122933.2714720-1-andrew.burgess@embecosm.com> (raw)
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
next reply other threads:[~2021-09-24 12:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-24 12:29 Andrew Burgess [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210924122933.2714720-1-andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox