From 9ec469f504f4bc4c3cdfa4a3f9e164c26e4881af Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 29 Apr 2021 14:03:09 +0200 Subject: Add parallelism support to gcov for MinGW platforms If you attempt a profiled bootstrap on the MinGW platforms with -jN, N > 1, it miserably fails because of profile mismatches all over the place, the reason being that gcov has no support for parallelism on these platforms. libgcc/ * libgcov.h: For the target, define GCOV_LOCKED_WITH_LOCKING if __MSVCRT__ and, for the host, define it if HOST_HAS_LK_LOCK. * libgcov-driver.c: Add directives if GCOV_LOCKED_WITH_LOCKING. gcc/ * configure.ac: Check for the presence of sys/locking.h header and for whether _LK_LOCK is supported by _locking. * configure: Regenerate. * config.in: Likewise. * gcov-io.h: Define GCOV_LOCKED_WITH_LOCKING if HOST_HAS_LK_LOCK. * gcov-io.c (gcov_open): Add support for GCOV_LOCKED_WITH_LOCKING. * system.h: Include if HAVE_SYS_LOCKING_H. --- gcc/gcov-io.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index 75f16a2..c9958f4 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -202,6 +202,12 @@ typedef uint64_t gcov_type_unsigned; #define GCOV_LOCKED 0 #endif +#if defined (HOST_HAS_LK_LOCK) +#define GCOV_LOCKED_WITH_LOCKING 1 +#else +#define GCOV_LOCKED_WITH_LOCKING 0 +#endif + #define ATTRIBUTE_HIDDEN #endif /* !IN_LIBGCOV */ -- cgit v1.1 From e3a682f4197f9f39808febfd1862e722d7675d34 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 20 Apr 2021 16:56:07 +0200 Subject: Use genversion to generate version.h. c++tools/ChangeLog: * Makefile.in: Include also ../gcc folder. gcc/ChangeLog: * Makefile.in: Rename gcov-iov to genversion and depend on version.h (instead of gcov-iov.h). * gcov-io.h: Include version.h instread of gcov-iov.h. * gengtype-state.c (read_state_version): Likewise. * gcov-iov.c: Moved to... * genversion.c: ...here. * lto-streamer.h (LTO_major_version): Define it with GCC_major_version. * version.c: Removed. * version.h: Removed. libgcc/ChangeLog: * libgcov-driver.c (gcov_version): Use different name that does not clash with newly introduced macro. --- gcc/gcov-io.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index c9958f4..c536554 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -231,11 +231,7 @@ typedef uint64_t gcov_type_unsigned; #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */ #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */ -/* gcov-iov.h is automatically generated by the makefile from - version.c, it looks like - #define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef) -*/ -#include "gcov-iov.h" +#include "version.h" /* Convert a magic or version number to a 4 character string. */ #define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \ -- cgit v1.1 From 23eb66d1d46a34cb28c4acbdf8a1deb80a7c5a05 Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 18 Nov 2020 16:13:23 +0100 Subject: gcov: Use system IO buffering gcc/ChangeLog: * gcov-io.c (gcov_write_block): Remove. (gcov_write_words): Likewise. (gcov_read_words): Re-implement using gcov_read_bytes. (gcov_allocate): Remove. (GCOV_BLOCK_SIZE): Likewise. (struct gcov_var): Remove most of the fields. (gcov_position): Implement with ftell. (gcov_rewrite): Remove setting of start and offset fields. (from_file): Re-format. (gcov_open): Remove setbuf call. It should not be needed. (gcov_close): Remove internal buffer handling. (gcov_magic): Use __builtin_bswap32. (gcov_write_counter): Use directly gcov_write_unsigned. (gcov_write_string): Use direct fwrite and do not round to 4 bytes. (gcov_seek): Use directly fseek. (gcov_write_tag): Use gcov_write_unsigned directly. (gcov_write_length): Likewise. (gcov_write_tag_length): Likewise. (gcov_read_bytes): Use directly fread. (gcov_read_unsigned): Use gcov_read_words. (gcov_read_counter): Likewise. (gcov_read_string): Use gcov_read_bytes. * gcov-io.h (GCOV_WORD_SIZE): Adjust to reflect that size is not in bytes, but words (4B). (GCOV_TAG_FUNCTION_LENGTH): Likewise. (GCOV_TAG_ARCS_LENGTH): Likewise. (GCOV_TAG_ARCS_NUM): Likewise. (GCOV_TAG_COUNTER_LENGTH): Likewise. (GCOV_TAG_COUNTER_NUM): Likewise. (GCOV_TAG_SUMMARY_LENGTH): Likewise. libgcc/ChangeLog: * libgcov-driver.c: Fix GNU coding style. --- gcc/gcov-io.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index c536554..f7584eb 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -243,22 +243,25 @@ typedef uint64_t gcov_type_unsigned; /* The record tags. Values [1..3f] are for tags which may be in either file. Values [41..9f] for those in the note file and [a1..ff] for the data file. The tag value zero is used as an explicit end of - file marker -- it is not required to be present. */ + file marker -- it is not required to be present. + All length values are in bytes. */ + +#define GCOV_WORD_SIZE 4 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000) -#define GCOV_TAG_FUNCTION_LENGTH (3) +#define GCOV_TAG_FUNCTION_LENGTH (3 * GCOV_WORD_SIZE) #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000) #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM) #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000) -#define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2) -#define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2) +#define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2 * GCOV_WORD_SIZE) +#define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH / GCOV_WORD_SIZE) - 1) / 2) #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000) #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000) -#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) -#define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2) +#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2 * GCOV_WORD_SIZE) +#define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH / GCOV_WORD_SIZE) / 2) #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) #define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000) /* Obsolete */ -#define GCOV_TAG_SUMMARY_LENGTH (2) +#define GCOV_TAG_SUMMARY_LENGTH (2 * GCOV_WORD_SIZE) #define GCOV_TAG_AFDO_FILE_NAMES ((gcov_unsigned_t)0xaa000000) #define GCOV_TAG_AFDO_FUNCTION ((gcov_unsigned_t)0xac000000) #define GCOV_TAG_AFDO_WORKING_SET ((gcov_unsigned_t)0xaf000000) -- cgit v1.1 From c0954059dba9b369439bcb77643655e42f9a181e Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 17 Jun 2021 11:39:11 +0200 Subject: gcov: update documentation entry about string format gcc/ChangeLog: * gcov-io.h: Update documentation entry about string format. --- gcc/gcov-io.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index f7584eb..ff92afe 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -42,15 +42,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see Numbers are recorded in the 32 bit unsigned binary form of the endianness of the machine generating the file. 64 bit numbers are - stored as two 32 bit numbers, the low part first. Strings are - padded with 1 to 4 NUL bytes, to bring the length up to a multiple - of 4. The number of 4 bytes is stored, followed by the padded + stored as two 32 bit numbers, the low part first. + The number of bytes is stored, followed by the string. Zero length and NULL strings are simply stored as a length of zero (they have no trailing NUL or padding). int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3 int64: int32:low int32:high - string: int32:0 | int32:length char* char:0 padding + string: int32:0 | int32:length char* char:0 padding: | char:0 | char:0 char:0 | char:0 char:0 char:0 item: int32 | int64 | string -- cgit v1.1 From 6871b899b831b4cb36a24033557c835e53c0b07f Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 22 Jun 2021 08:43:41 +0200 Subject: gcov: update comment about padding gcc/ChangeLog: * gcov-io.h: Remove padding entries. --- gcc/gcov-io.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index ff92afe..538bee8 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -45,12 +45,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see stored as two 32 bit numbers, the low part first. The number of bytes is stored, followed by the string. Zero length and NULL strings are simply stored as a length - of zero (they have no trailing NUL or padding). + of zero (they have no trailing NUL). int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3 int64: int32:low int32:high string: int32:0 | int32:length char* char:0 - padding: | char:0 | char:0 char:0 | char:0 char:0 char:0 item: int32 | int64 | string The basic format of the notes file is -- cgit v1.1 From 9124bbe1857f0d3a3015d6461d5f8d04f07cab85 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sat, 14 Nov 2020 13:51:09 +0100 Subject: gcov: Add __gcov_info_to_gdca() Add __gcov_info_to_gcda() to libgcov to get the gcda data for a gcda info in a freestanding environment. It is intended to be used with the -fprofile-info-section option. A crude test program which doesn't use a linker script is (use "gcc -coverage -fprofile-info-section -lgcov test.c" to compile it): #include #include #include extern const struct gcov_info *my_info; static void filename (const char *f, void *arg) { printf("filename: %s\n", f); } static void dump (const void *d, unsigned n, void *arg) { const unsigned char *c = d; for (unsigned i = 0; i < n; ++i) printf ("%02x", c[i]); } static void * allocate (unsigned length, void *arg) { return malloc (length); } int main() { __asm__ volatile (".set my_info, .LPBX2"); __gcov_info_to_gcda (my_info, filename, dump, allocate, NULL); return 0; } With this patch, is included in libgcov-driver.c even if inhibit_libc is defined. This header file should be also available for freestanding environments. If this is not the case, then we have to define intptr_t somehow. The patch removes one use of memset() which makes the include superfluous. gcc/ * gcov-io.h (gcov_write): Declare. * gcov-io.c (gcov_write): New. (gcov_write_counter): Remove. (gcov_write_tag_length): Likewise. (gcov_write_summary): Replace gcov_write_tag_length() with calls to gcov_write_unsigned(). * doc/invoke.texi (fprofile-info-section): Mention __gcov_info_to_gdca(). gcc/testsuite/ * gcc.dg/gcov-info-to-gcda.c: New test. libgcc/ * Makefile.in (LIBGCOV_DRIVER): Add _gcov_info_to_gcda. * gcov.h (gcov_info): Declare. (__gcov_info_to_gdca): Likewise. * libgcov.h (gcov_write_counter): Remove. (gcov_write_tag_length): Likewise. * libgcov-driver.c (#include ): New. (#include ): Remove. (NEED_L_GCOV): Conditionally define. (NEED_L_GCOV_INFO_TO_GCDA): Likewise. (are_all_counters_zero): New. (gcov_dump_handler): Likewise. (gcov_allocate_handler): Likewise. (dump_unsigned): Likewise. (dump_counter): Likewise. (write_topn_counters): Add dump_fn, allocate_fn, and arg parameters. Use dump_unsigned() and dump_counter(). (write_one_data): Add dump_fn, allocate_fn, and arg parameters. Use dump_unsigned(), dump_counter(), and are_all_counters_zero(). (__gcov_info_to_gcda): New. --- gcc/gcov-io.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/gcov-io.h') diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index 538bee8..99e1964 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -367,6 +367,7 @@ char *mangle_path (char const *base); #if !IN_GCOV /* Available outside gcov */ +GCOV_LINKAGE void gcov_write (const void *, unsigned) ATTRIBUTE_HIDDEN; GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN; #endif -- cgit v1.1