From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.rbg.tum.de (mailout2.rbg.tum.de [131.159.0.202]) by sourceware.org (Postfix) with ESMTPS id CEEE83857B98; Thu, 10 Aug 2023 11:34:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CEEE83857B98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=in.tum.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=in.tum.de Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout2.rbg.tum.de (Postfix) with ESMTPS id 3BC7F4C0254; Thu, 10 Aug 2023 13:34:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.tum.de; s=20220209; t=1691667244; bh=QjXkZvczkCgggsQAxugGPDyRZ/VjY5BQAjqaoNrT6kk=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=rAxbp4Y1oDNjmo5KbB1Gr75ms/8eM4rT6zX3qZEW8KL6wPbE+8w4dzxPai7zVhkqS IGaTyylks5kK2L4EI7jrFOqXBjgpLWBlmyKVkIO5b+30XxnTjHUNAbr9Bg/Sk0+0t1 07UV63Umagm2cZVCS9qg1SGv7JuRXsZkWpR0ayKOl9bMGXihlUKyvJkOiKisXU0QW8 7B9789VVWIaYP4KF9GUxp/yA4uA6bjSBad7YTLFpQZFLXuoeEI4pMjYI6K5DiOA2uG 185eaRiODdgRwTmnSaVzMHFSDyVRQgTvX603QeTIs4zGfsnlAvjkRAGJ+mQtSCHC2B 9UYweT4yiOqJg== Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id 3659E449; Thu, 10 Aug 2023 13:34:04 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id B89EE2C; Thu, 10 Aug 2023 13:34:03 +0200 (CEST) Received: from mail.in.tum.de (vmrbg426.in.tum.de [131.159.0.73]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id B1736449; Thu, 10 Aug 2023 13:34:03 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id 8A9664A013B; Thu, 10 Aug 2023 13:34:03 +0200 (CEST) Received: (Authenticated sender: neumann) by mail.in.tum.de (Postfix) with ESMTPSA id 939044A01D8; Thu, 10 Aug 2023 13:33:53 +0200 (CEST) (Extended-Queue-bit xtech_cs@fff.in.tum.de) Message-ID: Date: Thu, 10 Aug 2023 13:33:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 From: Thomas Neumann Subject: [PATCH] preserve base pointer for __deregister_frame [PR110956] To: "gcc-patches@gcc.gnu.org" Cc: Jakub Jelinek , Rainer Orth References: <2a4776b9-9271-bb3c-a626-d5ec22dae6f3@in.tum.de> <91045a34-a534-4436-bb06-cac32d797a36@in.tum.de> <87sfibqu1s.fsf@oldenburg.str.redhat.com> Content-Language: en-US In-Reply-To: <87sfibqu1s.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP 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: Original bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110956 Rainer Orth successfully tested the patch on Solaris with a full bootstrap. Some uncommon unwinding table encodings need to access the base pointer for address computations. We do not have that information in calls to __deregister_frame_info_bases, and previously simply used nullptr as base pointer. That is usually fine, but for some Solaris i386 shared libraries that results in wrong address computations. To fix this problem we now associate the unwinding object with the table pointer itself, which is always known, in addition to the PC range. When deregistering a frame, we first locate the object using the table pointer, and then use the base pointer stored within the object to compute the PC range. libgcc/ChangeLog: PR libgcc/110956 * unwind-dw2-fde.c: Associate object with address of unwinding table. --- libgcc/unwind-dw2-fde.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c index d7c4a467754..ae4530179f3 100644 --- a/libgcc/unwind-dw2-fde.c +++ b/libgcc/unwind-dw2-fde.c @@ -124,6 +124,9 @@ __register_frame_info_bases (const void *begin, struct object *ob, #endif #ifdef ATOMIC_FDE_FAST_PATH + // Register the object itself to know the base pointer on deregistration. + btree_insert (®istered_frames, (uintptr_type) begin, 1, ob); + // Register the frame in the b-tree uintptr_type range[2]; get_pc_range (ob, range); @@ -175,6 +178,9 @@ __register_frame_info_table_bases (void *begin, struct object *ob, ob->s.b.encoding = DW_EH_PE_omit; #ifdef ATOMIC_FDE_FAST_PATH + // Register the object itself to know the base pointer on deregistration. + btree_insert (®istered_frames, (uintptr_type) begin, 1, ob); + // Register the frame in the b-tree uintptr_type range[2]; get_pc_range (ob, range); @@ -225,22 +231,17 @@ __deregister_frame_info_bases (const void *begin) return ob; #ifdef ATOMIC_FDE_FAST_PATH - // Find the corresponding PC range - struct object lookupob; - lookupob.tbase = 0; - lookupob.dbase = 0; - lookupob.u.single = begin; - lookupob.s.i = 0; - lookupob.s.b.encoding = DW_EH_PE_omit; -#ifdef DWARF2_OBJECT_END_PTR_EXTENSION - lookupob.fde_end = NULL; -#endif - uintptr_type range[2]; - get_pc_range (&lookupob, range); + // Find the originally registered object to get the base pointer. + ob = btree_remove (®istered_frames, (uintptr_type) begin); - // And remove - ob = btree_remove (®istered_frames, range[0]); - bool empty_table = (range[1] - range[0]) == 0; + // Remove the corresponding PC range. + if (ob) + { + uintptr_type range[2]; + get_pc_range (ob, range); + if (range[0] != range[1]) + btree_remove (®istered_frames, range[0]); + } // Deallocate the sort array if any. if (ob && ob->s.b.sorted) @@ -283,12 +284,11 @@ __deregister_frame_info_bases (const void *begin) out: __gthread_mutex_unlock (&object_mutex); - const int empty_table = 0; // The non-atomic path stores all tables. #endif // If we didn't find anything in the lookup data structures then they // were either already destroyed or we tried to remove an empty range. - gcc_assert (in_shutdown || (empty_table || ob)); + gcc_assert (in_shutdown || ob); return (void *) ob; } -- 2.39.2