summaryrefslogtreecommitdiffstats
path: root/documentation/gcov.txt
blob: 896ec939d6e1eccef4450162bba3a83d2aa07d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
This patch contains our local modifications for gcov-io.h and libgcov.c.
The file gcov-iov.h is taken from a gcc build (produced at compile
time). The file gcov-io.c is unchanged.

--- gcc-4.7.2/gcc/gcov-io.h	2011-12-04 10:27:19.000000000 -0800
+++ coreboot/src/lib/gcov-io.h	2013-01-12 16:45:57.000000000 -0800
@@ -163,6 +163,24 @@
 #ifndef GCC_GCOV_IO_H
 #define GCC_GCOV_IO_H
 
+#ifdef __COREBOOT__
+#define GCOV_LINKAGE /* nothing */
+/* We need the definitions for
+    BITS_PER_UNIT and
+    LONG_LONG_TYPE_SIZE
+   They are defined in gcc/defaults.h and gcc/config/<arch_depend_files>
+   (like, gcc/config/i386/i386.h). And it can be overridden by setting
+   in build scripts. Here I hardcoded the value for x86. */
+#define BITS_PER_UNIT 8
+#define LONG_LONG_TYPE_SIZE 64
+
+/* There are many gcc_assertions. Set the vaule to 1 if we want a warning
+   message if the assertion fails.  */
+#ifndef ENABLE_ASSERT_CHECKING
+#define ENABLE_ASSERT_CHECKING 1
+#endif
+#endif /* __COREBOOT__ */
+
 #if IN_LIBGCOV
 /* About the target */
 
@@ -232,7 +250,9 @@
    is not also used in a DSO.  */
 #if IN_LIBGCOV
 
+#ifndef __COREBOOT__
 #include "tconfig.h"
+#endif /* __COREBOOT__ */
 
 #define gcov_var __gcov_var
 #define gcov_open __gcov_open
@@ -455,8 +475,10 @@
 /* Register a new object file module.  */
 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
 
+#ifndef __COREBOOT__
 /* Called before fork, to avoid double counting.  */
 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
+#endif
 
 /* The merge function that just sums the counters.  */
 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
--- gcc-4.7.2/libgcc/libgcov.c	2012-01-11 10:50:21.000000000 -0800
+++ coreboot/src/lib/libgcov.c	2013-01-16 09:45:11.000000000 -0800
@@ -25,12 +25,41 @@
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#define __COREBOOT__
+#ifdef __COREBOOT__
+#include <stdlib.h>
+#include <string.h>
+#include <console/console.h>
+#include <assert.h>
+typedef s32 pid_t;
+#define gcc_assert(x) ASSERT(x)
+#define fprintf(file, x...) printk(BIOS_ERR, x)
+#define alloca(size)   __builtin_alloca (size)
+#include "gcov-glue.c"
+
+/* Define MACROs to be used by coreboot compilation.  */
+# define L_gcov
+# define L_gcov_interval_profiler
+# define L_gcov_pow2_profiler
+# define L_gcov_one_value_profiler
+# define L_gcov_indirect_call_profiler
+# define L_gcov_average_profiler
+# define L_gcov_ior_profiler
+
+# define HAVE_CC_TLS 0
+# define __GCOV_KERNEL__
+
+# define IN_LIBGCOV 1
+# define IN_GCOV 0
+#else /* __COREBOOT__ */
 #include "tconfig.h"
 #include "tsystem.h"
 #include "coretypes.h"
 #include "tm.h"
 #include "libgcc_tm.h"
+#endif /* __COREBOOT__ */
 
+#ifndef __COREBOOT__
 #if defined(inhibit_libc)
 #define IN_LIBGCOV (-1)
 #else
@@ -41,6 +70,7 @@
 #define GCOV_LINKAGE /* nothing */
 #endif
 #endif
+#endif /* __COREBOOT__ */
 #include "gcov-io.h"
 
 #if defined(inhibit_libc)
@@ -68,12 +98,17 @@
 
 #else
 
+#ifndef __COREBOOT__
 #include <string.h>
 #if GCOV_LOCKED
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/stat.h>
 #endif
+#else
+void __gcov_merge_add(gcov_type *counters  __attribute__ ((unused)),
+			unsigned n_counters __attribute__ ((unused))) {}
+#endif /* __COREBOOT__ */
 
 #ifdef L_gcov
 #include "gcov-io.c"
@@ -99,6 +134,10 @@
 static int
 create_file_directory (char *filename)
 {
+#ifdef __COREBOOT__
+  (void) filename;
+  return 0;
+#else
 #if !defined(TARGET_POSIX_IO) && !defined(_WIN32)
   (void) filename;
   return -1;
@@ -137,6 +176,7 @@
       };
   return 0;
 #endif
+#endif
 }
 
 static struct gcov_fn_buffer *
@@ -279,7 +319,7 @@
   struct gcov_ctr_summary *cs_ptr;
   const struct gcov_ctr_info *ci_ptr;
   unsigned t_ix;
-  int f_ix;
+  int f_ix = 0;
   gcov_unsigned_t c_num;
   const char *gcov_prefix;
   int gcov_prefix_strip = 0;
@@ -329,6 +369,7 @@
 	}
     }
 
+#ifndef __COREBOOT__
   {
     /* Check if the level of dirs to strip off specified. */
     char *tmp = getenv("GCOV_PREFIX_STRIP");
@@ -352,6 +393,7 @@
 	prefix_length--;
     }
   else
+#endif
     prefix_length = 0;
 
   /* If no prefix was specified and a prefix stip, then we assume
@@ -696,8 +738,10 @@
       if (filename_length > gcov_max_filename)
         gcov_max_filename = filename_length;
 
+#ifndef __COREBOOT__
       if (!gcov_list)
 	atexit (gcov_exit);
+#endif
 
       info->next = gcov_list;
       gcov_list = info;
@@ -767,14 +811,15 @@
 
 #ifdef L_gcov_merge_single
 /* The profile merging function for choosing the most common value.
-   It is given an array COUNTERS of N_COUNTERS old counters and it
-   reads the same number of counters from the gcov file.  The counters
-   are split into 3-tuples where the members of the tuple have
-   meanings:
-
-   -- the stored candidate on the most common value of the measured entity
-   -- counter
-   -- total number of evaluations of the value  */
+ * It is given an array COUNTERS of N_COUNTERS old counters and it
+ * reads the same number of counters from the gcov file.  The counters
+ * are split into 3-tuples where the members of the tuple have
+ * meanings:
+ *
+ * -- the stored candidate on the most common value of the measured entity
+ * -- counter
+ * -- total number of evaluations of the value
+ */
 void
 __gcov_merge_single (gcov_type *counters, unsigned n_counters)
 {
@@ -805,15 +850,16 @@
 
 #ifdef L_gcov_merge_delta
 /* The profile merging function for choosing the most common
-   difference between two consecutive evaluations of the value.  It is
-   given an array COUNTERS of N_COUNTERS old counters and it reads the
-   same number of counters from the gcov file.  The counters are split
-   into 4-tuples where the members of the tuple have meanings:
-
-   -- the last value of the measured entity
-   -- the stored candidate on the most common difference
-   -- counter
-   -- total number of evaluations of the value  */
+ * difference between two consecutive evaluations of the value.  It is
+ * given an array COUNTERS of N_COUNTERS old counters and it reads the
+ * same number of counters from the gcov file.  The counters are split
+ * into 4-tuples where the members of the tuple have meanings:
+ *
+ * -- the last value of the measured entity
+ * -- the stored candidate on the most common difference
+ * -- counter
+ * -- total number of evaluations of the value
+ */
 void
 __gcov_merge_delta (gcov_type *counters, unsigned n_counters)
 {