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

--- Comment #17 from Martin Liška <marxin at gcc dot gnu.org> ---
Or I may have a smarter trick: let's do dry run of malloc/free functions early
in __gcov_init. Can you please test the patch as well?

commit d80cecdb87d159f0b3a4072b6e1ef80515ad2afb
Author: Martin Liska <mli...@suse.cz>
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 = 0;
+  if (!malloc_utilized)
+    {
+      __gcov_test_memory  = malloc (16);
+      free (__gcov_test_memory);
+      malloc_utilized = 1;
+    }
+
   if (!info->version || !info->n_functions)
     return;
   if (gcov_version (info, info->version, 0))

Reply via email to