From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CBD63858020; Thu, 29 Oct 2020 18:54:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CBD63858020 From: "marxin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/97461] [11 Regression] allocate_gcov_kvp() deadlocks in firefox LTO+PGO build (overridden malloc() recursion) Date: Thu, 29 Oct 2020 18:54:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: marxin at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: marxin at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2020 18:54:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97461 --- Comment #17 from Martin Li=C5=A1ka --- Or I may have a smarter trick: let's do dry run of malloc/free functions ea= rly in __gcov_init. Can you please test the patch as well? commit d80cecdb87d159f0b3a4072b6e1ef80515ad2afb Author: Martin Liska Date: Thu Oct 29 19:52:37 2020 +0100 PGO: use dry run of malloc and free functions. diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index e53e4dc392a..dd481b48e22 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -608,12 +608,25 @@ __gcov_exit (void) gcov_error_exit (); } +/* Test memory that forces malloc and free functions to be called early + so that allocate_gcov_kvp can use calloc. Indirect call counters + taken from a pre-allocated array are used before that. */ +char *__gcov_test_memory; + /* Add a new object file onto the bb chain. Invoked automatically when running an object file's global ctors. */ void __gcov_init (struct gcov_info *info) { + static int malloc_utilized =3D 0; + if (!malloc_utilized) + { + __gcov_test_memory =3D malloc (16); + free (__gcov_test_memory); + malloc_utilized =3D 1; + } + if (!info->version || !info->n_functions) return; if (gcov_version (info, info->version, 0))=