aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-06-02 13:31:48 +0200
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 13:20:21 -0300
commit24893cb6c1b8c56863331b6532a5f601c6f6c910 (patch)
tree3522565026d89f492da61e514a43d924bfe8d860 /gcc
parent2ef9777aa4708197954b48c12552b94607d34c70 (diff)
downloadgcc-24893cb6c1b8c56863331b6532a5f601c6f6c910.zip
gcc-24893cb6c1b8c56863331b6532a5f601c6f6c910.tar.gz
gcc-24893cb6c1b8c56863331b6532a5f601c6f6c910.tar.bz2
libgcov: support overloaded malloc
gcc/ChangeLog: * gcov-io.h (GCOV_PREALLOCATED_KVP): New. libgcc/ChangeLog: * libgcov-driver.c: Add __gcov_kvp_pool and __gcov_kvp_pool_index variables. * libgcov.h (allocate_gcov_kvp): New. (gcov_topn_add_value): Use it. gcc/testsuite/ChangeLog: * gcc.dg/tree-prof/indir-call-prof-malloc.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcov-io.h3
-rw-r--r--gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-malloc.c49
2 files changed, 52 insertions, 0 deletions
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 940eb7d..4dba01c 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -292,6 +292,9 @@ GCOV_COUNTERS
/* Maximum number of tracked TOP N value profiles. */
#define GCOV_TOPN_MAXIMUM_TRACKED_VALUES 32
+/* Number of pre-allocated gcov_kvp structures. */
+#define GCOV_PREALLOCATED_KVP 16
+
/* Convert a counter index to a tag. */
#define GCOV_TAG_FOR_COUNTER(COUNT) \
(GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17))
diff --git a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-malloc.c b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-malloc.c
new file mode 100644
index 0000000..454e224
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-malloc.c
@@ -0,0 +1,49 @@
+/* { dg-options "-O2 -ldl" } */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdint.h>
+#include <dlfcn.h>
+
+int global;
+int global2;
+
+void report1 (size_t size)
+{
+ global++;
+}
+
+void report2 (size_t size)
+{
+ global2++;
+}
+
+typedef void (*tp) (size_t);
+static tp fns[] = {report1, report2};
+
+void* malloc(size_t size)
+{
+ static void* (*real_malloc)(size_t) = NULL;
+ if (!real_malloc)
+ real_malloc = dlsym(RTLD_NEXT, "malloc");
+
+ void *p = real_malloc (size);
+ fns[size % 2] (size);
+ // fprintf(stderr, "malloc(%d) = %p\n", size, p);
+ return p;
+}
+
+void *calloc (size_t n, size_t size)
+{
+ void *ptr = malloc (n * size);
+ __builtin_memset (ptr, 0, n * size);
+ return ptr;
+}
+
+void *ptr;
+
+int main()
+{
+ ptr = malloc (16);
+ return 0;
+}