public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marxin at gcc dot gnu.org" <gcc-bugzilla@gcc.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: Mon, 09 Nov 2020 09:57:01 +0000	[thread overview]
Message-ID: <bug-97461-4-hXalDTSRqO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97461-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97461

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #23 from Martin Liška <marxin at gcc dot gnu.org> ---
Thank you for the testing. Neither of the suggested changes help us.
The core issue is that gcov does not know if it's called from a free/malloc
function.

That said, I see currently 2 possible fixes:

1. help from a malloc library that uses
__gcov_supress_malloc/__gcov_allow_malloc:

commit ee382a226ba0e76e2242dcbb4768033a4809a890
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Nov 6 16:59:43 2020 +0100

    WIP patch.

diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index d6075d32bd4..b235231f9d6 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -907,7 +907,7 @@ LIBGCOV_PROFILER = _gcov_interval_profiler                 
        \
 LIBGCOV_INTERFACE = _gcov_dump _gcov_fork                              \
        _gcov_execl _gcov_execlp                                        \
        _gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset  \
-       _gcov_lock_unlock
+       _gcov_lock_unlock _gcov_supress_malloc _gcov_allow_malloc
 LIBGCOV_DRIVER = _gcov

 libgcov-merge-objects = $(patsubst %,%$(objext),$(LIBGCOV_MERGE))
diff --git a/libgcc/gcov.h b/libgcc/gcov.h
index 0e3eed31032..444f996692e 100644
--- a/libgcc/gcov.h
+++ b/libgcc/gcov.h
@@ -33,4 +33,12 @@ extern void __gcov_reset (void);

 extern void __gcov_dump (void);

+/* Prevent from calling malloc.  */
+
+extern void __gcov_supress_malloc (void);
+
+/* Allow calling malloc.  */
+
+extern void __gcov_allow_malloc (void);
+
 #endif /* GCC_GCOV_H */
diff --git a/libgcc/libgcov-interface.c b/libgcc/libgcov-interface.c
index 3a8a5bf44b8..bcfc38b85c3 100644
--- a/libgcc/libgcov-interface.c
+++ b/libgcc/libgcov-interface.c
@@ -36,6 +36,14 @@ void __gcov_reset (void) {}
 void __gcov_dump (void) {}
 #endif

+#ifdef L_gcov_supress_malloc
+void __gcov_supress_malloc (void) {}
+#endif
+
+#ifdef L_gcov_allow_malloc
+void __gcov_allow_malloc (void) {}
+#endif
+
 #else

 extern __gthread_mutex_t __gcov_mx ATTRIBUTE_HIDDEN;
@@ -174,6 +182,20 @@ __gcov_dump (void)

 #endif /* L_gcov_dump */

+#ifdef L_gcov_supress_malloc
+void __gcov_supress_malloc (void)
+{
+  __gcov_block_malloc = 1;
+}
+#endif /* L_gcov_supress_malloc */
+
+#ifdef L_gcov_allow_malloc
+void __gcov_allow_malloc (void)
+{
+  __gcov_block_malloc = 0;
+}
+#endif /* L_gcov_block_malloc */
+
 #ifdef L_gcov_fork
 /* A wrapper for the fork function.  We reset counters in the child
    so that they are not counted twice.  */
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index 45ab93c9776..b83b230cd9c 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -141,6 +141,12 @@ __thread
 #endif
 struct indirect_call_tuple __gcov_indirect_call;

+// TODO: move to a proper place
+#if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
+__thread
+#endif
+int __gcov_block_malloc;
+
 /* By default, the C++ compiler will use function addresses in the
    vtable entries.  Setting TARGET_VTABLE_USES_DESCRIPTORS to nonzero
    tells the compiler to use function descriptors instead.  The value
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index e70cf63b414..2eaed9548ea 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -247,6 +247,12 @@ struct indirect_call_tuple
   /* Pointer to counters.  */
   gcov_type *counters;
 };
+
+extern
+#if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
+__thread
+#endif
+int __gcov_block_malloc;

 /* Exactly one of these will be active in the process.  */
 extern struct gcov_master __gcov_master;
@@ -428,7 +434,12 @@ allocate_gcov_kvp (void)
 #endif

   if (new_node == NULL)
-    new_node = (struct gcov_kvp *)xcalloc (1, sizeof (struct gcov_kvp));
+    {
+#if !defined(IN_GCOV_TOOL)
+      if (!__gcov_block_malloc)
+       new_node = (struct gcov_kvp *)xcalloc (1, sizeof (struct gcov_kvp));
+#endif
+    }

   return new_node;
 }

2) make a dynamic allocation for counters for TOPN at the very beginning in
__gcov_init.

@Honza: What do you think about it?

  parent reply	other threads:[~2020-11-09  9:57 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16 15:03 [Bug gcov-profile/97461] New: " slyfox at gcc dot gnu.org
2020-10-16 15:05 ` [Bug gcov-profile/97461] " slyfox at gcc dot gnu.org
2020-10-16 15:09 ` slyfox at gcc dot gnu.org
2020-10-16 15:16 ` slyfox at gcc dot gnu.org
2020-10-19  7:12 ` [Bug gcov-profile/97461] [11 Regression] " marxin at gcc dot gnu.org
2020-10-19  7:15 ` rguenth at gcc dot gnu.org
2020-10-19 13:42 ` marxin at gcc dot gnu.org
2020-10-19 13:46   ` Jan Hubicka
2020-10-19 13:46 ` hubicka at ucw dot cz
2020-10-19 14:15 ` marxin at gcc dot gnu.org
2020-10-19 14:51   ` Jan Hubicka
2020-10-19 14:52 ` hubicka at ucw dot cz
2020-10-19 14:58 ` marxin at gcc dot gnu.org
2020-10-27 10:50 ` cvs-commit at gcc dot gnu.org
2020-10-27 10:50 ` marxin at gcc dot gnu.org
2020-10-27 22:18 ` slyfox at gcc dot gnu.org
2020-10-29 10:19 ` marxin at gcc dot gnu.org
2020-10-29 14:53 ` slyfox at gcc dot gnu.org
2020-10-29 15:00 ` marxin at gcc dot gnu.org
2020-10-29 15:05 ` marxin at gcc dot gnu.org
2020-10-29 18:54 ` marxin at gcc dot gnu.org
2020-10-29 19:11 ` jakub at gcc dot gnu.org
2020-10-30  8:45 ` slyfox at gcc dot gnu.org
2020-10-30 23:37 ` slyfox at gcc dot gnu.org
2020-11-06 13:47 ` cvs-commit at gcc dot gnu.org
2020-11-06 13:49 ` marxin at gcc dot gnu.org
2020-11-09  9:57 ` marxin at gcc dot gnu.org [this message]
2020-12-04  7:01 ` marxin at gcc dot gnu.org
2021-01-21  9:26 ` rguenth at gcc dot gnu.org
2021-01-26 11:51 ` marxin at gcc dot gnu.org
2021-03-03 13:22 ` cvs-commit at gcc dot gnu.org
2021-03-03 13:27 ` marxin at gcc dot gnu.org
2021-03-03 13:31 ` jakub at gcc dot gnu.org
2021-03-03 14:49 ` marxin at gcc dot gnu.org
2021-03-03 15:14 ` lh_mouse at 126 dot com
2021-03-05 18:11 ` slyfox at gcc dot gnu.org
2021-03-06  8:19 ` marxin at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97461-4-hXalDTSRqO@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).