aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcov-io.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2021-04-29 14:03:09 +0200
committerEric Botcazou <ebotcazou@adacore.com>2021-04-29 16:02:17 +0200
commit9ec469f504f4bc4c3cdfa4a3f9e164c26e4881af (patch)
tree97e4d0e08706a85c153da52ec785c7c1fb7523e0 /gcc/gcov-io.c
parentd03ca8a6148f55e119b8220a9c65147173b32065 (diff)
downloadgcc-9ec469f504f4bc4c3cdfa4a3f9e164c26e4881af.zip
gcc-9ec469f504f4bc4c3cdfa4a3f9e164c26e4881af.tar.gz
gcc-9ec469f504f4bc4c3cdfa4a3f9e164c26e4881af.tar.bz2
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 <sys/locking.h> if HAVE_SYS_LOCKING_H.
Diffstat (limited to 'gcc/gcov-io.c')
-rw-r--r--gcc/gcov-io.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c
index 80c9082..21ca394 100644
--- a/gcc/gcov-io.c
+++ b/gcc/gcov-io.c
@@ -137,6 +137,8 @@ gcov_open (const char *name, int mode)
s_flock.l_start = 0;
s_flock.l_len = 0; /* Until EOF. */
s_flock.l_pid = getpid ();
+#elif GCOV_LOCKED_WITH_LOCKING
+ int fd;
#endif
gcov_nonruntime_assert (!gcov_var.file);
@@ -175,6 +177,34 @@ gcov_open (const char *name, int mode)
close (fd);
return 0;
}
+#elif GCOV_LOCKED_WITH_LOCKING
+ if (mode > 0)
+ {
+ /* pass mode (ignored) for compatibility */
+ fd = open (name, O_RDONLY | O_BINARY, S_IRUSR | S_IWUSR);
+ }
+ else
+ {
+ /* Truncate if force new mode. */
+ fd = open (name, O_RDWR | O_BINARY | O_CREAT | (mode < 0 ? O_TRUNC : 0),
+ 0666);
+ }
+ if (fd < 0)
+ return 0;
+
+ if (_locking (fd, _LK_LOCK, LONG_MAX) < 0)
+ {
+ close (fd);
+ return 0;
+ }
+
+ gcov_var.file = fdopen (fd, (mode > 0) ? "rb" : "r+b");
+
+ if (!gcov_var.file)
+ {
+ close (fd);
+ return 0;
+ }
#else
if (mode >= 0)
/* Open an existing file. */