From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 35B1C3858032 for ; Wed, 2 Mar 2022 17:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35B1C3858032 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-x51es92rPXOQPkg6fUPlvA-1; Wed, 02 Mar 2022 12:22:49 -0500 X-MC-Unique: x51es92rPXOQPkg6fUPlvA-1 Received: by mail-wm1-f70.google.com with SMTP id f12-20020a7bcd0c000000b00384993440cfso842415wmj.3 for ; Wed, 02 Mar 2022 09:22:49 -0800 (PST) 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:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=wZJwKDpOJwhXPscbHIyGRlWo9lES1QJt6J1u+Rb10bU=; b=vei6BVIX8TB7hHty6v5g36x8HCKt+kllgU4qug8oZSuKWfZ1prQILFbLhhmbu0hBWS fkfnLZ2PrpgiCJLIDVPs2KTAjzViXhQ3Ffm3+KPO1oey+DxHd2Alk9yDuY/VD5tk4Oce Yc5OAAmc4D0eEWMO/F94FxLcg87vK9/vC611yCAJHJvzXfAyy0kM2tEyH7rcIwgYP9GA nWVU52ns5fbQz+Gx7v22lBsuMZk1spW5mOIqBm4ObAK9KpuVFJ/UvPw83KRiG7Mf9ARI K2wa5dHE+6leeNrVKnZ1KrV8fB+m8cdU1yRnVbfK89sRxDluYPJ2MD+CPYAXkDoGlobh 3KCg== X-Gm-Message-State: AOAM5324sgJc5Gx5BUxPstlQOlpDTMrF7NMqbDw5/o+Ys6pOQGxxQ81u m+s/WTenNZw7SjoapWK4w2+2Hsof7V8jRZik2duvfSGaZu8F1wLVr4YSwf5txMyVsgyB5UX6uC1 EJWDcm8FigjCIryqaJ+5k8Q== X-Received: by 2002:a05:6000:12c7:b0:1ea:8dfe:90a2 with SMTP id l7-20020a05600012c700b001ea8dfe90a2mr24005995wrx.681.1646241768385; Wed, 02 Mar 2022 09:22:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbO7dHm1VHzMEbTtPm24iw2spVqkagw6YaQeDvP2opeZiu98jOmknf0iYuqbebuSDX2Or8+w== X-Received: by 2002:a05:6000:12c7:b0:1ea:8dfe:90a2 with SMTP id l7-20020a05600012c700b001ea8dfe90a2mr24005977wrx.681.1646241768066; Wed, 02 Mar 2022 09:22:48 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id w6-20020a05600018c600b001efe4a49566sm8839744wrq.78.2022.03.02.09.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 09:22:47 -0800 (PST) From: Andrew Burgess To: Simon Marchi , =?utf-8?B?5ZGo5pil5piOKOaXpQ==?= =?utf-8?B?5pyIKQ==?= Cc: Gdb-patches , Dominique Quatravaux , Louis-He <1726110778@qq.com>, gdb-patches , Sam Warner Subject: Re: ../../gdbsupport/new-op.cc:137:1: error: =?utf-8?Q?=E2=80=98v?= =?utf-8?Q?oid?= operator delete [](void*, =?utf-8?Q?std=3A=3Asize=5Ft=29?= =?utf-8?Q?=E2=80=99?= is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] In-Reply-To: <18e3cba4-71ce-5b88-c760-8c8787541f35@polymtl.ca> References: <65ee9ce9-34db-4434-9cc6-34378f96bee9.riyue.zcm@alibaba-inc.com> <20220302163056.GC1212730@redhat.com> <18e3cba4-71ce-5b88-c760-8c8787541f35@polymtl.ca> Date: Wed, 02 Mar 2022 17:22:46 +0000 Message-ID: <87sfs0xo9l.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 02 Mar 2022 17:22:54 -0000 Simon Marchi via Gdb-patches writes: > On 2022-03-02 11:30, Andrew Burgess wrote: >> * =E5=91=A8=E6=98=A5=E6=98=8E(=E6=97=A5=E6=9C=88) via Gdb-patches [2022-03-01 15:48:47 +0800]: >>=20 >>> >>> Hi GDB maintainers, >>> >>> I tried to build new GDB12, but encounter below error, anyone could tel= l me how to fix it? Thanks! >>> >>> CXX new-op.o >>> ../../gdbsupport/new-op.cc:32:13: error: =E2=80=98void operator delete(= void*, std::size_t)=E2=80=99 is a usual (non-placement) deallocation functi= on in C++14 (or with -fsized-deallocation) [-Werror=3Dc++14-compat] >>> extern void operator delete (void *p, std::size_t) noexcept; >>> ^ >>> ../../gdbsupport/new-op.cc:33:13: error: =E2=80=98void operator delete = [](void*, std::size_t)=E2=80=99 is a usual (non-placement) deallocation fun= ction in C++14 (or with -fsized-deallocation) [-Werror=3Dc++14-compat] >>> extern void operator delete[] (void *p, std::size_t) noexcept; >>> ^ >>> ../../gdbsupport/new-op.cc:119:1: error: =E2=80=98void operator delete(= void*, std::size_t)=E2=80=99 is a usual (non-placement) deallocation functi= on in C++14 (or with -fsized-deallocation) [-Werror=3Dc++14-compat] >>> operator delete (void *p, std::size_t) noexcept >>> ^ >>> ../../gdbsupport/new-op.cc:137:1: error: =E2=80=98void operator delete = [](void*, std::size_t)=E2=80=99 is a usual (non-placement) deallocation fun= ction in C++14 (or with -fsized-deallocation) [-Werror=3Dc++14-compat] >>> operator delete[] (void *p, std::size_t) noexcept >>=20 >> I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0. >> I was unable to easily rebuild GCC 5.4.0 on my current development >> machine to check if this is reproducible with upstream gcc, or is just >> something impacting Ubuntu. However, you can configure like: >>=20 >> ../src/configure ...configure-flags-here... CXXFLAGS=3D"-Wno-error=3Dc= ++14-compat" >>=20 >> to disable this warning/error which I believe should be fine. >>=20 >> For why this error is occurring, I'm honestly not 100% sure what the >> error is telling us. I _think_ what it's saying is that the delete >> operator that we're declaring/defining conflicts with a "usual >> deallocation function", which is added in c++14 and means something >> specific. I guess the idea is that maybe we're just randomly defining >> this version of delete for some reason, and then, if/when we move on >> to c++14 this function will get called unexpectedly by the language >> runtime in some situations. >>=20 >> As time moved on I think this warning was relaxed, possibly with this >> commit: >>=20 >> https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html >>=20 >> All this makes me wonder if the usual deallocation functions are ever >> actually used, and indeed, I applied the patch below, and GDB still >> seems to build fine, so this might be an alternative approach. Maybe >> we should commit this to master? >>=20 >> Thanks, >> Andrew >>=20 >> --- >>=20 >> diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc >> index 1d066ba..4faa557 100644 >> --- a/gdbsupport/new-op.cc >> +++ b/gdbsupport/new-op.cc >> @@ -27,11 +27,6 @@ >> #include "host-defs.h" >> #include >> =20 >> -/* These are declared in starting C++14. Add these here to enabl= e >> - compilation using C++11. */ >> -extern void operator delete (void *p, std::size_t) noexcept; >> -extern void operator delete[] (void *p, std::size_t) noexcept; > > The story of this is that ASan gave some alloc-dealloc mismatch warnings > if we didn't define these specific delete operators, so we defined them > in this commit: > > https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0a= e8d144e1c8418ee2ee1 I saw that commit, but it wasn't clear (to me) that _every_ supplied delete was actually needed, or if the patch author just went wide. The patch even says: There could be 16 operators delete but there are only 6, GDB uses 2 of them. It depends on libraries and compiler which of the operators will get used. But, that does seem to indicate that if I built with a different compiler/c++-runtime, then I might end up using different delete functions.=20 > > But for the variants of delete that are only introduced in C++14, it > meant adding functions without an equivalent declaration when building > in C++11, which produced some -Wmissing-declarations warnings. So these > declarations were added in this commit: > > https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdea= d1db23eddc4fd654305 OK, so, I think you're saying that if we compile with C++14 then we might need the delete functions I proposed deleting. Just for my sanity, GDB currently targets C++11, right? But, I guess you're suggesting you'd like to keep these functions in place so we _can_ compile with C++14 if we want? > > The idea being that in C++11, these delete operators won't get used, but > there will be a declaration to avoid the warning, and in C++14 the > declarations will duplicate those found in headers, which is harmless. > > And now here we are, we have a C++11 compiler that complains about > declaring these delete operators. > > So we can't simply remove the declarations and / or definitions, we > would just re-introduce the problems fixed by these commits. I think this last statement depends on the "wanting to compile with C++14" idea above, right? Otherwise... > > I think that a clean way to fix this would be to conditionally define > these delete operators based on the C++ version. So we would remove the > declarations, as you do in your commit, but place the definitions under > an "#if __cplusplus >=3D xyz". ... if we did this, and only ever compile with C++11, then this would be equivalent to what I proposed, right? I ask the above not (just) to be pedantic, but (mostly) to ensure I've properly understood what's going on. Below is a patch which maybe does what you suggest. No commit message, but if this is what you were thinking then I can write this up. Thanks, Andrew --- diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc index 1d066ba..8699ec3 100644 --- a/gdbsupport/new-op.cc +++ b/gdbsupport/new-op.cc @@ -27,11 +27,6 @@ #include "host-defs.h" #include =20 -/* These are declared in starting C++14. Add these here to enable - compilation using C++11. */ -extern void operator delete (void *p, std::size_t) noexcept; -extern void operator delete[] (void *p, std::size_t) noexcept; - /* Override operator new / operator new[], in order to internal_error on allocation failure and thus query the user for abort/core dump/continue, just like xmalloc does. We don't do this from a @@ -116,19 +111,20 @@ operator delete (void *p, const std::nothrow_t&) noex= cept } =20 void -operator delete (void *p, std::size_t) noexcept +operator delete[] (void *p) noexcept { - return ::operator delete (p, std::nothrow); + return ::operator delete (p); } =20 void -operator delete[] (void *p) noexcept +operator delete[] (void *p, const std::nothrow_t&) noexcept { - return ::operator delete (p); + return ::operator delete (p, std::nothrow); } =20 +#if __cplusplus >=3D 201402L void -operator delete[] (void *p, const std::nothrow_t&) noexcept +operator delete (void *p, std::size_t) noexcept { return ::operator delete (p, std::nothrow); } @@ -138,5 +134,6 @@ operator delete[] (void *p, std::size_t) noexcept { return ::operator delete[] (p, std::nothrow); } +#endif =20 #endif