]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/libgcov.h
[Ada] Spurious accessibility error on return aggregate in GNATprove mode
[thirdparty/gcc.git] / libgcc / libgcov.h
CommitLineData
40d6b753 1/* Header file for libgcov-*.c.
8d9254fc 2 Copyright (C) 1996-2020 Free Software Foundation, Inc.
40d6b753
RX
3
4 This file is part of GCC.
5
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.
10
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.
15
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.
19
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/>. */
24
25#ifndef GCC_LIBGCOV_H
26#define GCC_LIBGCOV_H
27
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
c77556a5
RX
36#ifndef IN_GCOV_TOOL
37/* About the target. */
38/* This path will be used by libgcov runtime. */
39
40d6b753 40#include "tconfig.h"
a51a76e5 41#include "auto-target.h"
40d6b753
RX
42#include "tsystem.h"
43#include "coretypes.h"
44#include "tm.h"
45#include "libgcc_tm.h"
46928a8f 46#include "gcov.h"
40d6b753 47
a153644f 48#if __CHAR_BIT__ == 8
40d6b753
RX
49typedef unsigned gcov_unsigned_t __attribute__ ((mode (SI)));
50typedef unsigned gcov_position_t __attribute__ ((mode (SI)));
51#if LONG_LONG_TYPE_SIZE > 32
52typedef signed gcov_type __attribute__ ((mode (DI)));
53typedef unsigned gcov_type_unsigned __attribute__ ((mode (DI)));
54#else
55typedef signed gcov_type __attribute__ ((mode (SI)));
56typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
57#endif
58#else
a153644f 59#if __CHAR_BIT__ == 16
40d6b753
RX
60typedef unsigned gcov_unsigned_t __attribute__ ((mode (HI)));
61typedef unsigned gcov_position_t __attribute__ ((mode (HI)));
62#if LONG_LONG_TYPE_SIZE > 32
63typedef signed gcov_type __attribute__ ((mode (SI)));
64typedef unsigned gcov_type_unsigned __attribute__ ((mode (SI)));
65#else
66typedef signed gcov_type __attribute__ ((mode (HI)));
67typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
68#endif
69#else
70typedef unsigned gcov_unsigned_t __attribute__ ((mode (QI)));
71typedef unsigned gcov_position_t __attribute__ ((mode (QI)));
72#if LONG_LONG_TYPE_SIZE > 32
73typedef signed gcov_type __attribute__ ((mode (HI)));
74typedef unsigned gcov_type_unsigned __attribute__ ((mode (HI)));
75#else
76typedef signed gcov_type __attribute__ ((mode (QI)));
77typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI)));
78#endif
79#endif
80#endif
81
82#if defined (TARGET_POSIX_IO)
83#define GCOV_LOCKED 1
84#else
85#define GCOV_LOCKED 0
86#endif
87
19926161
NS
88/* In libgcov we need these functions to be extern, so prefix them with
89 __gcov. In libgcov they must also be hidden so that the instance in
90 the executable is not also used in a DSO. */
91#define gcov_var __gcov_var
92#define gcov_open __gcov_open
93#define gcov_close __gcov_close
94#define gcov_write_tag_length __gcov_write_tag_length
95#define gcov_position __gcov_position
96#define gcov_seek __gcov_seek
97#define gcov_rewrite __gcov_rewrite
98#define gcov_is_error __gcov_is_error
99#define gcov_write_unsigned __gcov_write_unsigned
100#define gcov_write_counter __gcov_write_counter
101#define gcov_write_summary __gcov_write_summary
102#define gcov_read_unsigned __gcov_read_unsigned
103#define gcov_read_counter __gcov_read_counter
104#define gcov_read_summary __gcov_read_summary
19926161 105
c77556a5
RX
106#else /* IN_GCOV_TOOL */
107/* About the host. */
108/* This path will be compiled for the host and linked into
109 gcov-tool binary. */
110
111#include "config.h"
112#include "system.h"
113#include "coretypes.h"
114#include "tm.h"
115
116typedef unsigned gcov_unsigned_t;
117typedef 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
121#else
122#define GCOV_LOCKED 0
123#endif
124
125/* Some Macros specific to gcov-tool. */
126
127#define L_gcov 1
128#define L_gcov_merge_add 1
596341c7 129#define L_gcov_merge_topn 1
c77556a5
RX
130#define L_gcov_merge_ior 1
131#define L_gcov_merge_time_profile 1
132
c77556a5
RX
133extern gcov_type gcov_read_counter_mem ();
134extern unsigned gcov_get_merge_weight ();
d10ee722 135extern struct gcov_info *gcov_list;
c77556a5
RX
136
137#endif /* !IN_GCOV_TOOL */
138
40d6b753
RX
139#if defined(inhibit_libc)
140#define IN_LIBGCOV (-1)
141#else
142#define IN_LIBGCOV 1
143#if defined(L_gcov)
144#define GCOV_LINKAGE /* nothing */
145#endif
146#endif
147
40d6b753
RX
148/* Poison these, so they don't accidentally slip in. */
149#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
17d1594b 150#pragma GCC poison gcov_time
40d6b753
RX
151
152#ifdef HAVE_GAS_HIDDEN
153#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
154#else
155#define ATTRIBUTE_HIDDEN
156#endif
157
158#include "gcov-io.h"
159
160/* Structures embedded in coveraged program. The structures generated
161 by write_profile must match these. */
162
163/* Information about counters for a single function. */
164struct gcov_ctr_info
165{
166 gcov_unsigned_t num; /* number of counters. */
167 gcov_type *values; /* their values. */
168};
169
170/* Information about a single function. This uses the trailing array
171 idiom. The number of counters is determined from the merge pointer
172 array in gcov_info. The key is used to detect which of a set of
173 comdat functions was selected -- it points to the gcov_info object
174 of the object file containing the selected comdat function. */
175
176struct gcov_fn_info
177{
178 const struct gcov_info *key; /* comdat key */
179 gcov_unsigned_t ident; /* unique ident of function */
180 gcov_unsigned_t lineno_checksum; /* function lineo_checksum */
181 gcov_unsigned_t cfg_checksum; /* function cfg checksum */
72602c6c 182 struct gcov_ctr_info ctrs[1]; /* instrumented counters */
40d6b753
RX
183};
184
185/* Type of function used to merge counters. */
186typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t);
187
188/* Information about a single object file. */
189struct gcov_info
190{
191 gcov_unsigned_t version; /* expected version number */
192 struct gcov_info *next; /* link to next, used by libgcov */
193
194 gcov_unsigned_t stamp; /* uniquifying time stamp */
195 const char *filename; /* output file name */
196
197 gcov_merge_fn merge[GCOV_COUNTERS]; /* merge functions (null for
198 unused) */
199
200 unsigned n_functions; /* number of functions */
c77556a5
RX
201
202#ifndef IN_GCOV_TOOL
40d6b753 203 const struct gcov_fn_info *const *functions; /* pointer to pointers
c77556a5
RX
204 to function information */
205#else
206 const struct gcov_fn_info **functions;
207#endif /* !IN_GCOV_TOOL */
40d6b753
RX
208};
209
4303c581
NS
210/* Root of a program/shared-object state */
211struct gcov_root
212{
213 struct gcov_info *list;
214 unsigned dumped : 1; /* counts have been dumped. */
215 unsigned run_counted : 1; /* run has been accounted for. */
cadb2b96
NS
216 struct gcov_root *next;
217 struct gcov_root *prev;
4303c581
NS
218};
219
220extern struct gcov_root __gcov_root ATTRIBUTE_HIDDEN;
221
cadb2b96
NS
222struct gcov_master
223{
224 gcov_unsigned_t version;
225 struct gcov_root *root;
226};
3edbcdbe
ML
227
228struct indirect_call_tuple
229{
230 /* Callee function. */
231 void *callee;
232
233 /* Pointer to counters. */
234 gcov_type *counters;
235};
cadb2b96
NS
236
237/* Exactly one of these will be active in the process. */
238extern struct gcov_master __gcov_master;
239
4303c581
NS
240/* Dump a set of gcov objects. */
241extern void __gcov_dump_one (struct gcov_root *) ATTRIBUTE_HIDDEN;
242
40d6b753
RX
243/* Register a new object file module. */
244extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN;
245
8c9434c2
ML
246/* GCOV exit function registered via a static destructor. */
247extern void __gcov_exit (void) ATTRIBUTE_HIDDEN;
248
b20ee094
NS
249/* Function to reset all counters to 0. Both externally visible (and
250 overridable) and internal version. */
b20ee094 251extern void __gcov_reset_int (void) ATTRIBUTE_HIDDEN;
40d6b753 252
cadb2b96 253/* User function to enable early write of profile information so far. */
cadb2b96 254extern void __gcov_dump_int (void) ATTRIBUTE_HIDDEN;
40d6b753 255
d39f7dc8
ML
256/* Lock critical section for __gcov_dump and __gcov_reset functions. */
257extern void __gcov_lock (void) ATTRIBUTE_HIDDEN;
258
259/* Unlock critical section for __gcov_dump and __gcov_reset functions. */
260extern void __gcov_unlock (void) ATTRIBUTE_HIDDEN;
261
40d6b753
RX
262/* The merge function that just sums the counters. */
263extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
264
265/* The merge function to select the minimum valid counter value. */
266extern void __gcov_merge_time_profile (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
267
596341c7
ML
268/* The merge function to choose the most common N values. */
269extern void __gcov_merge_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
40d6b753 270
40d6b753
RX
271/* The merge function that just ors the counters together. */
272extern void __gcov_merge_ior (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
273
274/* The profiler functions. */
275extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
a266236e
ML
276extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int,
277 unsigned);
40d6b753 278extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
a266236e 279extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type);
596341c7
ML
280extern void __gcov_topn_values_profiler (gcov_type *, gcov_type);
281extern void __gcov_topn_values_profiler_atomic (gcov_type *, gcov_type);
92d41717 282extern void __gcov_indirect_call_profiler_v4 (gcov_type, void *);
3ae37f92 283extern void __gcov_indirect_call_profiler_v4_atomic (gcov_type, void *);
40d6b753 284extern void __gcov_time_profiler (gcov_type *);
a266236e 285extern void __gcov_time_profiler_atomic (gcov_type *);
40d6b753 286extern void __gcov_average_profiler (gcov_type *, gcov_type);
a266236e 287extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type);
40d6b753 288extern void __gcov_ior_profiler (gcov_type *, gcov_type);
a266236e 289extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type);
40d6b753
RX
290
291#ifndef inhibit_libc
292/* The wrappers around some library functions.. */
293extern pid_t __gcov_fork (void) ATTRIBUTE_HIDDEN;
294extern int __gcov_execl (const char *, char *, ...) ATTRIBUTE_HIDDEN;
295extern int __gcov_execlp (const char *, char *, ...) ATTRIBUTE_HIDDEN;
296extern int __gcov_execle (const char *, char *, ...) ATTRIBUTE_HIDDEN;
297extern int __gcov_execv (const char *, char *const []) ATTRIBUTE_HIDDEN;
298extern int __gcov_execvp (const char *, char *const []) ATTRIBUTE_HIDDEN;
299extern int __gcov_execve (const char *, char *const [], char *const [])
300 ATTRIBUTE_HIDDEN;
301
302/* Functions that only available in libgcov. */
303GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
304GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN;
305GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t)
306 ATTRIBUTE_HIDDEN;
307GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
308 const struct gcov_summary *)
309 ATTRIBUTE_HIDDEN;
310GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/) ATTRIBUTE_HIDDEN;
19926161 311GCOV_LINKAGE void gcov_rewrite (void) ATTRIBUTE_HIDDEN;
40d6b753 312
c77556a5
RX
313/* "Counts" stored in gcda files can be a real counter value, or
314 an target address. When differentiate these two types because
315 when manipulating counts, we should only change real counter values,
316 rather target addresses. */
317
318static inline gcov_type
319gcov_get_counter (void)
320{
321#ifndef IN_GCOV_TOOL
322 /* This version is for reading count values in libgcov runtime:
323 we read from gcda files. */
324
325 return gcov_read_counter ();
326#else
327 /* This version is for gcov-tool. We read the value from memory and
328 multiply it by the merge weight. */
329
330 return gcov_read_counter_mem () * gcov_get_merge_weight ();
331#endif
332}
333
92d41717
ML
334/* Similar function as gcov_get_counter(), but do not scale
335 when read value is equal to IGNORE_SCALING. */
336
337static inline gcov_type
54e2d83c 338gcov_get_counter_ignore_scaling (gcov_type ignore_scaling ATTRIBUTE_UNUSED)
92d41717
ML
339{
340#ifndef IN_GCOV_TOOL
341 /* This version is for reading count values in libgcov runtime:
342 we read from gcda files. */
343
344 return gcov_read_counter ();
345#else
346 /* This version is for gcov-tool. We read the value from memory and
347 multiply it by the merge weight. */
348
349 gcov_type v = gcov_read_counter_mem ();
350 if (v != ignore_scaling)
351 v *= gcov_get_merge_weight ();
352
353 return v;
354#endif
355}
356
c77556a5
RX
357/* Similar function as gcov_get_counter(), but handles target address
358 counters. */
359
360static inline gcov_type
361gcov_get_counter_target (void)
362{
363#ifndef IN_GCOV_TOOL
364 /* This version is for reading count target values in libgcov runtime:
365 we read from gcda files. */
366
367 return gcov_read_counter ();
368#else
369 /* This version is for gcov-tool. We read the value from memory and we do NOT
370 multiply it by the merge weight. */
371
372 return gcov_read_counter_mem ();
373#endif
374}
375
40d6b753
RX
376#endif /* !inhibit_libc */
377
378#endif /* GCC_LIBGCOV_H */