From patchwork Mon Sep 19 16:20:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Neumann X-Patchwork-Id: 1302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1040800wrt; Mon, 19 Sep 2022 09:21:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oyFo1wrz2NMYs3GhffQ5je091ci8wm8wkvOPjlc0Nnd6VRkYBUR1gCpFXxbWD7fdASJZe X-Received: by 2002:a05:6402:ca9:b0:44e:d8f3:3d0e with SMTP id cn9-20020a0564020ca900b0044ed8f33d0emr16189126edb.397.1663604476710; Mon, 19 Sep 2022 09:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663604476; cv=none; d=google.com; s=arc-20160816; b=OimoI5cCZPQj7xFyzZosnK2y047w7yIQvoRM550K777SCJRqbKCOu48ElIIefIG3Ud Eqs2padG1dTuGhm4j18mkTj3lPMAUD9L5NY0O/yDEdLLytAfT1iq0cq7yai/uuLgvoW6 /7JRVt4NV1a1/OMDyaEoeH+8Bq6Ug68DoAiAqbH9bxMchnAdW0y7RCrJFSda1iZy/vUn By2dFpkpewTA1xz2NR/7gKvOkpozzhxkqwYpXr9b8yRtCEjdVPS16yjJMAUmFBY6Ycer I21eGonLuhtP6+A9KWOn39/GdLmdG34hVUnyk8x/BnqEx+MwRKCqXeWlALbGboflN3ir Ay4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=dmqUsclje1VbV714APZpkNWih8pLSA7QF947RT/QcTY=; b=ut0er1rXxEridhMv5fn13GKGGqxdkS7cOM+oE8BxOKn9ag5ROOU89xGpu1hDiFhuMR rYoSYSz95DkficGW/RuJ4aneClfBLekdlwW1UYEHXU5H56+TsYwW/ztTXrj6qdh4AWcm L5nMGL/zQeX7Cth+KyQ3HgY4Xp0KraOAofnPoku8BLeiPcdbdaMNj/jieLIRBAVokvhH tbDthz1ak0iOnVMF1TuHcgWSEuGHuDJ1G8ZX5Ew9ntj3VhypVTQ6uO9g8j7bxGQ0iT0k E9iu2twiaLlK6aeEXGcCQIzLdrCRbX5DbdkomZIohajlurAYVXHfBi73yKB/av6VB09I Jq0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s5E3KB6q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q16-20020a1709064c9000b007314b427e96si21584331eju.633.2022.09.19.09.21.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 09:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s5E3KB6q; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B06D33858C56 for ; Mon, 19 Sep 2022 16:21:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B06D33858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663604475; bh=dmqUsclje1VbV714APZpkNWih8pLSA7QF947RT/QcTY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=s5E3KB6qsb8MzlZXswCZoqc6T2TriPzFoznJoRM+Nnz3/MqdCcApZmQeTU41KZeZz Q2LLJ88NXSnqCrRBSETAy6BeARIXXy6WxgCtPScEJ+dX7QuAlEyA8K8LdqdwUQuY9S 2N1iTCNMa2Ob4HTCKWOiXrz8X4+uoBDk39BhOO/M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailout3.rbg.tum.de (mailout3.rbg.tum.de [131.159.0.8]) by sourceware.org (Postfix) with ESMTPS id 769023858D28 for ; Mon, 19 Sep 2022 16:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 769023858D28 Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout3.rbg.tum.de (Postfix) with ESMTPS id 006D61003BD; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id ECC9E1AA; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id CA0B41A8; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) Received: from mail.in.tum.de (mailproxy.in.tum.de [IPv6:2a09:80c0::78]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id C813ACD; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id C59584A034B; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) Received: (Authenticated sender: neumann) by mail.in.tum.de (Postfix) with ESMTPSA id 89C1D4A0063; Mon, 19 Sep 2022 18:20:23 +0200 (CEST) (Extended-Queue-bit xtech_vi@fff.in.tum.de) Message-ID: <5aba5553-ed71-50a8-e934-6e94f3a1057e@in.tum.de> Date: Mon, 19 Sep 2022 18:20:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid depending on destructor order X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Neumann via Gcc-patches From: Thomas Neumann Reply-To: Thomas Neumann Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744415727563508919?= X-GMAIL-MSGID: =?utf-8?q?1744415727563508919?= In some scenarios (e.g., when mixing gcc and clang code), it can happen that frames are deregistered after the lookup structure has already been destroyed. That in itself would be fine, but it triggers an assert in __deregister_frame_info_bases that expects to find the frame. To avoid that, we now remember that the btree as already been destroyed and disable the assert in that case. libgcc/ChangeLog: * unwind-dw2-fde.c: (release_register_frames) Remember when the btree has been destroyed. (__deregister_frame_info_bases) Disable the assert when shutting down. --- libgcc/unwind-dw2-fde.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) static void @@ -282,7 +284,7 @@ __deregister_frame_info_bases (const void *begin) __gthread_mutex_unlock (&object_mutex); #endif - gcc_assert (ob); + gcc_assert (in_shutdown || ob); return (void *) ob; } diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c index 919abfe0664..d237179f4ea 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 bool in_shutdown; static void release_registered_frames (void) __attribute__ ((destructor (110))); @@ -57,6 +58,7 @@ release_registered_frames (void) /* Release the b-tree and all frames. Frame releases that happen later are * silently ignored */ btree_destroy (®istered_frames); + in_shutdown = true; }