From patchwork Mon Oct 14 00:18:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 34930 Received: (qmail 39064 invoked by alias); 14 Oct 2019 00:19:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 39055 invoked by uid 89); 14 Oct 2019 00:19:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=safer, defer 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; Mon, 14 Oct 2019 00:19:07 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0498F10CC1F1 for ; Mon, 14 Oct 2019 00:19:06 +0000 (UTC) Received: from f30-1.lan (ovpn-118-26.phx2.redhat.com [10.3.118.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 383905D6A3; Mon, 14 Oct 2019 00:19:04 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 1/2] Fix BZ 25065 - Ensure that physnames are computed for inherited DIEs Date: Sun, 13 Oct 2019 17:18:41 -0700 Message-Id: <20191014001842.27413-2-kevinb@redhat.com> In-Reply-To: <20191014001842.27413-1-kevinb@redhat.com> References: <20191014001842.27413-1-kevinb@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes This is a fix for BZ 25065. GDB segfaults when running either gdb.cp/subtypes.exp or gdb.cp/local.exp in conjunction with using the -flto compiler/linker flag. A much simpler program, which was used to help create the test for this fix, is: -- doit.cc -- int main() { class Foo { public: int doit () { return 0; } }; Foo foo; return foo.doit (); } -- end doit.cc -- gcc -o doit -flto -g doit.cc gdb -q doit Reading symbols from doit... (gdb) ptype main::Foo type = class Foo { Segmentation fault (core dumped) The segfault occurs due to a NULL physname in c_type_print_base_struct_union in c-typeprint.c. Specifically, calling is_constructor_name() eventually causes the SIGSEGV is this code in c-typeprint.c: const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j); int is_full_physname_constructor = TYPE_FN_FIELD_CONSTRUCTOR (f, j) || is_constructor_name (physname) || is_destructor_name (physname) || method_name[0] == '~'; However, looking at compute_delayed_physnames(), we see that the TYPE_FN_FIELD_PHYSNAME field should never be NULL. This field will be set to "" for NULL physnames: physname = dwarf2_physname (mi.name, mi.die, cu); TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi.index) = physname ? physname : ""; For this particular case, it turns out that compute_delayed_physnames wasn't being called, which left TYPE_FN_FIELD_PHYSNAME set to the NULL value that it started with when that data structure was allocated. The place to fix it, I think, is towards the end of inherit_abstract_dies(). My fix causes the origin CU's method_list (which is simply the list of methods whose physnames still need to be computed) to be added to the CU which is doing the inheriting. Another way to fix it might be call compute_delayed_physnames() from inherit_abstract_dies(), but I wasn't confident that all needed types would be known at that point. It seemed safer to defer the physname computation until the inheriting CU is completely processed. gdb/ChangeLog: * dwarf2read.c (inherit_abstract_dies): Ensure that delayed physnames are computed for inherited DIEs. --- gdb/dwarf2read.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ee9df34ed2..f7ef122933 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -13666,6 +13666,17 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) origin_child_die = sibling_die (origin_child_die); } origin_cu->list_in_scope = origin_previous_list_in_scope; + + if (cu != origin_cu && !origin_cu->method_list.empty ()) + { + /* Add list of methods found in origin_cu to the list in cu. These + methods still need to have their physnames computed in + compute_delayed_physnames(). */ + cu->method_list.insert (cu->method_list.end (), + origin_cu->method_list.begin (), + origin_cu->method_list.end ()); + origin_cu->method_list.clear (); + } } static void