From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 5pN/Br7ETWHGNgAAWB0awg (envelope-from ) for ; Fri, 24 Sep 2021 08:29:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 091BD1EE25; Fri, 24 Sep 2021 08:29:50 -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 B3A6D1EDF0 for ; Fri, 24 Sep 2021 08:29:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 021923857C71 for ; Fri, 24 Sep 2021 12:29:48 +0000 (GMT) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id CEC553858403 for ; Fri, 24 Sep 2021 12:29:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CEC553858403 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-x434.google.com with SMTP id w17so26910332wrv.10 for ; Fri, 24 Sep 2021 05:29:36 -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:mime-version :content-transfer-encoding; bh=EsHgZeylsqPmlmPebmO4KeK9mtoBo3yFYDxhJtww9Zk=; b=GVjSg+2iFDJHPUT2aGy8hXbhcdrdPo0mqT7QYrABuwoFjc98aig2AIy/lyKmy+XXw8 dFrAmP+WrRzFih7UwbSu3YGwa5KsjHAMeFHzVBvE35JYneN+zY9a6MfzeT2XLINuilGc kb9Ake8ZWK/42mH8N7eNRzTzLSlKirT0K60d6c+GVvdqkB9TqjdLZutYXPtYBdS18k1x 6+/0UELoqAI+QUE9/VbLI5FCDLxH25kELJgaUWBh0JxxFzytI4QoRFn2ilkCNlJmXog8 R2C3oLEURbxFt6Spa+vxkD7Ry3n0zNl0WQpUiAJgZM1Kt/tMajbzbQPMAE5b4wYQ0Rcv ExrA== 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:mime-version :content-transfer-encoding; bh=EsHgZeylsqPmlmPebmO4KeK9mtoBo3yFYDxhJtww9Zk=; b=TogoBlro24YAvbR15fVBNH09tA/xPkIJqQkkryroRnHfGmSHzlXwiNe+JjKtE7THz8 7S8su4Ykg0TPFzz5bAtFgH1q+YCT5unDRpC5PX4n8C1L2C/p1+OMB8rmEvfGArSqQQXJ g6siJ6O2V1aNd2ev1rzjiXJ4WS/7w3pgorB7+NMp8P6JJomW5RCqy0e/ISWJwUik43Yh byefKr4ySbJx7tbmL4gJb5ftfUqe3RHahuW1y/7xmvsQUW3fLn8LQtPZSyI3CbqvCkT0 sVssSuHnzZG5IHH71DG5i0PJgiKeNpZG+SMHrCLA2Pwhfyt2UFYsZ4am73bOdqm8cyeC O7XA== X-Gm-Message-State: AOAM530FMp8UdzwL5S7StMbpteAk4Xl7IqdVKrxcdS1BSZTPdFMaYR/U 1iAK/tTVXzo97HWmcjpdkl7mrttLYHIdaA== X-Google-Smtp-Source: ABdhPJzAJaPS9mpk81w0LefcQqoBjVq6Y1qaYZHtJR5T87TqwmlbfBEI5eVn8HgpgG/EEpoIxXI77w== X-Received: by 2002:a5d:6a08:: with SMTP id m8mr10902827wru.336.1632486575785; Fri, 24 Sep 2021 05:29:35 -0700 (PDT) Received: from localhost (host86-169-137-11.range86-169.btcentralplus.com. [86.169.137.11]) by smtp.gmail.com with ESMTPSA id q7sm8642433wrc.55.2021.09.24.05.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 05:29:35 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH] gdbsupport: better detection of -Wmissing-prototypes support Date: Fri, 24 Sep 2021 13:29:33 +0100 Message-Id: <20210924122933.2714720-1-andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 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" 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