Message ID | CADip9gZB9YwRjDWXBbVL70izubGEowqoP0f_DaLhdXaEPqp--Q@mail.gmail.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 106151 invoked by alias); 30 Dec 2017 18:21:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 106140 invoked by uid 89); 30 Dec 2017 18:21:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=destroying, D*ru, H*c:alternative X-HELO: mail-it0-f46.google.com Received: from mail-it0-f46.google.com (HELO mail-it0-f46.google.com) (209.85.214.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 30 Dec 2017 18:21:40 +0000 Received: by mail-it0-f46.google.com with SMTP id c16so9608812itc.5 for <gdb-patches@sourceware.org>; Sat, 30 Dec 2017 10:21:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=DdMSiaC7Sqsn8CjlOn3cSKjigE0m6aURV/lYtAalmS4=; b=rGfgQCfMtomeom0K5SRMddfiwjZNyp5Zp/8MqyyxLTC5RSKGe1KTzXc20aaFmLaCuN uDPS90sAmsWyW6m/ttPuHFgOlHsYHd+9LA7LrSPstDgBTixE6WIAAV5CqRUTCyY4+SnC 1MDc8auqVoN9TH7Mj7fkS4+H3l93ChSq9TFTivyYiVtas5D8rpgrpRMJ35w+qs/lKOVo 99/4b0KcqabP5hlgNxU5CQFMqfDQ7bM74piGJ6DRyPIzgp0uLO/W7vdI3zgDEO26NJNY QZW0dK57Yufn4pNf6Zf6gIrFCy5ixFynjoMfTNwpt5w9UfcFQbnbKtGLSmzlep/JzRKf 3/Pw== X-Gm-Message-State: AKGB3mLfJWWIMcSVQEUYmCHoOgIK4Yp9Ij+Ql1sTgAK+SSM42ymuBdqU IyhX79ajV0HdoZqb3dxZO+cW0CiNxteRNfTxnt/LxZqrjnM= X-Google-Smtp-Source: ACJfBouMPwl5jmxHHlIzfHJ5BY1GvQxramiaXZJ7UufqvpGC+dQqt9Ja8jJpoh+OTH1I2rENEdZeCHSZsVH7Di64rqE= X-Received: by 10.36.214.132 with SMTP id o126mr48591780itg.80.1514658098668; Sat, 30 Dec 2017 10:21:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.1.193 with HTTP; Sat, 30 Dec 2017 10:21:38 -0800 (PST) From: =?UTF-8?B?0J/QsNCy0LXQuyDQmtGA0Y7QutC+0LI=?= <kryukov@frtk.ru> Date: Sat, 30 Dec 2017 21:21:38 +0300 Message-ID: <CADip9gZB9YwRjDWXBbVL70izubGEowqoP0f_DaLhdXaEPqp--Q@mail.gmail.com> Subject: [PATCH] Make dtor of mapped_index_base virtual To: gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" |
Commit Message
Павел Крюков
Dec. 30, 2017, 6:21 p.m. UTC
gdb/Changelog: 2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> * dwarf2read.c (mapped_index_base): Make dtor virtual -- 2.7.4
Comments
On 2017-12-30 13:21, Павел Крюков wrote: > gdb/Changelog: > 2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> > > * dwarf2read.c (mapped_index_base): Make dtor virtual > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 8555b55..fc4c1b3 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,7 @@ > +2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> > + > + * dwarf2read.c (mapped_index_base): Make dtor virtual > + > 2017-12-28 Simon Marchi <simon.marchi@polymtl.ca> > > * target.h (enum target_object) <TARGET_OBJECT_HPUX_UREGS, > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c > index 484cbce..3ac4380 100644 > --- a/gdb/dwarf2read.c > +++ b/gdb/dwarf2read.c > @@ -272,7 +272,7 @@ struct mapped_index_base > > /* Prevent deleting/destroying via a base class pointer. */ > protected: > - ~mapped_index_base() = default; > + virtual ~mapped_index_base() = default; > }; > > /* A description of the mapped index. The file format is described in > -- > 2.7.4 Hi Pavel, Can you clarify what you are trying to fix/improve with this patch? Since the goal is that we don't delete through a pointer of this class, does the destructor need to be virtual (not that it would hurt anything)? Do you get a build error or something? Simon
Hi Simon > Do you get a build error or something? Yes, I get a build error with Clang: dwarf2read.c:25409:5: error: destructor called on non-final 'mapped_index' that has virtual functions but non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor] data->index_table->~mapped_index (); > Since the goal is that we don't delete through a pointer of this class, does the destructor need to be virtual (not that it would hurt anything)? Just to handle the case if someone would delete through a pointer to "mapped_index_base" class. Thanks, -- Pavel 2017-12-31 4:28 GMT+03:00 Simon Marchi <simon.marchi@polymtl.ca>: > On 2017-12-30 13:21, Павел Крюков wrote: > >> gdb/Changelog: >> 2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> >> >> * dwarf2read.c (mapped_index_base): Make dtor virtual >> >> diff --git a/gdb/ChangeLog b/gdb/ChangeLog >> index 8555b55..fc4c1b3 100644 >> --- a/gdb/ChangeLog >> +++ b/gdb/ChangeLog >> @@ -1,3 +1,7 @@ >> +2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> >> + >> + * dwarf2read.c (mapped_index_base): Make dtor virtual >> + >> 2017-12-28 Simon Marchi <simon.marchi@polymtl.ca> >> >> * target.h (enum target_object) <TARGET_OBJECT_HPUX_UREGS, >> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c >> index 484cbce..3ac4380 100644 >> --- a/gdb/dwarf2read.c >> +++ b/gdb/dwarf2read.c >> @@ -272,7 +272,7 @@ struct mapped_index_base >> >> /* Prevent deleting/destroying via a base class pointer. */ >> protected: >> - ~mapped_index_base() = default; >> + virtual ~mapped_index_base() = default; >> }; >> >> /* A description of the mapped index. The file format is described in >> -- >> 2.7.4 >> > > Hi Pavel, > > Can you clarify what you are trying to fix/improve with this patch? Since > the goal is that we don't delete through a pointer of this class, does the > destructor need to be virtual (not that it would hurt anything)? Do you > get a build error or something? > > Simon >
On 2017-12-31 05:12, Павел Крюков wrote: > Hi Simon > >> Do you get a build error or something? > > Yes, I get a build error with Clang: > > dwarf2read.c:25409:5: error: destructor called on non-final > 'mapped_index' > that > has virtual functions but non-virtual destructor > [-Werror,-Wdelete-non-virtual-dtor] > data->index_table->~mapped_index (); > >> Since the goal is that we don't delete through a pointer of this >> class, does > the destructor need to be virtual (not that it would hurt anything)? > > Just to handle the case if someone would delete through a pointer to > "mapped_index_base" class. > > Thanks, Hi Pavel, I think this warning was fixed by the following commit: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=fc898b42e355fef58e6a029799fdd71b9dda5dc6 We don't want anything deleting through a pointer of the base class, because (for now) instances of the two child classes (mapped_index and mapped_debug_names) are allocated differently. One is allocated on the objfile obstack (some kind of manual memory block allocation) and the other is allocated with new. Trying to delete or manually call the destructor through a pointer to mapped_index_base would do the wrong thing for one of the two children. So it's on purpose that mapped_index_base's destructor is hidden, and it doesn't matter whether or not it is virtual. Thanks, Simon
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8555b55..fc4c1b3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2017-12-30 Pavel I. Kryukov <kryukov@frtk.ru> + + * dwarf2read.c (mapped_index_base): Make dtor virtual + 2017-12-28 Simon Marchi <simon.marchi@polymtl.ca> * target.h (enum target_object) <TARGET_OBJECT_HPUX_UREGS, diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 484cbce..3ac4380 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -272,7 +272,7 @@ struct mapped_index_base /* Prevent deleting/destroying via a base class pointer. */ protected: - ~mapped_index_base() = default; + virtual ~mapped_index_base() = default; }; /* A description of the mapped index. The file format is described in