]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add parallelism support to gcov for MinGW platforms
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 29 Apr 2021 12:03:09 +0000 (14:03 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 29 Apr 2021 14:02:17 +0000 (16:02 +0200)
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.

gcc/config.in
gcc/configure
gcc/configure.ac
gcc/gcov-io.c
gcc/gcov-io.h
gcc/system.h
libgcc/libgcov-driver.c
libgcc/libgcov.h

index fb88acb3c34e67ccf0ebda560a3195a624a36397..e54f59ce0c35d4e208b653a0390df1aded8e5464 100644 (file)
 #endif
 
 
+/* Define to 1 if you have the <sys/locking.h> header file. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_SYS_LOCKING_H
+#endif
+
+
 /* Define to 1 if you have the <sys/mman.h> header file. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_SYS_MMAN_H
 #endif
 
 
+/* Define if _LK_LOC supported by _locking. */
+#ifndef USED_FOR_TARGET
+#undef HOST_HAS_LK_LOCK
+#endif
+
+
 /* Define if O_CLOEXEC supported by fcntl. */
 #ifndef USED_FOR_TARGET
 #undef HOST_HAS_O_CLOEXEC
index f5bef76ef7765d8461af1302ba2837966705e51e..d9c9cca9ebb23c05b8542eb1809e137e26abefc6 100755 (executable)
@@ -9075,7 +9075,7 @@ fi
 
 for ac_header in limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \
                 fcntl.h ftw.h unistd.h sys/file.h sys/time.h sys/mman.h \
-                sys/resource.h sys/param.h sys/times.h sys/stat.h \
+                sys/resource.h sys/param.h sys/times.h sys/stat.h sys/locking.h \
                 direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -12308,6 +12308,43 @@ $as_echo "#define HAVE_AF_INET6 1" >>confdefs.h
 
 fi
 
+# Check if _LK_LOCK is supported by _locking
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LK_LOCK" >&5
+$as_echo_n "checking for _LK_LOCK... " >&6; }
+if ${ac_cv_lk_lock+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <io.h>
+#include <sys/locking.h>
+int
+main ()
+{
+
+  int fd;
+  return _locking (fd, _LK_LOCK, 0);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_lk_lock=yes
+else
+  ac_cv_lk_lock=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lk_lock" >&5
+$as_echo "$ac_cv_lk_lock" >&6; }
+if test $ac_cv_lk_lock = yes; then
+
+$as_echo "#define HOST_HAS_LK_LOCK 1" >>confdefs.h
+
+fi
+
 # Restore CFLAGS, CXXFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
 CFLAGS="$saved_CFLAGS"
 CXXFLAGS="$saved_CXXFLAGS"
@@ -19398,7 +19435,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19401 "configure"
+#line 19438 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19504,7 +19541,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19507 "configure"
+#line 19544 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 22305e3707176c5056e1b0b1ab81827bc8485cb4..e9ba2af548a5c0891475ff851c79a8fa8ebf373f 100644 (file)
@@ -1257,7 +1257,7 @@ AC_HEADER_SYS_WAIT
 AC_HEADER_TIOCGWINSZ
 AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \
                 fcntl.h ftw.h unistd.h sys/file.h sys/time.h sys/mman.h \
-                sys/resource.h sys/param.h sys/times.h sys/stat.h \
+                sys/resource.h sys/param.h sys/times.h sys/stat.h sys/locking.h \
                 direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h)
 
 # Check for thread headers.
@@ -1711,6 +1711,19 @@ if test $ac_cv_af_inet6 = yes; then
   [Define if AF_INET6 supported.])
 fi
 
+# Check if _LK_LOCK is supported by _locking
+AC_CACHE_CHECK(for _LK_LOCK, ac_cv_lk_lock, [
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <io.h>
+#include <sys/locking.h>]], [[
+  int fd;
+  return _locking (fd, _LK_LOCK, 0);]])],
+[ac_cv_lk_lock=yes],[ac_cv_lk_lock=no])])
+if test $ac_cv_lk_lock = yes; then
+  AC_DEFINE(HOST_HAS_LK_LOCK, 1,
+  [Define if _LK_LOC supported by _locking.])
+fi
+
 # Restore CFLAGS, CXXFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
 CFLAGS="$saved_CFLAGS"
 CXXFLAGS="$saved_CXXFLAGS"
index 80c9082a64957f852ad08819c36c6a5e26f27dc2..21ca3949c41f714e48b8c07e6f4b858794236fe7 100644 (file)
@@ -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);
@@ -170,6 +172,34 @@ gcov_open (const char *name, int mode)
 
   gcov_var.file = fdopen (fd, (mode > 0) ? "rb" : "r+b");
 
+  if (!gcov_var.file)
+    {
+      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);
index 75f16a274c72835bd18ef5bb70e67eca62534935..c9958f450d33b9be9c2f5ae426e27c5311d9ebb2 100644 (file)
@@ -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 */
index a3f5948aaeec3b6c8350a57259113b022f06a16e..6416c4e033e927fb64a742516914d3aa70372390 100644 (file)
@@ -360,6 +360,10 @@ extern int errno;
 # endif
 #endif
 
+#ifdef HAVE_SYS_LOCKING_H
+# include <sys/locking.h>
+#endif
+
 #ifndef SEEK_SET
 # define SEEK_SET 0
 # define SEEK_CUR 1
index a1338b6e5255997e817a552718b02b6ebedc3a95..faa2df447152917511af35768fe438b6a2185ff3 100644 (file)
@@ -36,10 +36,15 @@ void __gcov_init (struct gcov_info *p __attribute__ ((unused))) {}
 #else /* inhibit_libc */
 
 #include <string.h>
+
 #if GCOV_LOCKED
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/stat.h>
+#elif GCOV_LOCKED_WITH_LOCKING
+#include <fcntl.h>
+#include <sys/locking.h>
+#include <sys/stat.h>
 #endif
 
 #if HAVE_SYS_MMAN_H
index 7b0d367ec52693dec4ea2a798635b3e32fa8f300..8d323db05386681b15cb75b3eaf610e161dc8659 100644 (file)
@@ -89,6 +89,12 @@ typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI)));
 #define GCOV_LOCKED 0
 #endif
 
+#if defined (__MSVCRT__)
+#define GCOV_LOCKED_WITH_LOCKING 1
+#else
+#define GCOV_LOCKED_WITH_LOCKING 0
+#endif
+
 #ifndef GCOV_SUPPORTS_ATOMIC
 /* Detect whether target can support atomic update of profilers.  */
 #if __SIZEOF_LONG_LONG__ == 4 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
@@ -133,12 +139,19 @@ typedef unsigned gcov_type_unsigned __attribute__ ((mode (QI)));
 typedef unsigned gcov_unsigned_t;
 typedef unsigned gcov_position_t;
 /* gcov_type is typedef'd elsewhere for the compiler */
+
 #if defined (HOST_HAS_F_SETLKW)
 #define GCOV_LOCKED 1
 #else
 #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
+
 /* Some Macros specific to gcov-tool.  */
 
 #define L_gcov 1