From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2zsJAp8IW2GGcQAAWB0awg (envelope-from ) for ; Mon, 04 Oct 2021 09:58:55 -0400 Received: by simark.ca (Postfix, from userid 112) id EB78B1EE1A; Mon, 4 Oct 2021 09:58:54 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 AFA461E813 for ; Mon, 4 Oct 2021 09:58:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5403D3858408 for ; Mon, 4 Oct 2021 13:58:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5403D3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633355932; bh=sUbGm30AtbCzPg/R6H9fT91TJ96pzCVEfKGpcMm9t6c=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bNPQUCpmq3+u45L2Jru+T+uwZ33umg/1WOj5uiLpYXEb64OqCUaJHf1Lj9XR4rdfi g4C0b5909W+0bkvXC9NYGXRQj7ue+h+PX1d8InHBtPP0OwMIu59Wha/vhh97D/xCde 0IqT3Od3USW2TFGEtZgDC1md47+YPnGiaETO3ZMM= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E909B3858D28 for ; Mon, 4 Oct 2021 13:58:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E909B3858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 117691FFEE; Mon, 4 Oct 2021 13:58:32 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F02E313342; Mon, 4 Oct 2021 13:58:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3SpNOYcIW2GnYgAAMHmgww (envelope-from ); Mon, 04 Oct 2021 13:58:31 +0000 Subject: Re: [PATCH, master+11][gdb/build] Add CXX_DIALECT to CXX To: Simon Marchi , gdb-patches@sourceware.org References: <20210908121519.GA17723@delia> <73d742e2-c0c5-d641-83cb-ea12bc24cade@polymtl.ca> Message-ID: <6cb21c7a-5701-2909-7142-ef9b7296ad3e@suse.de> Date: Mon, 4 Oct 2021 15:58:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 9/27/21 2:59 PM, Tom de Vries via Gdb-patches wrote: > On 9/23/21 4:27 PM, Simon Marchi wrote: >> >> On 2021-09-08 8:15 a.m., Tom de Vries wrote: >>> Hi, >>> >>> The problem reported in PR28318 is that when using a gcc version that (while >>> supporting c++11) does not support c++11 by default, the configure test for >>> std::thread support will fail. >>> >>> If gdb would use the default AX_CXX_COMPILE_STDCXX from autoconf, then we'd >>> have: >>> ... >>> CXX="g++ -std=gnu++11" >>> ... >>> and the test for std::thread support would succeed. >>> >>> Instead, gdb uses a custom AX_CXX_COMPILE_STDCXX (see commit 0bcda685399) >>> which does: >>> ... >>> CXX=g++ >>> CXX_DIALECT=-std=gnu++11 >>> ... >>> >>> We could add $CXX_DIALECT to the test for std::thread support, but that would >>> have to be repeated for each added c++ support test. >>> >>> Instead, fix this by doing: >>> ... >>> CXX="g++ -std=gnu++11" >>> CXX_DIALECT=-std=gnu++11 >>> ... >>> >>> The code added in gdb/ax_cxx_compile_stdcxx.m4 is copied from the default >>> AX_CXX_COMPILE_STDCXX from autoconf. >> From autoconf-archive? >> > Yes, updated. > >> At first glance, it looks like CXX_DIALECT would not be needed anymore, >> since it's only used to be appended to CXX in Makefiles. So now it >> would end up twice in the command-line, which is not harmful but not >> useful. >> >> However, if we look at the original explanation of why we have this >> local modification: >> >> We need to tweak AX_CXX_COMPILE_STDCXX a bit though. Pristine >> upstream AX_CXX_COMPILE_STDCXX appends -std=gnu++11 to CXX directly. >> That doesn't work for us, because the top level Makefile passes CXX >> down to subdirs, and that overrides whatever gdb/Makefile may set CXX >> to. The result would be that a make invocation from the build/gdb/ >> directory would use "g++ -std=gnu++11" as expected, while a make >> invocation at the top level would not. >> >> So instead of having AX_CXX_COMPILE_STDCXX set CXX directly, tweak it >> to AC_SUBST a separate variable -- CXX_DIALECT -- and use '$(CXX) >> (CXX_DIALECT)' to compile/link. >> >> https://gitlab.com/gnutools/binutils-gdb/-/commit/0bcda68539948828795564b35a497dc69c27f768 >> >> So it sounds like we need both (and your patch is correct): >> >> - the switch in CXX for the std::thread tests (and other tests) >> - the switch in CXX_DIALECT so it can be appended in Makefiles, to >> counteract the fact that the top-level Makefile overrides CXX >> >> This should probably be explained in the comment, because that situation >> is strange, and people might wonder why we end up with two -std=... >> switches, and might try to "fix" it. > Ack, I've rewritten the commit log to make this more clear (and copied > part of you comments). > > Any further comments? > I'll commit this tomorrow, unless there are further comments. Thanks, - Tom > 0001-gdb-build-Add-CXX_DIALECT-to-CXX.patch > > [gdb/build] Add CXX_DIALECT to CXX > > Say we use a gcc version that (while supporting c++11) does not support c++11 > by default, and needs an -std setting to enable it. > > If gdb would use the default AX_CXX_COMPILE_STDCXX from autoconf-archive, then > we'd have: > ... > CXX="g++ -std=gnu++11" > ... > > That mechanism however has the following problem (quoting from commit > 0bcda685399): > ... > the top level Makefile passes CXX down to subdirs, and that overrides whatever > gdb/Makefile may set CXX to. The result would be that a make invocation from > the build/gdb/ directory would use "g++ -std=gnu++11" as expected, while a > make invocation at the top level would not. > ... > > Commit 0bcda685399 fixes this by using a custom AX_CXX_COMPILE_STDCXX which > does: > ... > CXX=g++ > CXX_DIALECT=-std=gnu++11 > ... > > The problem reported in PR28318 is that using the custom instead of the > default AX_CXX_COMPILE_STDCXX makes the configure test for std::thread > support fail. > > We could simply add $CXX_DIALECT to the test for std::thread support, but > that would have to be repeated for each added c++ support test. > > Instead, fix this by doing: > ... > CXX="g++ -std=gnu++11" > CXX_DIALECT=-std=gnu++11 > ... > > This is somewhat awkward, since it results in -std=gnu++11 occuring twice in > some situations: > ... > $ touch src/gdb/dwarf2/read.c > $ ( cd build/gdb; make V=1 dwarf2/read.o ) > g++-4.8 -std=gnu++11 -x c++ -std=gnu++11 ... > ... > > However, both settings are needed: > - the switch in CXX for the std::thread tests (and other tests) > - the switch in CXX_DIALECT so it can be appended in Makefiles, to > counteract the fact that the top-level Makefile overrides CXX > > The code added in gdb/ax_cxx_compile_stdcxx.m4 is copied from the default > AX_CXX_COMPILE_STDCXX from autoconf-archive. > > Tested on x86_64-linux. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28318 > > --- > gdb/ax_cxx_compile_stdcxx.m4 | 8 ++++++++ > gdb/configure | 8 ++++++++ > gdbserver/configure | 8 ++++++++ > gdbsupport/configure | 8 ++++++++ > 4 files changed, 32 insertions(+) > > diff --git a/gdb/ax_cxx_compile_stdcxx.m4 b/gdb/ax_cxx_compile_stdcxx.m4 > index 413755a2e88..29d8e10bcc4 100644 > --- a/gdb/ax_cxx_compile_stdcxx.m4 > +++ b/gdb/ax_cxx_compile_stdcxx.m4 > @@ -94,6 +94,10 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl > CXX="$ac_save_CXX"]) > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > @@ -118,6 +122,10 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl > CXX="$ac_save_CXX"]) > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > diff --git a/gdb/configure b/gdb/configure > index f0b1af4a6ea..98badb46cfd 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -5841,6 +5841,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > @@ -6160,6 +6164,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > diff --git a/gdbserver/configure b/gdbserver/configure > index b227167e270..f05c1a9b976 100755 > --- a/gdbserver/configure > +++ b/gdbserver/configure > @@ -5625,6 +5625,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > @@ -5944,6 +5948,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > diff --git a/gdbsupport/configure b/gdbsupport/configure > index a9dd02c5b72..ae6047865ae 100755 > --- a/gdbsupport/configure > +++ b/gdbsupport/configure > @@ -6520,6 +6520,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi > @@ -6839,6 +6843,10 @@ eval ac_res=\$$cachevar > $as_echo "$ac_res" >&6; } > if eval test x\$$cachevar = xyes; then > CXX_DIALECT="$switch" > + CXX="$CXX $switch" > + if test -n "$CXXCPP" ; then > + CXXCPP="$CXXCPP $switch" > + fi > ac_success=yes > break > fi >