From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout1.rbg.tum.de (mailout1.rbg.tum.de [131.159.0.201]) by sourceware.org (Postfix) with ESMTPS id 114F93857836 for ; Fri, 15 Mar 2024 10:30:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 114F93857836 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 114F93857836 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.159.0.201 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710498607; cv=none; b=gYXe9Hzb0FH3KKgnLQRU7GQJ8aMMeacf+4guh++r6Q1joCN1DQPlAqZKnsADsT2mWdrsZaqf3yjbLAqmDgkYf8wvWeev1g39AVU7bpT8Xfc5btygdN86ZROl59/7j79/M0DYyxBErwn7KVB41X7GvTc+Sw5dUocunYVOyY7AIgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710498607; c=relaxed/simple; bh=anfcATDirPsqQC9FoTFxQr37wSxT8hrx8J2N2Ys2Pec=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=LqwiZe0rR+tbB6pn7Lp+5MQfQE4uvl2aovraqEDO2AJoWIeZ2mSylvT3KUnsEfUp6Ii+GHFzE72Qu6MwxwDvrGvhyQpmcfjJvXWq7r9eWOmeZ71PaitXs93SFz9j2C5pefAPFsg9egaZXeIpk9ae1n5c66n1O4pFVSZOStdGmDw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout1.rbg.tum.de (Postfix) with ESMTPS id BF7727E; Fri, 15 Mar 2024 11:29:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=in.tum.de; s=20220209; t=1710498598; bh=YR4vLEBHgc+dMtQdB7IKKCRyK9W2cJqVvS6EfUgsZuo=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=MT+lLV4/WVjS+qyg2HetF8Ys6He70evT/gEqmfOvM1zwGEbTY3D44/5IJwvkljHpP wmEtRAMBJd2lL54QxlGoS+YIP5sjh2HazeoxzPs871KWNqbqqT+e+zkJL8ndPGvz41 Nofc7HoJvud+pzLSK359aAsjFSlujm/Il/B7vKtD3+e0nPvXHNxZXTa859sE0exGki 7Cipmzt0GcKhULf6WsE+GlLhO4brBiw/NZjgSHcR86w982+YU3elXYy7AsU0/EEUNf toduXz7vZ2TsEnVh/MU/DTtkE6kCDsEba0kyWPcjaSsciPkIRn1QXoE+EOWbkoeXIf l3MTY4OsB6gkA== Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id BA164FC; Fri, 15 Mar 2024 11:29:58 +0100 (CET) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id 94AF9B5; Fri, 15 Mar 2024 11:29:58 +0100 (CET) Received: from mail.in.tum.de (vmrbg426.in.tum.de [131.159.0.73]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id 931D799; Fri, 15 Mar 2024 11:29:58 +0100 (CET) Received: by mail.in.tum.de (Postfix, from userid 112) id 901BE4A01D8; Fri, 15 Mar 2024 11:29:58 +0100 (CET) Received: (Authenticated sender: neumann) by mail.in.tum.de (Postfix) with ESMTPSA id F34304A0211; Fri, 15 Mar 2024 11:29:48 +0100 (CET) (Extended-Queue-bit xtech_cf@fff.in.tum.de) Message-ID: Date: Fri, 15 Mar 2024 11:29:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Thomas Neumann Subject: [PATCH] handle unwind tables that are embedded within unwinding code, [PR111731] To: "gcc-patches@gcc.gnu.org" Cc: Jakub Jelinek 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=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,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: Original bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111731 Given that this is a regression, is this okay for gcc 13 and mainline? The unwinding mechanism registers both the code range and the unwind table itself within a b-tree lookup structure. That data structure assumes that is consists of non-overlappping intervals. This becomes a problem if the unwinding table is embedded within the code itself, as now the intervals do overlap. To fix this problem we now keep the unwind tables in a separate b-tree, which prevents the overlap. libgcc/ChangeLog: PR libgcc/111731 * unwind-dw2-fde.c: Split unwind ranges if they contain the unwind table. --- libgcc/unwind-dw2-fde.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c index 61a578d097e..9d503545677 100644 --- a/libgcc/unwind-dw2-fde.c +++ b/libgcc/unwind-dw2-fde.c @@ -48,6 +48,7 @@ typedef __UINTPTR_TYPE__ uintptr_type; #include "unwind-dw2-btree.h" static struct btree registered_frames; +static struct btree registered_objects; static bool in_shutdown; static void @@ -58,6 +59,7 @@ release_registered_frames (void) /* Release the b-tree and all frames. Frame releases that happen later are * silently ignored */ btree_destroy (®istered_frames); + btree_destroy (®istered_objects); in_shutdown = true; } @@ -103,6 +105,21 @@ static __gthread_mutex_t object_mutex; #endif #endif +#ifdef ATOMIC_FDE_FAST_PATH +// Register the pc range for a given object in the lookup structure. +static void +register_pc_range_for_object (uintptr_type begin, struct object *ob) +{ + // Register the object itself to know the base pointer on deregistration. + btree_insert (®istered_objects, begin, 1, ob); + + // Register the frame in the b-tree + uintptr_type range[2]; + get_pc_range (ob, range); + btree_insert (®istered_frames, range[0], range[1] - range[0], ob); +} +#endif + /* Called from crtbegin.o to register the unwind info for an object. */ void @@ -124,13 +141,7 @@ __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); - btree_insert (®istered_frames, range[0], range[1] - range[0], ob); + register_pc_range_for_object ((uintptr_type) begin, ob); #else init_object_mutex_once (); __gthread_mutex_lock (&object_mutex); @@ -178,13 +189,7 @@ __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); - btree_insert (®istered_frames, range[0], range[1] - range[0], ob); + register_pc_range_for_object ((uintptr_type) begin, ob); #else init_object_mutex_once (); __gthread_mutex_lock (&object_mutex); @@ -232,7 +237,7 @@ __deregister_frame_info_bases (const void *begin) #ifdef ATOMIC_FDE_FAST_PATH // Find the originally registered object to get the base pointer. - ob = btree_remove (®istered_frames, (uintptr_type) begin); + ob = btree_remove (®istered_objects, (uintptr_type) begin); // Remove the corresponding PC range. if (ob) @@ -240,7 +245,7 @@ __deregister_frame_info_bases (const void *begin) uintptr_type range[2]; get_pc_range (ob, range); if (range[0] != range[1]) - btree_remove (®istered_frames, range[0]); + btree_remove (®istered_frames, range[0]); } // Deallocate the sort array if any. -- 2.43.0