From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 50B643858C39 for ; Wed, 20 Mar 2024 08:25:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50B643858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 50B643858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710923136; cv=none; b=iy3ChPxmQxCEtQibWdkMEnmHZFtH+DI/jvCPxE/++JRt03qWbofUZkJpmkRgMa0G8I+eK/qfFCiMk6sVdWK2VoJYxA8SfORu7tipXBe4hHYQt8hCZeP5oAQxtMMmkjqfFHrxma3xHoYo7K3iJ5hvvqPL1KpUx/O9uKXChk6XwMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710923136; c=relaxed/simple; bh=gO+FRmBAOTBYK4EYWMwO0QCkSUUOJRg0N2WB8sTSos0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=VaPGDUrmEz+MTMp8+19en+FahDod87ImOySfmc81WZD5SQKcpD1dmc6wfqs5WSoUO2ADCUmOLdtiBULpv84JwfzfAmTtvQQKuIrzojpAZ8Imn7tzxdWzo0iReh4atx/tGE6N4p69zL2zwphXTtjGrXe3UKO1S3B2hRVxtSnjZAE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2d228a132acso91182931fa.0 for ; Wed, 20 Mar 2024 01:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710923127; x=1711527927; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gZkRx5Y371xVUUZhYK300U5NQAsTn3w9x2He/1aLLmc=; b=XV9wUWqA/qdv5gg8e/4/EMhWKvOHFeWPkTzmxIc9PYfO0J4kzWY5N9IzN7RHVt2ZqM zQOko5pn3IlshVMBsau2cBFq/P9wrx4FuILdRkFpExlEm/5SohcTbznile6Easj9M9ZQ ggzS7wkWo4IcAIrMmQaErCXBm/iGDZDWkkU2CnktbC+cYoIz0dsDF0b+HiaZl5cd2GH9 sV1iM+60DfP5KN0R8ckt+nvsHQ8IqoHGNqJw9EwGnaKW8VKJuXc5DvRLkK/P6pUAqLiD T7NH7QKMmSy3rnB78xXQF34BbZcEOlZhUbvqjSKMVn6meQt/IuubLGScWkd8eiF2L6o6 pPxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710923127; x=1711527927; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gZkRx5Y371xVUUZhYK300U5NQAsTn3w9x2He/1aLLmc=; b=Qjn1h1eKap3uN352zGIARIlBZagdM0jPSX1ivSOgQytjyVHygRTDGllRKBkS8oA8fx 7aYIuB5U7d9mZIQZhZb5a7oVWnbQOy/SY/W8xlJCDG88EUgaS22OXvbK6Mw+Eaer7iVC ZWtk7wyniTbI8Qv2/U9Zz6h+foYmgaHwpVNcAtZJtHWH+yoGvWjGNgFfnZ2OzeUN0Doi lJ6eu5uAG0KWOdHj5enQD3T09WHXS+VFt2coLyrpgQbk+3v9RvB3XYp3EBLIDCEECqhZ 9zUYbNJuP0B0za0ngrXxCc83ih3tjpDwjCv+53B9g75s3rTKdfTdaN99VEehXTjiOP5q paCA== X-Gm-Message-State: AOJu0Yyn92ut2UN9uJnBK0xFu+m0qr3XX41YTYa765cV19IVeQT842Pv MMYAAvPeCmbNUkYCUmSmGPNTemfS4NIECfMT5a5m74nZelgRSW31PGXdKfGNd6Mwx4AqspDFkC4 7SJ29KciSxIr3sIZqMNT0C99swsA= X-Google-Smtp-Source: AGHT+IEJEPgnmUka5m6fKzfqL6E3N3wDCfnbQwGm6qSBxj9XVyCX+dSehvidbxSUspvCjQ7P0OeHmG2Zek51QCnLs8k= X-Received: by 2002:a19:ca04:0:b0:513:d5b4:f902 with SMTP id a4-20020a19ca04000000b00513d5b4f902mr3405411lfg.67.1710923127267; Wed, 20 Mar 2024 01:25:27 -0700 (PDT) MIME-Version: 1.0 References: <2a4776b9-9271-bb3c-a626-d5ec22dae6f3@in.tum.de> <91045a34-a534-4436-bb06-cac32d797a36@in.tum.de> <87sfibqu1s.fsf@oldenburg.str.redhat.com> In-Reply-To: From: Richard Biener Date: Wed, 20 Mar 2024 09:25:15 +0100 Message-ID: Subject: Re: [PATCH] handle unwind tables that are embedded within unwinding code, [PR111731] To: Thomas Neumann , Jason Merrill , Florian Weimer Cc: "gcc-patches@gcc.gnu.org" , Jakub Jelinek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: On Fri, Mar 15, 2024 at 11:31=E2=80=AFAM Thomas Neumann wrote: > > Original bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D11173= 1 > Given that this is a regression, is this okay for gcc 13 and mainline? It does look straightforward but I hope Jason or Florian can provide the AC= K. Thanks, Richard. > 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 late= r are > * silently ignored */ > btree_destroy (®istered_frames); > + btree_destroy (®istered_objects); > in_shutdown =3D 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 deregistrati= on. > + 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, stru= ct object *ob, > #endif > > #ifdef ATOMIC_FDE_FAST_PATH > - // Register the object itself to know the base pointer on deregistrati= on. > - 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, stru= ct object *ob, > ob->s.b.encoding =3D DW_EH_PE_omit; > > #ifdef ATOMIC_FDE_FAST_PATH > - // Register the object itself to know the base pointer on deregistrati= on. > - 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 =3D btree_remove (®istered_frames, (uintptr_type) begin); > + ob =3D 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] !=3D range[1]) > - btree_remove (®istered_frames, range[0]); > + btree_remove (®istered_frames, range[0]); > } > > // Deallocate the sort array if any. > -- > 2.43.0 >