1 /* Header file for libgcov-*.c.
2 Copyright (C) 1996-2017 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
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
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/>. */
28 /* work around the poisoned malloc/calloc in system.h. */
30 #define xmalloc malloc
33 #define xcalloc calloc
37 /* About the target. */
38 /* This path will be used by libgcov runtime. */
42 #include "coretypes.h"
44 #include "libgcc_tm.h"
48 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (SI
)));
49 typedef unsigned gcov_position_t
__attribute__ ((mode (SI
)));
50 #if LONG_LONG_TYPE_SIZE > 32
51 typedef signed gcov_type
__attribute__ ((mode (DI
)));
52 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (DI
)));
54 typedef signed gcov_type
__attribute__ ((mode (SI
)));
55 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (SI
)));
58 #if __CHAR_BIT__ == 16
59 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (HI
)));
60 typedef unsigned gcov_position_t
__attribute__ ((mode (HI
)));
61 #if LONG_LONG_TYPE_SIZE > 32
62 typedef signed gcov_type
__attribute__ ((mode (SI
)));
63 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (SI
)));
65 typedef signed gcov_type
__attribute__ ((mode (HI
)));
66 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (HI
)));
69 typedef unsigned gcov_unsigned_t
__attribute__ ((mode (QI
)));
70 typedef unsigned gcov_position_t
__attribute__ ((mode (QI
)));
71 #if LONG_LONG_TYPE_SIZE > 32
72 typedef signed gcov_type
__attribute__ ((mode (HI
)));
73 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (HI
)));
75 typedef signed gcov_type
__attribute__ ((mode (QI
)));
76 typedef unsigned gcov_type_unsigned
__attribute__ ((mode (QI
)));
81 #if defined (TARGET_POSIX_IO)
87 /* In libgcov we need these functions to be extern, so prefix them with
88 __gcov. In libgcov they must also be hidden so that the instance in
89 the executable is not also used in a DSO. */
90 #define gcov_var __gcov_var
91 #define gcov_open __gcov_open
92 #define gcov_close __gcov_close
93 #define gcov_write_tag_length __gcov_write_tag_length
94 #define gcov_position __gcov_position
95 #define gcov_seek __gcov_seek
96 #define gcov_rewrite __gcov_rewrite
97 #define gcov_is_error __gcov_is_error
98 #define gcov_write_unsigned __gcov_write_unsigned
99 #define gcov_write_counter __gcov_write_counter
100 #define gcov_write_summary __gcov_write_summary
101 #define gcov_read_unsigned __gcov_read_unsigned
102 #define gcov_read_counter __gcov_read_counter
103 #define gcov_read_summary __gcov_read_summary
104 #define gcov_sort_n_vals __gcov_sort_n_vals
106 #else /* IN_GCOV_TOOL */
107 /* About the host. */
108 /* This path will be compiled for the host and linked into
113 #include "coretypes.h"
116 typedef unsigned gcov_unsigned_t
;
117 typedef unsigned gcov_position_t
;
118 /* gcov_type is typedef'd elsewhere for the compiler */
119 #if defined (HOST_HAS_F_SETLKW)
120 #define GCOV_LOCKED 1
122 #define GCOV_LOCKED 0
125 /* Some Macros specific to gcov-tool. */
128 #define L_gcov_merge_add 1
129 #define L_gcov_merge_single 1
130 #define L_gcov_merge_ior 1
131 #define L_gcov_merge_time_profile 1
132 #define L_gcov_merge_icall_topn 1
134 extern gcov_type
gcov_read_counter_mem ();
135 extern unsigned gcov_get_merge_weight ();
136 extern struct gcov_info
*gcov_list
;
138 #endif /* !IN_GCOV_TOOL */
140 #if defined(inhibit_libc)
141 #define IN_LIBGCOV (-1)
145 #define GCOV_LINKAGE /* nothing */
149 /* Poison these, so they don't accidentally slip in. */
150 #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
151 #pragma GCC poison gcov_time gcov_magic
153 #ifdef HAVE_GAS_HIDDEN
154 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
156 #define ATTRIBUTE_HIDDEN
161 /* Structures embedded in coveraged program. The structures generated
162 by write_profile must match these. */
164 /* Information about counters for a single function. */
167 gcov_unsigned_t num
; /* number of counters. */
168 gcov_type
*values
; /* their values. */
171 /* Information about a single function. This uses the trailing array
172 idiom. The number of counters is determined from the merge pointer
173 array in gcov_info. The key is used to detect which of a set of
174 comdat functions was selected -- it points to the gcov_info object
175 of the object file containing the selected comdat function. */
179 const struct gcov_info
*key
; /* comdat key */
180 gcov_unsigned_t ident
; /* unique ident of function */
181 gcov_unsigned_t lineno_checksum
; /* function lineo_checksum */
182 gcov_unsigned_t cfg_checksum
; /* function cfg checksum */
183 struct gcov_ctr_info ctrs
[1]; /* instrumented counters */
186 /* Type of function used to merge counters. */
187 typedef void (*gcov_merge_fn
) (gcov_type
*, gcov_unsigned_t
);
189 /* Information about a single object file. */
192 gcov_unsigned_t version
; /* expected version number */
193 struct gcov_info
*next
; /* link to next, used by libgcov */
195 gcov_unsigned_t stamp
; /* uniquifying time stamp */
196 const char *filename
; /* output file name */
198 gcov_merge_fn merge
[GCOV_COUNTERS
]; /* merge functions (null for
201 unsigned n_functions
; /* number of functions */
204 const struct gcov_fn_info
*const *functions
; /* pointer to pointers
205 to function information */
207 const struct gcov_fn_info
**functions
;
208 #endif /* !IN_GCOV_TOOL */
211 /* Root of a program/shared-object state */
214 struct gcov_info
*list
;
215 unsigned dumped
: 1; /* counts have been dumped. */
216 unsigned run_counted
: 1; /* run has been accounted for. */
217 struct gcov_root
*next
;
218 struct gcov_root
*prev
;
221 extern struct gcov_root __gcov_root ATTRIBUTE_HIDDEN
;
225 gcov_unsigned_t version
;
226 struct gcov_root
*root
;
229 /* Exactly one of these will be active in the process. */
230 extern struct gcov_master __gcov_master
;
232 /* Dump a set of gcov objects. */
233 extern void __gcov_dump_one (struct gcov_root
*) ATTRIBUTE_HIDDEN
;
235 /* Register a new object file module. */
236 extern void __gcov_init (struct gcov_info
*) ATTRIBUTE_HIDDEN
;
238 /* GCOV exit function registered via a static destructor. */
239 extern void __gcov_exit (void) ATTRIBUTE_HIDDEN
;
241 /* Function to reset all counters to 0. Both externally visible (and
242 overridable) and internal version. */
243 extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN
;
245 /* User function to enable early write of profile information so far. */
246 extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN
;
248 /* The merge function that just sums the counters. */
249 extern void __gcov_merge_add (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
251 /* The merge function to select the minimum valid counter value. */
252 extern void __gcov_merge_time_profile (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
254 /* The merge function to choose the most common value. */
255 extern void __gcov_merge_single (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
257 /* The merge function that just ors the counters together. */
258 extern void __gcov_merge_ior (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
260 /* The merge function is used for topn indirect call counters. */
261 extern void __gcov_merge_icall_topn (gcov_type
*, unsigned) ATTRIBUTE_HIDDEN
;
263 /* The profiler functions. */
264 extern void __gcov_interval_profiler (gcov_type
*, gcov_type
, int, unsigned);
265 extern void __gcov_interval_profiler_atomic (gcov_type
*, gcov_type
, int,
267 extern void __gcov_pow2_profiler (gcov_type
*, gcov_type
);
268 extern void __gcov_pow2_profiler_atomic (gcov_type
*, gcov_type
);
269 extern void __gcov_one_value_profiler (gcov_type
*, gcov_type
);
270 extern void __gcov_one_value_profiler_atomic (gcov_type
*, gcov_type
);
271 extern void __gcov_indirect_call_profiler_v2 (gcov_type
, void *);
272 extern void __gcov_time_profiler (gcov_type
*);
273 extern void __gcov_time_profiler_atomic (gcov_type
*);
274 extern void __gcov_average_profiler (gcov_type
*, gcov_type
);
275 extern void __gcov_average_profiler_atomic (gcov_type
*, gcov_type
);
276 extern void __gcov_ior_profiler (gcov_type
*, gcov_type
);
277 extern void __gcov_ior_profiler_atomic (gcov_type
*, gcov_type
);
278 extern void __gcov_indirect_call_topn_profiler (gcov_type
, void *);
279 extern void gcov_sort_n_vals (gcov_type
*, int);
282 /* The wrappers around some library functions.. */
283 extern pid_t
__gcov_fork (void) ATTRIBUTE_HIDDEN
;
284 extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
285 extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
286 extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN
;
287 extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN
;
288 extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN
;
289 extern int __gcov_execve (const char *, char *const [], char *const [])
292 /* Functions that only available in libgcov. */
293 GCOV_LINKAGE
int gcov_open (const char */
*name*/
) ATTRIBUTE_HIDDEN
;
294 GCOV_LINKAGE
void gcov_write_counter (gcov_type
) ATTRIBUTE_HIDDEN
;
295 GCOV_LINKAGE
void gcov_write_tag_length (gcov_unsigned_t
, gcov_unsigned_t
)
297 GCOV_LINKAGE
void gcov_write_summary (gcov_unsigned_t
/*tag*/,
298 const struct gcov_summary
*)
300 GCOV_LINKAGE
void gcov_seek (gcov_position_t
/*position*/) ATTRIBUTE_HIDDEN
;
301 GCOV_LINKAGE
void gcov_rewrite (void) ATTRIBUTE_HIDDEN
;
303 /* "Counts" stored in gcda files can be a real counter value, or
304 an target address. When differentiate these two types because
305 when manipulating counts, we should only change real counter values,
306 rather target addresses. */
308 static inline gcov_type
309 gcov_get_counter (void)
312 /* This version is for reading count values in libgcov runtime:
313 we read from gcda files. */
315 return gcov_read_counter ();
317 /* This version is for gcov-tool. We read the value from memory and
318 multiply it by the merge weight. */
320 return gcov_read_counter_mem () * gcov_get_merge_weight ();
324 /* Similar function as gcov_get_counter(), but handles target address
327 static inline gcov_type
328 gcov_get_counter_target (void)
331 /* This version is for reading count target values in libgcov runtime:
332 we read from gcda files. */
334 return gcov_read_counter ();
336 /* This version is for gcov-tool. We read the value from memory and we do NOT
337 multiply it by the merge weight. */
339 return gcov_read_counter_mem ();
343 #endif /* !inhibit_libc */
345 #endif /* GCC_LIBGCOV_H */