From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id e3RjH13rTWEFPAAAWB0awg (envelope-from ) for ; Fri, 24 Sep 2021 11:14:37 -0400 Received: by simark.ca (Postfix, from userid 112) id 6FA2F1EE25; Fri, 24 Sep 2021 11:14:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E3CCC1EDDB for ; Fri, 24 Sep 2021 11:14:35 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E4863858034 for ; Fri, 24 Sep 2021 15:14:35 +0000 (GMT) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id A4F273858402 for ; Fri, 24 Sep 2021 15:14:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4F273858402 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id w17so28424376wrv.10 for ; Fri, 24 Sep 2021 08:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=io0OgghBBzoEObV+Knrlo2EX8mKYyfrAt45b5fy1xic=; b=QE7umJOHq77LFSfCz3iZpIYJQmbzMEYB3DPVb9OHQlV/+CH/ozjs8gp5fP3S0lX9NP N0GID1uJhgnUMdIprzMNTVgdU1IntJYRFrVZeLgQMEFIou18vsUYpdyCgriQF6PBocVK yk224G3h3a48uPOx6PjjxNW6I9HTemqWXhR5veU2NCr/4JGVTwtGIK3gCXBwuP/sKbZK z7CUnhRep+k9pQQcPaxZPXRHoe4LJCYyuFNsN6+nwF317/0/GcOexSElnIatOhRhNs1N p+8l73oulEDAUyvkXWocP0uCZ+0wVbKhvb2ebjQNUu/iw8YdV90QivUzEW1hjOl9vi52 WxTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=io0OgghBBzoEObV+Knrlo2EX8mKYyfrAt45b5fy1xic=; b=hDM0IOWl+e4wWxMFsISPoTsQWT9LWdbhqIqsguOZluueTIQ4FtnwBKF+h76gWigfYv ijuXa+yhId8RVwR39i8nJtbF42/87qVfZ/iVLzRMf+S67fy8SAiNqsMMb7eRNbMuWuoP 9fzph7dBGOk6v+JhOnzSO4+7F2ILzBJHuqTCi0YCpZhqUQASKMJIFkmVNJywMT6Wj41m bVCMjZbRHQiXnemKn6WtjrWPVW/815JO40VT3pcliZU0oaoP9IlfjMrcwJunvtkFbSav 64kzNCR3W8/s0y5e9FRxB9kVY7aGpykfv47GXy9rrqnkmOHmBVgRnnO/QO7evOYWLPss F7SA== X-Gm-Message-State: AOAM530F8mmDo4U7Lbd7Q4sVZXMKCwrsM94tLAlTIxRF4uL7t8YKgr6K dzTXPooEce62d063BQBvCJF0VQE16kD9hg== X-Google-Smtp-Source: ABdhPJzKlf2pXEM+Prh+kRqTT7D7lvTtxEMIcd23Q1/cji8MJ/X5mojIkWQ+LZkeAcd+Bd/OgDnnkA== X-Received: by 2002:a7b:cf36:: with SMTP id m22mr1295077wmg.194.1632496462278; Fri, 24 Sep 2021 08:14:22 -0700 (PDT) Received: from localhost (host86-169-137-11.range86-169.btcentralplus.com. [86.169.137.11]) by smtp.gmail.com with ESMTPSA id m29sm8690043wrb.89.2021.09.24.08.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 08:14:21 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCHv2] gdbsupport: better detection of -Wmissing-prototypes support Date: Fri, 24 Sep 2021 16:14:17 +0100 Message-Id: <20210924151417.2843353-1-andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210924122933.2714720-1-andrew.burgess@embecosm.com> References: <20210924122933.2714720-1-andrew.burgess@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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