From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 06EA23858D37; Wed, 2 Mar 2022 17:41:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 06EA23858D37 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 222HfC3S013765 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 2 Mar 2022 12:41:17 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 222HfC3S013765 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 15DD81EA69; Wed, 2 Mar 2022 12:41:11 -0500 (EST) Message-ID: Date: Wed, 2 Mar 2022 12:41:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: =?UTF-8?B?UmU6IC4uLy4uL2dkYnN1cHBvcnQvbmV3LW9wLmNjOjEzNzoxOiBlcnJv?= =?UTF-8?B?cjog4oCYdm9pZCBvcGVyYXRvciBkZWxldGUgW10odm9pZCosIHN0ZDo6c2l6ZV90?= =?UTF-8?Q?=29=e2=80=99_is_a_usual_=28non-placement=29_deallocation_function?= =?UTF-8?Q?_in_C++14_=28or_with_-fsized-deallocation=29_=5b-Werror=3dc++14-c?= =?UTF-8?Q?ompat=5d?= Content-Language: en-US To: Andrew Burgess , =?UTF-8?B?5ZGo5pil5piOKOaXpeaciCk=?= Cc: Gdb-patches , Dominique Quatravaux , Louis-He <1726110778@qq.com>, gdb-patches , Sam Warner References: <65ee9ce9-34db-4434-9cc6-34378f96bee9.riyue.zcm@alibaba-inc.com> <20220302163056.GC1212730@redhat.com> <18e3cba4-71ce-5b88-c760-8c8787541f35@polymtl.ca> <87sfs0xo9l.fsf@redhat.com> From: Simon Marchi In-Reply-To: <87sfs0xo9l.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 2 Mar 2022 17:41:12 +0000 X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, 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:41:32 -0000 On 2022-03-02 12:22, Andrew Burgess wrote: > Simon Marchi via Gdb-patches writes: > >> On 2022-03-02 11:30, Andrew Burgess wrote: >>> * 周春明(日月) via Gdb-patches [2022-03-01 15:48:47 +0800]: >>> >>>> >>>> Hi GDB maintainers, >>>> >>>> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks! >>>> >>>> CXX new-op.o >>>> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] >>>> extern void operator delete (void *p, std::size_t) noexcept; >>>> ^ >>>> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] >>>> extern void operator delete[] (void *p, std::size_t) noexcept; >>>> ^ >>>> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] >>>> operator delete (void *p, std::size_t) noexcept >>>> ^ >>>> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] >>>> operator delete[] (void *p, std::size_t) noexcept >>> >>> 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: >>> >>> ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat" >>> >>> to disable this warning/error which I believe should be fine. >>> >>> 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. >>> >>> As time moved on I think this warning was relaxed, possibly with this >>> commit: >>> >>> https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html >>> >>> 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? >>> >>> Thanks, >>> Andrew >>> >>> --- >>> >>> 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 >>> >>> -/* 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; >> >> 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/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1 > > 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. > >> >> 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/b038b53f1ff4bf00ecdead1db23eddc4fd654305 > > 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? That was my idea, yes. We require GDB to be buildable in C++11, but we also regularly build it in C++14 and C++17 as well, since recent compilers default to that version (and we don't force -std=c++11/-std=gnu++11). >> 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... Yes. >> 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 >= xyz". > > ... if we did this, and only ever compile with C++11, then this would be > equivalent to what I proposed, right? Yes (but we currently don't restrict to C++11). > 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. I think it is what I suggested, by per Pedro's message, that is probably not good. From what I understand, it is possible for a library GDB links with to be built with a more recent C++, and call some "recent" delete operator. So even if we build GDB in C++11, we have to cover the more recent delete operators introduced in C++14. Simon