aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcov-io.h2
-rw-r--r--gcc/testsuite/gcc.dg/tree-prof/pr97461.c58
2 files changed, 59 insertions, 1 deletions
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 4dba01c..4e95c7c 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -293,7 +293,7 @@ GCOV_COUNTERS
#define GCOV_TOPN_MAXIMUM_TRACKED_VALUES 32
/* Number of pre-allocated gcov_kvp structures. */
-#define GCOV_PREALLOCATED_KVP 16
+#define GCOV_PREALLOCATED_KVP 64
/* Convert a counter index to a tag. */
#define GCOV_TAG_FOR_COUNTER(COUNT) \
diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr97461.c b/gcc/testsuite/gcc.dg/tree-prof/pr97461.c
new file mode 100644
index 0000000..8d21a3e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/pr97461.c
@@ -0,0 +1,58 @@
+/* PR gcov-profile/97461 */
+/* { dg-options "-O2 -ldl" } */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int malloc_depth = 0;
+
+static char memory[128* 1024];
+static size_t memory_p = 0;
+
+void f1(void) {}
+void f2(void) {}
+
+typedef void (*fun_t)(void);
+static const fun_t funs[2] = { f1, f2, };
+
+static void * malloc_impl(size_t size) {
+ void * r = &memory[memory_p];
+ memory_p += size;
+
+ // force TOPN profile
+ funs[size % 2]();
+ return r;
+}
+
+// Override default malloc, check it it get s called recursively
+void * malloc(size_t size) {
+ // Must not be called recursively. Malloc implementation does not support it.
+ if (malloc_depth != 0) __builtin_trap();
+
+ ++malloc_depth;
+ void * r = malloc_impl(size);
+ --malloc_depth;
+ return r;
+}
+
+// Called from gcov
+void *calloc(size_t nmemb, size_t size) {
+ // Must not be called recursively. Malloc implementation does not support it.
+ if (malloc_depth != 0) __builtin_trap();
+
+ ++malloc_depth;
+ void * r = malloc_impl(size * nmemb);
+ memset(r, 0, size * nmemb);
+ --malloc_depth;
+ return r;
+}
+
+void free(void *ptr){}
+
+int main() {
+ void * p = malloc(8);
+ return p != 0 ? 0 : 1;
+}