Implement __gcov_dump_all for shared libs
[official-gcc.git] / gcc-4_9 / libgcc / libgcov.h
blobfdfb6502e9c7a4580b6383f1652af4f4678b0ce6
1 /* Header file for libgcov-*.c.
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #ifndef GCC_LIBGCOV_H
26 #define GCC_LIBGCOV_H
28 /* work around the poisoned malloc/calloc in system.h. */
29 #ifndef xmalloc
30 #define xmalloc malloc
31 #endif
32 #ifndef xcalloc
33 #define xcalloc calloc
34 #endif
35 #ifndef xrealloc
36 #define xrealloc realloc
37 #endif
39 #ifndef IN_GCOV_TOOL
40 /* About the target. */
41 /* This path will be used by libgcov runtime. */
43 #include "tconfig.h"
44 #include "tsystem.h"
45 #include "coretypes.h"
46 #include "tm.h"
47 #include "libgcc_tm.h"
49 #undef FUNC_ID_WIDTH
50 #undef FUNC_ID_MASK
52 #if BITS_PER_UNIT == 8
53 typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI)));
54 typedef unsigned gcov_position_t __attribute__ ((mode (SI)));
55 #if LONG_LONG_TYPE_SIZE > 32
56 typedef signed gcov_type __attribute__ ((mode (DI)));
57 typedef unsigned gcov_type_unsigned __attribute__ ((mode (DI)));
58 #define FUNC_ID_WIDTH 32
59 #define FUNC_ID_MASK ((1ll << FUNC_ID_WIDTH) - 1)
60 #else
61 typedef signed gcov_type __attribute__ ((mode (SI)));
62 typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
63 #define FUNC_ID_WIDTH 16
64 #define FUNC_ID_MASK ((1 << FUNC_ID_WIDTH) - 1)
65 #endif
66 #else /* BITS_PER_UNIT != 8 */
67 #if BITS_PER_UNIT == 16
68 typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI)));
69 typedef unsigned gcov_position_t __attribute__ ((mode (HI)));
70 #if LONG_LONG_TYPE_SIZE > 32
71 typedef signed gcov_type __attribute__ ((mode (SI)));
72 typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
73 #define FUNC_ID_WIDTH 32
74 #define FUNC_ID_MASK ((1ll << FUNC_ID_WIDTH) - 1)
75 #else
76 typedef signed gcov_type __attribute__ ((mode (HI)));
77 typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
78 #define FUNC_ID_WIDTH 16
79 #define FUNC_ID_MASK ((1 << FUNC_ID_WIDTH) - 1)
80 #endif
81 #else /* BITS_PER_UNIT != 16 */
82 typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI)));
83 typedef unsigned gcov_position_t __attribute__ ((mode (QI)));
84 #if LONG_LONG_TYPE_SIZE > 32
85 typedef signed gcov_type __attribute__ ((mode (HI)));
86 typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
87 #define FUNC_ID_WIDTH 32
88 #define FUNC_ID_MASK ((1ll << FUNC_ID_WIDTH) - 1)
89 #else
90 typedef signed gcov_type __attribute__ ((mode (QI)));
91 typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI)));
92 #define FUNC_ID_WIDTH 16
93 #define FUNC_ID_MASK ((1 << FUNC_ID_WIDTH) - 1)
94 #endif
95 #endif /* BITS_PER_UNIT == 16 */
96 #endif /* BITS_PER_UNIT == 8 */
98 #if LONG_LONG_TYPE_SIZE > 32
99 #define GCOV_TYPE_ATOMIC_FETCH_ADD_FN __atomic_fetch_add_8
100 #define GCOV_TYPE_ATOMIC_FETCH_ADD BUILT_IN_ATOMIC_FETCH_ADD_8
101 #else
102 #define GCOV_TYPE_ATOMIC_FETCH_ADD_FN __atomic_fetch_add_4
103 #define GCOV_TYPE_ATOMIC_FETCH_ADD BUILT_IN_ATOMIC_FETCH_ADD_4
104 #endif
106 #if defined (TARGET_POSIX_IO)
107 #define GCOV_LOCKED 1
108 #else
109 #define GCOV_LOCKED 0
110 #endif
112 #else /* IN_GCOV_TOOL */
113 /* About the host. */
114 /* This path will be compiled for the host and linked into
115 gcov-tool binary. */
117 #include "config.h"
118 #include "system.h"
119 #include "coretypes.h"
120 #include "tm.h"
122 typedef unsigned gcov_unsigned_t;
123 typedef unsigned gcov_position_t;
124 /* gcov_type is typedef'd elsewhere for the compiler */
125 #if defined (HOST_HAS_F_SETLKW)
126 #define GCOV_LOCKED 1
127 #else
128 #define GCOV_LOCKED 0
129 #endif
131 /* xur??? */
132 #define FUNC_ID_WIDTH 32
133 #define FUNC_ID_MASK ((1ll << FUNC_ID_WIDTH) - 1)
135 /* Some Macros specific to gcov-tool. */
137 #define L_gcov 1
138 #define L_gcov_merge_add 1
139 #define L_gcov_merge_single 1
140 #define L_gcov_merge_delta 1
141 #define L_gcov_merge_ior 1
142 #define L_gcov_merge_time_profile 1
143 #define L_gcov_merge_icall_topn 1
144 #define L_gcov_merge_dc 1
146 /* Make certian internal functions/variables in libgcov available for
147 gcov-tool access. */
148 #define GCOV_TOOL_LINKAGE
150 extern gcov_type gcov_read_counter_mem ();
151 extern unsigned gcov_get_merge_weight ();
153 #endif /* !IN_GCOV_TOOL */
155 #undef EXTRACT_MODULE_ID_FROM_GLOBAL_ID
156 #undef EXTRACT_FUNC_ID_FROM_GLOBAL_ID
157 #undef GEN_FUNC_GLOBAL_ID
158 #define EXTRACT_MODULE_ID_FROM_GLOBAL_ID(gid) \
159 (gcov_unsigned_t)(((gid) >> FUNC_ID_WIDTH) & FUNC_ID_MASK)
160 #define EXTRACT_FUNC_ID_FROM_GLOBAL_ID(gid) \
161 (gcov_unsigned_t)((gid) & FUNC_ID_MASK)
162 #define GEN_FUNC_GLOBAL_ID(m,f) ((((gcov_type) (m)) << FUNC_ID_WIDTH) | (f))
164 #if defined(inhibit_libc)
165 #define IN_LIBGCOV (-1)
166 #else
167 #define IN_LIBGCOV 1
168 #if defined(L_gcov)
169 #define GCOV_LINKAGE /* nothing */
170 #endif
171 #endif
173 /* In libgcov we need these functions to be extern, so prefix them with
174 __gcov. In libgcov they must also be hidden so that the instance in
175 the executable is not also used in a DSO. */
176 #define gcov_var __gcov_var
177 #define gcov_open __gcov_open
178 #define gcov_close __gcov_close
179 #define gcov_write_tag_length __gcov_write_tag_length
180 #define gcov_position __gcov_position
181 #define gcov_seek __gcov_seek
182 #define gcov_rewrite __gcov_rewrite
183 #define gcov_truncate __gcov_truncate
184 #define gcov_is_error __gcov_is_error
185 #define gcov_write_unsigned __gcov_write_unsigned
186 #define gcov_write_counter __gcov_write_counter
187 #define gcov_write_summary __gcov_write_summary
188 #define gcov_write_module_info __gcov_write_module_info
189 #define gcov_read_unsigned __gcov_read_unsigned
190 #define gcov_read_counter __gcov_read_counter
191 #define gcov_read_summary __gcov_read_summary
192 #define gcov_read_module_info __gcov_read_module_info
193 #define gcov_sort_n_vals __gcov_sort_n_vals
195 /* Poison these, so they don't accidentally slip in. */
196 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
197 #pragma GCC poison gcov_time gcov_magic
199 #ifdef HAVE_GAS_HIDDEN
200 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
201 #else
202 #define ATTRIBUTE_HIDDEN
203 #endif
205 #include "gcov-io.h"
207 /* Structures embedded in coveraged program. The structures generated
208 by write_profile must match these. */
209 /* Information about counters for a single function. */
210 struct gcov_ctr_info
212 gcov_unsigned_t num; /* number of counters. */
213 gcov_type *values; /* their values. */
216 /* Information about a single function. This uses the trailing array
217 idiom. The number of counters is determined from the merge pointer
218 array in gcov_info. The key is used to detect which of a set of
219 comdat functions was selected -- it points to the gcov_info object
220 of the object file containing the selected comdat function. */
222 struct gcov_fn_info
224 const struct gcov_info *key; /* comdat key */
225 gcov_unsigned_t ident; /* unique ident of function */
226 gcov_unsigned_t lineno_checksum; /* function lineo_checksum */
227 gcov_unsigned_t cfg_checksum; /* function cfg checksum */
228 struct gcov_ctr_info ctrs[1]; /* instrumented counters */
231 /* Type of function used to merge counters. */
232 typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
234 /* Information about a single object file. */
235 struct gcov_info
237 gcov_unsigned_t version; /* expected version number */
238 struct gcov_module_info *mod_info; /* addtional module info. */
239 struct gcov_info *next; /* link to next, used by libgcov */
241 gcov_unsigned_t stamp; /* uniquifying time stamp */
242 const char *filename; /* output file name */
243 gcov_unsigned_t eof_pos; /* end position of profile data */
244 gcov_merge_fn merge[GCOV_COUNTERS]; /* merge functions (null for
245 unused) */
247 unsigned n_functions; /* number of functions */
249 #ifndef IN_GCOV_TOOL
250 const struct gcov_fn_info *const *functions; /* pointer to pointers
251 to function information */
252 #else
253 const struct gcov_fn_info **functions;
254 #endif /* !IN_GCOV_TOOL */
257 /* Information about a single imported module. */
258 struct dyn_imp_mod
260 const struct gcov_info *imp_mod;
261 double weight;
264 /* Register a new object file module. */
265 extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
267 /* Set sampling rate to RATE. */
268 extern void __gcov_set_sampling_rate (unsigned int rate);
270 /* Called before fork, to avoid double counting. */
271 extern void __gcov_flush (void) ATTRIBUTE_HIDDEN;
273 /* Function to reset all counters to 0. */
274 extern void __gcov_reset (void);
275 /* Function to enable early write of profile information so far.
276 __gcov_dump is also used by __gcov_dump_all. The latter
277 depends on __GCOV_DUMP to have hidden or protected visibility
278 so that each library has its own copy of the registered dumper. */
279 extern void __gcov_dump (void) ATTRIBUTE_HIDDEN;
281 /* Call __gcov_dump registered from each shared library.
282 This function must have default visibility. */
283 void __gcov_dump_all (void);
285 /* The merge function that just sums the counters. */
286 extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
288 /* The merge function to choose the most common value. */
289 extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
291 /* The merge function to choose the most common difference between
292 consecutive values. */
293 extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
295 /* The merge function that just ors the counters together. */
296 extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
298 /* The merge function used for direct call counters. */
299 extern void __gcov_merge_dc (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
301 /* The merge function used for indirect call counters. */
302 extern void __gcov_merge_icall_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
304 extern void __gcov_merge_time_profile (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
306 /* The profiler functions. */
307 extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
308 extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
309 extern void __gcov_one_value_profiler (gcov_type *, gcov_type);
310 extern void __gcov_indirect_call_profiler (gcov_type*, gcov_type,
311 void*, void*);
312 extern void __gcov_indirect_call_profiler_v2 (gcov_type, void *);
313 extern void __gcov_indirect_call_topn_profiler (void *, void *, gcov_unsigned_t) ATTRIBUTE_HIDDEN;
314 extern void __gcov_direct_call_profiler (void *, void *, gcov_unsigned_t) ATTRIBUTE_HIDDEN;
315 extern void __gcov_average_profiler (gcov_type *, gcov_type);
316 extern void __gcov_ior_profiler (gcov_type *, gcov_type);
317 extern void __gcov_sort_n_vals (gcov_type *value_array, int n);
318 extern void __gcov_time_profiler (gcov_type *);
320 #ifndef inhibit_libc
321 /* The wrappers around some library functions.. */
322 extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN;
323 extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN;
324 extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN;
325 extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN;
326 extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
327 extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
328 extern int __gcov_execve (const char *, char *const [], char *const [])
329 ATTRIBUTE_HIDDEN;
332 /* Functions that only available in libgcov. */
333 GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
334 GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
335 GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
336 ATTRIBUTE_HIDDEN;
337 GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
338 const struct gcov_summary *)
339 ATTRIBUTE_HIDDEN;
340 GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
341 GCOV_LINKAGE void gcov_truncate (void) ATTRIBUTE_HIDDEN;
342 GCOV_LINKAGE void gcov_write_module_infos (struct gcov_info *mod_info)
343 ATTRIBUTE_HIDDEN;
344 GCOV_LINKAGE const struct dyn_imp_mod **
345 gcov_get_sorted_import_module_array (struct gcov_info *mod_info, unsigned *len)
346 ATTRIBUTE_HIDDEN;
347 GCOV_LINKAGE inline void gcov_rewrite (void);
349 /* "Counts" stored in gcda files can be a real counter value, or
350 an target address. When differentiate these two types because
351 when manipulating counts, we should only change real counter values,
352 rather target addresses. */
354 static inline gcov_type
355 gcov_get_counter (void)
357 #ifndef IN_GCOV_TOOL
358 /* This version is for reading count values in libgcov runtime:
359 we read from gcda files. */
361 return gcov_read_counter ();
362 #else
363 /* This version is for gcov-tool. We read the value from memory and
364 multiply it by the merge weight. */
366 return gcov_read_counter_mem () * gcov_get_merge_weight ();
367 #endif
370 /* Similar function as gcov_get_counter(), but handles target address
371 counters. */
373 static inline gcov_type
374 gcov_get_counter_target (void)
376 #ifndef IN_GCOV_TOOL
377 /* This version is for reading count target values in libgcov runtime:
378 we read from gcda files. */
380 return gcov_read_counter ();
381 #else
382 /* This version is for gcov-tool. We read the value from memory and we do NOT
383 multiply it by the merge weight. */
385 return gcov_read_counter_mem ();
386 #endif
389 #endif /* !inhibit_libc */
391 #endif /* GCC_LIBGCOV_H */