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 6733B3858C50 for ; Wed, 3 May 2023 18:47:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6733B3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca 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 343IlFAh009985 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 3 May 2023 14:47:20 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 343IlFAh009985 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1683139641; bh=T+GsxrcqYihd+Mwk2+Nx+DOpCF5Rg7myYtzU+1E+1zI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=uxg4IrRMvE33ps8sxSCTAQSWy9vifRvYrKzOvbDnPudl1ejbrpVSA57rtKM+QmINP 3/H1j0RPEFDiqJvishrEa+PzD1b9CuOO9uFz38gRpCF13VTIg8KAjA7+tcQwYJrSev JN0X2T65Kr16P7RtxMkbDan5H2m+lQbNJeUa1tfI= Received: from [10.0.0.170] (unknown [167.248.160.41]) (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 7A89A1E0D6; Wed, 3 May 2023 14:47:15 -0400 (EDT) Message-ID: <7ccea69e-7cce-9016-06a4-e63b3bf16a17@polymtl.ca> Date: Wed, 3 May 2023 14:47:14 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] [gdb/build] Fix frame_list position in frame.c Content-Language: fr To: Tom de Vries , gdb-patches@sourceware.org References: <20230503175826.4242-1-tdevries@suse.de> From: Simon Marchi In-Reply-To: <20230503175826.4242-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 3 May 2023 18:47:15 +0000 X-Spam-Status: No, score=-3039.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 5/3/23 13:58, Tom de Vries wrote: > In commit 995a34b1772 ("Guard against frame.c destructors running before > frame-info.c's") the following problem was addressed. > > The frame_info_ptr destructor: > ... > ~frame_info_ptr () > { > frame_list.erase (frame_list.iterator_to (*this)); > } > ... > uses frame_list, which is a static member of class frame_info_ptr, > instantiated in frame-info.c: > ... > intrusive_list frame_info_ptr::frame_list; > ... > > Then there's a static frame_info_pointer variable named selected_frame in > frame.c: > ... > static frame_info_ptr selected_frame; > ... > > Because the destructor of selected_frame uses frame_list, its destructor needs > to be called before the destructor of frame_list. > > But because they're in different compilation units, the initialization order and > consequently destruction order is not guarantueed. > > The commit fixed this by handling the case that the destructor of frame_list > is called first, adding a check on is_linked (): > ... > ~frame_info_ptr () > { > - frame_list.erase (frame_list.iterator_to (*this)); > + /* If this node has static storage, it may be deleted after > + frame_list. Attempting to erase ourselves would then trigger > + internal errors, so make sure we are still linked first. */ > + if (is_linked ()) > + frame_list.erase (frame_list.iterator_to (*this)); > } > ... > > However, since then frame_list has been moved into frame.c, and > initialization/destruction order is guarantueed inside a compilation unit. > > Revert aforementioned commit, and fix the destruction order problem by moving > frame_list before selected_frame. > > Reverting the commit is another way of fixing the already fixed > Wdangling-pointer warning reported in PR build/30413, in a different way than > commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for > skip_[language_]trampoline"). > > Tested on x86_64-linux. > > PR build/30413 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413 > --- > gdb/frame.c | 11 +++++++---- > gdb/frame.h | 9 ++++----- > 2 files changed, 11 insertions(+), 9 deletions(-) > > diff --git a/gdb/frame.c b/gdb/frame.c > index 36fb02f3c8e..531eadf3d54 100644 > --- a/gdb/frame.c > +++ b/gdb/frame.c > @@ -1733,6 +1733,13 @@ get_current_frame (void) > static frame_id selected_frame_id = null_frame_id; > static int selected_frame_level = -1; > > +/* See frame.h. This definition should come before any definition of a static > + frame_info_ptr, to ensure that frame_list is destroyed after any static > + frame_info_ptr. This is necessary because the destructor of frame_info_ptr Spurious double space. > + uses frame_list. */ > + > +intrusive_list frame_info_ptr::frame_list; > + > /* The cached frame_info object pointing to the selected frame. > Looked up on demand by get_selected_frame. */ > static frame_info_ptr selected_frame; > @@ -3275,10 +3282,6 @@ maintenance_print_frame_id (const char *args, int from_tty) > > /* See frame-info-ptr.h. */ > > -intrusive_list frame_info_ptr::frame_list; > - > -/* See frame-info-ptr.h. */ > - > frame_info_ptr::frame_info_ptr (struct frame_info *ptr) > : m_ptr (ptr) > { > diff --git a/gdb/frame.h b/gdb/frame.h > index 6ed8db0af56..ed19dfdc090 100644 > --- a/gdb/frame.h > +++ b/gdb/frame.h > @@ -254,11 +254,10 @@ class frame_info_ptr : public intrusive_list_node > > ~frame_info_ptr () > { > - /* If this node has static storage, it may be deleted after > - frame_list. Attempting to erase ourselves would then trigger > - internal errors, so make sure we are still linked first. */ > - if (is_linked ()) > - frame_list.erase (frame_list.iterator_to (*this)); > + /* If this node has static storage, it should be be deleted before > + frame_list. Verify this by checking that it is still in the list. */ > + gdb_assert (is_linked ()); > + frame_list.erase (frame_list.iterator_to (*this)); The assert is a bit redundant with the assertions in intrusive_list::erase_element: gdb_assert (elem_node->prev != INTRUSIVE_LIST_UNLINKED_VALUE); gdb_assert (elem_node->next != INTRUSIVE_LIST_UNLINKED_VALUE); I would maybe remove the assert, but keep the comment (at least the first sentence)? In any case, this LGTM, thanks for doing this. Approved-By: Simon Marchi Simon