Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCHv2] gdbsupport: better detection of -Wmissing-prototypes support
Date: Fri, 24 Sep 2021 16:14:17 +0100	[thread overview]
Message-ID: <20210924151417.2843353-1-andrew.burgess@embecosm.com> (raw)
In-Reply-To: <20210924122933.2714720-1-andrew.burgess@embecosm.com>

I know there's still some discussion about what the best way to deal
with this might be, but here's an updated patch that just uses
AM_LINK_IFELSE for all the AM_GDB_WARNINGS tests.

If the preference is for a different approach, I'm happy to go with
something else instead.

Thanks,
Andrew

---

When building using ccache 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 an issue with ccache and gcc relating to
option ordering, these are described here:

  https://github.com/ccache/ccache/issues/738
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87161

Basically, ccache reorders some command line options, so this:

  -Werror -Wmissing-prototypes

becomes:

  -Wmissing-prototypes -Werror

And, so, when g++ sees the -Wmissing-prototypes option, it has not yet
seen -Werror, and as -Wmissing-prototypes is not supported in g++, a
warning is immediately issued.

What this means is that when the AM_GDB_WARNINGS macro tries to test
if -Wmissing-prototypes is support on g++ (and if the user is using
ccache), then all the macro ever sees is a warning, not an error, and
so the macro assumes that -Wmissing-prototypes is supported.

Now the AM_GDB_WARNINGS makes use of AM_COMPILE_IFELSE to compile a
test file to object format.  IF instead we use AM_LINK_IFELSE then the
compiler will be invoked to take the source file all the way to
executable format.

Now, when ccache sees the compiler invoked to do a full build (to
executable), ccache does not activate, and there is not command line
flag reordering, and so, we get an error for -Wmissing-prototypes
rather than a warning, and this flag will not be used (for g++).
---
 gdb/configure         | 26 ++++++++++++++++++++++----
 gdbserver/configure   | 26 ++++++++++++++++++++++----
 gdbsupport/configure  | 26 ++++++++++++++++++++++----
 gdbsupport/warning.m4 | 20 ++++++++++++++++++--
 4 files changed, 84 insertions(+), 14 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index f0b1af4a6ea..41df4d22b88 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -16993,6 +16993,22 @@ $as_echo_n "checking compiler warning flags... " >&6; }
 	    CFLAGS="$CFLAGS -Werror $wtest"
 	    saved_CXXFLAGS="$CXXFLAGS"
 	    CXXFLAGS="$CXXFLAGS -Werror $wtest"
+            # In the following tests we use AC_LINK_IFELSE rather than
+            # AC_COMPILE_IFELSE, this works around this issue when
+            # using ccache: https://github.com/ccache/ccache/issues/738.
+            #
+            # Basically, ccache will reorder -Werror with respect to
+            # other command line options, placing -Werror after other
+            # options.  If the problem with the command line option is
+            # that it is not supported in the current language
+            # (e.g. -Wmissing-prototypes for g++), then this means
+            # that you'll get a warning and not an error about the
+            # option.
+            #
+            # However, if we perform a full link then ccache will not
+            # kick in (ccache only activates when compiling to object
+            # format), and so the options are not reordered, and we'll
+            # get an error for any unsupported options.
 	    if test "x$w" = "x-Wunused-variable"; then
 	      # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
 	      # fixed in GCC 4.9.  This test is derived from the gdb
@@ -17012,10 +17028,11 @@ const scoped_restore_base &b = scoped_restore_tmpl();
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+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.  */
@@ -17028,10 +17045,11 @@ main ()
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    fi
 	    CFLAGS="$saved_CFLAGS"
 	    CXXFLAGS="$saved_CXXFLAGS"
diff --git a/gdbserver/configure b/gdbserver/configure
index b227167e270..23f1fc4d022 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -9743,6 +9743,22 @@ $as_echo_n "checking compiler warning flags... " >&6; }
 	    CFLAGS="$CFLAGS -Werror $wtest"
 	    saved_CXXFLAGS="$CXXFLAGS"
 	    CXXFLAGS="$CXXFLAGS -Werror $wtest"
+            # In the following tests we use AC_LINK_IFELSE rather than
+            # AC_COMPILE_IFELSE, this works around this issue when
+            # using ccache: https://github.com/ccache/ccache/issues/738.
+            #
+            # Basically, ccache will reorder -Werror with respect to
+            # other command line options, placing -Werror after other
+            # options.  If the problem with the command line option is
+            # that it is not supported in the current language
+            # (e.g. -Wmissing-prototypes for g++), then this means
+            # that you'll get a warning and not an error about the
+            # option.
+            #
+            # However, if we perform a full link then ccache will not
+            # kick in (ccache only activates when compiling to object
+            # format), and so the options are not reordered, and we'll
+            # get an error for any unsupported options.
 	    if test "x$w" = "x-Wunused-variable"; then
 	      # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
 	      # fixed in GCC 4.9.  This test is derived from the gdb
@@ -9762,10 +9778,11 @@ const scoped_restore_base &b = scoped_restore_tmpl();
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+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.  */
@@ -9778,10 +9795,11 @@ main ()
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    fi
 	    CFLAGS="$saved_CFLAGS"
 	    CXXFLAGS="$saved_CXXFLAGS"
diff --git a/gdbsupport/configure b/gdbsupport/configure
index a9dd02c5b72..43c7b06d135 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -10228,6 +10228,22 @@ $as_echo_n "checking compiler warning flags... " >&6; }
 	    CFLAGS="$CFLAGS -Werror $wtest"
 	    saved_CXXFLAGS="$CXXFLAGS"
 	    CXXFLAGS="$CXXFLAGS -Werror $wtest"
+            # In the following tests we use AC_LINK_IFELSE rather than
+            # AC_COMPILE_IFELSE, this works around this issue when
+            # using ccache: https://github.com/ccache/ccache/issues/738.
+            #
+            # Basically, ccache will reorder -Werror with respect to
+            # other command line options, placing -Werror after other
+            # options.  If the problem with the command line option is
+            # that it is not supported in the current language
+            # (e.g. -Wmissing-prototypes for g++), then this means
+            # that you'll get a warning and not an error about the
+            # option.
+            #
+            # However, if we perform a full link then ccache will not
+            # kick in (ccache only activates when compiling to object
+            # format), and so the options are not reordered, and we'll
+            # get an error for any unsupported options.
 	    if test "x$w" = "x-Wunused-variable"; then
 	      # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
 	      # fixed in GCC 4.9.  This test is derived from the gdb
@@ -10247,10 +10263,11 @@ const scoped_restore_base &b = scoped_restore_tmpl();
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+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.  */
@@ -10263,10 +10280,11 @@ main ()
   return 0;
 }
 _ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
+if ac_fn_cxx_try_link "$LINENO"; then :
   WARN_CFLAGS="${WARN_CFLAGS} $w"
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 	    fi
 	    CFLAGS="$saved_CFLAGS"
 	    CXXFLAGS="$saved_CXXFLAGS"
diff --git a/gdbsupport/warning.m4 b/gdbsupport/warning.m4
index 46036fa461e..53dc59bc490 100644
--- a/gdbsupport/warning.m4
+++ b/gdbsupport/warning.m4
@@ -135,11 +135,27 @@ then
 	    CFLAGS="$CFLAGS -Werror $wtest"
 	    saved_CXXFLAGS="$CXXFLAGS"
 	    CXXFLAGS="$CXXFLAGS -Werror $wtest"
+            # In the following tests we use AC_LINK_IFELSE rather than
+            # AC_COMPILE_IFELSE, this works around this issue when
+            # using ccache: https://github.com/ccache/ccache/issues/738.
+            #
+            # Basically, ccache will reorder -Werror with respect to
+            # other command line options, placing -Werror after other
+            # options.  If the problem with the command line option is
+            # that it is not supported in the current language
+            # (e.g. -Wmissing-prototypes for g++), then this means
+            # that you'll get a warning and not an error about the
+            # option.
+            #
+            # However, if we perform a full link then ccache will not
+            # kick in (ccache only activates when compiling to object
+            # format), and so the options are not reordered, and we'll
+            # get an error for any unsupported options.
 	    if test "x$w" = "x-Wunused-variable"; then
 	      # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
 	      # fixed in GCC 4.9.  This test is derived from the gdb
 	      # source code that triggered this bug in GCC.
-	      AC_COMPILE_IFELSE(
+	      AC_LINK_IFELSE(
 		[AC_LANG_PROGRAM(
 		   [struct scoped_restore_base {};
 		    struct scoped_restore_tmpl : public scoped_restore_base {
@@ -151,7 +167,7 @@ then
 		[]
 	      )
 	    else
-	      AC_COMPILE_IFELSE(
+	      AC_LINK_IFELSE(
 		[AC_LANG_PROGRAM([], [])],
 		[WARN_CFLAGS="${WARN_CFLAGS} $w"],
 		[]
-- 
2.25.4


  parent reply	other threads:[~2021-09-24 15:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-24 12:29 [PATCH] " 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 ` Andrew Burgess [this message]
2021-10-25 14:50   ` [PATCHv2] " 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=20210924151417.2843353-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