From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTPS id ECB48385840E for ; Sun, 14 May 2023 16:09:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECB48385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=soeren-tempel.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=soeren-tempel.net DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=opensmtpd; bh=DHxojpY6ie zr/0zxfXetANtvYHWxkea2LyVF2nV3cms=; h=from:subject:cc:to:date; d=soeren-tempel.net; b=inmO8GOjFOPjKDEZHF/Srm9/xUoUMvgqVX7MxCgfuR93uqD xk8+rapP31wABA4f6ZmxCkRhB2FneGhiWgUhAF04LNJHSUJVIXlL7HW7Invko7Il9lRijA VtVqOmKAkHRMwHV8eg+Zn//m9VbftMTlj9TdsMDutBLlsFSmoHByas= Received: from localhost ( [2a02:8109:3b40:398a:3ea7:a648:38d:8056]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id d9889997 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Sun, 14 May 2023 18:09:39 +0200 (CEST) Date: Sun, 14 May 2023 18:09:35 +0200 To: neumann@in.tum.de Cc: gcc-patches@gcc.gnu.org, tneumann@users.sourceforge.net, alice@ayaya.dev Subject: [PATCH] Fix assertion for unwind-dw2-fde.c btree changes From: =?UTF-8?Q?S=C3=B6ren?= Tempel Message-Id: <2TMB4YQOP1E1R.2QLW7HCD1NVF3@8pit.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_239b30b51b5026374cfb0161_=_" X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_LOTSOFHASH,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: This is a multipart message in MIME format. ------_=_239b30b51b5026374cfb0161_=_ Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Dear Thomas Neumann, I am contacting you as the author of the commit with commit hash 6e80a1d164d1f996ad08a512c000025a7c2ca893 [1] in the GCC repository. In this commit, you refactored the __register_frame/__deregister_frame implementation in GCC. The commit is part of the GCC 13 release. While upgrading the GCC version in Alpine Linux from GCC 12 to GCC 13 we ran into a regression introduced by these changes. The regression manifests itself in a failing assertion in __deregister_frame_info_bases. The assertion failure was observed while using Chromium's `flatc` build system tool. The failing assertion is: unwind-dw2-fde.c:281 gcc_assert (in_shutdown || ob); The assertion fails for us because ob is a null pointer and in_shutdown is zero. The backtrace for the assertion failure looks as follows: #0 __restore_sigs (set=3Dset@entry=3D0x7fffffffe050) at ./arch/x86_64/sys= call_arch.h:40 #1 0x00007ffff7facea5 in raise (sig=3Dsig@entry=3D6) at src/signal/raise.= c:11 #2 0x00007ffff7f7ffa8 in abort () at src/exit/abort.c:11 #3 0x00007ffff7f3d411 in __deregister_frame_info_bases (begin=3D0x5555555= 7ef58) at /home/buildozer/aports/main/gcc/src/gcc-13-20230506/libgcc/unwind-d= w2-fde.c:281 #4 __deregister_frame_info_bases (begin=3D0x55555557ef58) at /home/buildozer/aports/main/gcc/src/gcc-13-20230506/libgcc/unwind-d= w2-fde.c:219 #5 0x0000555555580072 in __do_global_dtors_aux () #6 0x000000185eb03fee in ?? () #7 0x00007ffff7fc1ad6 in __libc_exit_fini () at ldso/dynlink.c:1453 #8 0x00007ffff7f78082 in exit (code=3D1) at src/exit/exit.c:30 #9 0x00005555555802a6 in Error(flatbuffers::FlatCompiler const*, std::__c= xx11::basic_string, std::allocator > con= st&, bool, bool) () #10 0x000055555560f952 in flatbuffers::FlatCompiler::ParseFromCommandLineA= rguments(int, char const**) () #11 0x0000555555581b42 in main ( I noticed that you already pushed a fixup for the aforementioned assertion in commit 386ebf75f4c0342b1f823f4e4aba07abda3288d1 [2]. However, I believe there is one more edge case that isn't being account for presently: If the inserted entry has a size of 0 (i.e. if range[1] - range[0] =3D=3D 0) then the btree_insert call in __register_frame_info_base= s will not insert anything. This is not accounted for in __deregister_frame_info_bases as it is assumed that the prior btree_insert call in __register_frame_info_bases always inserted something into the lookup data structure. Based on the information contained in the backtrace shown above, this behavior can be observed in the following gdb debug session: (gdb) break __register_frame_info_bases if begin=3D=3D0x55555557ef58 (gdb) run Breakpoint 11.1, __register_frame_info_bases (begin=3D0x55555557ef58, ob=3D= 0x555555907f60 , tbase=3D0x0, dbase=3D0x0) at /home/buildozer/aports/main/gcc/src/gcc-13-20230506/libgcc/unwind-d= w2-fde.c:111 (gdb) break btree_insert (gdb) cont Continuing. Breakpoint 12, btree_insert (base=3D0, size=3D0, ob=3D0x555555907f60 , t=3D0x7ffff7f5d290 ) at /home/buildozer/aports/main/gcc/src/gcc-13-20230506/libgcc/unwind-dw2-= btree.h:726 726 if (!size) (gdb) p size $1 =3D 0 (gdb) next 727 return false; =46rom the above debug output, we can deduce that nothing was inserted into= =0A= the lookup data structure for the frame beginning at 0x55555557ef58 because the size of the range is zero. If we set at breakpoint in __deregister_frame_info_bases for the same frame we can observe the following: (gdb) break __deregister_frame_info_bases if begin=3D=3D0x55555557ef58 Continuing. /home/buildozer/aports/community/chromium/src/chromium-113.0.5672.92/out/b= ld/flatc: Breakpoint 13.1, __deregister_frame_info_bases (begin=3D0x55555557ef58) at /home/buildozer/aports/main/gcc/src/gcc-13-20230506/libgcc/unwind-d= w2-fde.c:220 (gdb) break unwind-dw2-fde.c:242 (gdb) cont 242 ob =3D btree_remove (®istered_frames, range[0]); (gdb) p range $2 =3D {0, 0} (gdb) next (gdb) p ob $3 =3D 0x0 Naturally, since nothing was inserted into the lookup data structure for this frame, btree_remove isn't able to remove anything and returns a null pointer for ob. This then causes the aforementioned assertion failure. A git-format-patch(1) for the assertion is attached, which adds handling for the edge case that nothing was inserted via btree_insert in __register_frame_info_bases to __deregister_frame_info_bases. Would be cool if this could be fixed on the GCC trunk. Greetings S=C3=B6ren Tempel [1]: https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommit;h=3D6e80a1d164d1f996ad= 08a512c000025a7c2ca893 [2]: https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommit;h=3D386ebf75f4c0342b1f= 823f4e4aba07abda3288d1 ------_=_239b30b51b5026374cfb0161_=_ Content-Disposition: attachment; filename*0*=UTF-8''0001-fix-assert-in-__deregister_frame_info_bases.patc; filename*1*=h Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =46rom 6dc56564cad69a26595cc38956355e5be7d2c2b0 Mon Sep 17 00:00:00 2001 =46rom: =3D?UTF-8?q?S=3DC3=3DB6ren=3D20Tempel?=3D =44ate: Sun, 14 May 2023 19:30:21 +0200 =53ubject: [PATCH] fix assert in __deregister_frame_info_bases =4DIME-Version: 1.0 =43ontent-Type: text/plain; charset=3DUTF-8 =43ontent-Transfer-Encoding: 8bit =0AThe assertion in __deregister_frame_info_bases assumes that for every =66rame something was inserted into the lookup data structure by =5F_register_frame_info_bases. Unfortunately, this does not necessarily =68old true as the btree_insert call in __register_frame_info_bases will =6Eot insert anything for empty ranges. Therefore, we need to explicitly =61ccount for such empty ranges in the assertion as `ob` will be a null =70ointer for such ranges, hence causing the assertion to fail. =0ASigned-off-by: S=C3=B6ren Tempel =2D-- =20libgcc/unwind-dw2-fde.c | 4 +++- =201 file changed, 3 insertions(+), 1 deletion(-) =0Adiff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c =69ndex 7b74c391ced..8683a65aa02 100644 =2D-- a/libgcc/unwind-dw2-fde.c =2B++ b/libgcc/unwind-dw2-fde.c =40@ -278,7 +278,9 @@ __deregister_frame_info_bases (const void *begin) =20 __gthread_mutex_unlock (&object_mutex); =20#endif =20= =2D gcc_assert (in_shutdown || ob); =2B // If we didn't find anything in the lookup data structures then they =2B // were either already destroyed or we tried to remove an empty range.= =0A+ gcc_assert (in_shutdown || ((range[1] - range[0]) =3D=3D 0 || ob)); =20 return (void *) ob; =20} =20= ------_=_239b30b51b5026374cfb0161_=_--