From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91155 invoked by alias); 13 Oct 2016 00:38:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 91141 invoked by uid 89); 13 Oct 2016 00:38:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=iow, mixing, IOW, xxx X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Oct 2016 00:38:16 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF91D3B72D; Thu, 13 Oct 2016 00:38:14 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9D0cAD1026671; Wed, 12 Oct 2016 20:38:10 -0400 Subject: [PATCH] Enable C++11 starting with gcc 4.8 (was: Re: [PATCH 1/3] Introduce gdb::unique_ptr) To: "Metzger, Markus T" , Eli Zaretskii References: <1476117992-5689-1-git-send-email-palves@redhat.com> <1476117992-5689-2-git-send-email-palves@redhat.com> <20161011121639.GE3813@adacore.com> <68fc02cb-59bc-012c-d1be-b5ed2076d6a5@redhat.com> <20161011144741.GF3813@adacore.com> <83insydifw.fsf@gnu.org> <83a8eadds7.fsf@gnu.org> <4d49eb8f-5a0c-1e7e-d082-1a224179184f@redhat.com> <831szmd977.fsf@gnu.org> <83vawybol4.fsf@gnu.org> <6ba388f7-1696-42db-ae92-23df79e3ba11@redhat.com> <83oa2qaxe7.fsf@gnu.org> <46f76e28-dda9-632b-2f76-81fdcbee63bf@redhat.com> Cc: "brobecker@adacore.com" , "gdb-patches@sourceware.org" , "Jan Kratochvil (jan.kratochvil@redhat.com)" , Simon Marchi From: Pedro Alves Message-ID: <97f51cf1-be35-1328-78e5-3642479e67fa@redhat.com> Date: Thu, 13 Oct 2016 00:38:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <46f76e28-dda9-632b-2f76-81fdcbee63bf@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-10/txt/msg00336.txt.bz2 On 10/12/2016 11:28 AM, Pedro Alves wrote: > On 10/12/2016 09:11 AM, Metzger, Markus T wrote: > >> A simple and pragmatic solution would be a patch to add -std=c++11 >> to GDB's compiler options. Pedro already mentioned it but I'm afraid it >> got lost. > > Looks like it, yes. As I've explained, we can't do it on src/gdb/ > alone, because the CXX make variable is passed down from the top level, > which would override whatever we set in gdb/'s configure/Makefile. > > I want to give it a try, though. It just requires time and getting > the patch into gcc and merged back. I don't think that should hold > back the proposed series (or pieces of it). > > I wasn't originally meaning to unconditionally add -std=c++11 though, > but instead to only add it if the compiler supports it, in order > to conservatively still support C++03-only compilers. OK, I spend a few hours tonight working on this. I was thinking ahead that we'll like have other C++ libraries in the top level that we'd be using (code shared with gcc, and also gdbserver moving to top level, maybe parts split to libraries, etc.). And I was mistakenly under the impression that all subdirs would have to be built with the same C++ dialect, given the C++11 ABI change. I.e., use the same dialect throughout to avoid ABI conflicts. So I first wrote a patch that had the top level configure source a file in each subdir that would tell the top level the minimum and maximum C++ dialect versions each subdir supported, and then the top level could compute the dialect to set CXX to. But, https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html explains how mixing dialects is not really a problem. So I was over complicating. However, the issue with CXX being passed by the top level overriding whatever gdb's configure/Makefile decide to set CXX to is real though. But I solved it in a different way, all within gdb/ Instead of having configure append -std=xxx to CXX, simply set a separate CXX_DIALECT variable, and tweak the Makefile to use "$CXX CXX_DIALECT" to compile/link. In order to detect whether the compiler supports C++11 (i.e., if we're using gcc 4.8 or later, or a clang that supports C++11, etc.), I'm reusing a macro from the GNU Autoconf Archive, at: http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html To recap: > Conceptually, the gdb::unique_ptr patch (this thread) does: > > #if HAVE_STD_UNIQUE_PTR > > // just use it > > #else > > // write replacement > > #endif > > The replacement is fully functional. > > If I push the patch in now, HAVE_STD_UNIQUE_PTR will only be true > when compiling GDB with GCC >= 6.x, because G++ 6.1 targets G++14 > by default, which is a superset of C++11. The replacement > works with all other GCCs. It'd be possible to make > HAVE_STD_UNIQUE_PTR be true with GCC >= 4.x too, but nobody wrote > that patch yet. So I wrote that patch now. IOW, the idea is that gdb::unique_ptr maps to C++11 std::unique_ptr iff C++11 is available and to a replacement otherwise. The C++03 replacement works just as well, however the C++11 version catches more bugs at compile time. Full C++11 support is available starting with gcc 4.8, however only gcc 6.1 switched to default to C++11 (C++14, actually). So for gcc 4.8 till gcc 6.1, we need to explicitly pass -std=gnu++11 to the compiler. That's what the patch I wrote tonight does. I'll send it as reply to this email. Two patches actually. > But if we agree to go full-on C++11, then I'll be more than > happy to make gdb's configure error out on non-C++11 compilers. The patches add this to configure: AX_CXX_COMPILE_STDCXX(11, , optional) "optional" means that not having a C++11 compiler is OK. IOW, "try to enable C++11 iff possible". If we decide to _require_ C++11 (i.e., drop support for C++03-only), then it's a simple matter of changing that to: AX_CXX_COMPILE_STDCXX(11, , mandatory) Thanks, Pedro Alves