[flang-commits] [flang] 3299647 - [flang] Avoid dependency of runtime library on pthread for MinGW
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Apr 25 10:16:55 PDT 2023
Author: Markus Mützel
Date: 2023-04-25T10:12:41-07:00
New Revision: 329964769972ef3c8a68f2dfea30e66beb4ae3e2
URL: https://github.com/llvm/llvm-project/commit/329964769972ef3c8a68f2dfea30e66beb4ae3e2
DIFF: https://github.com/llvm/llvm-project/commit/329964769972ef3c8a68f2dfea30e66beb4ae3e2.diff
LOG: [flang] Avoid dependency of runtime library on pthread for MinGW
When building the Fortran runtime on MinGW, `clock_gettime` is currently used. That function is provided by the `pthread` library on that platform. That means that all programs that link `libFortranRuntime` also require to be linked with `pthread` on that platform.
There is already a code path (for MSVC) that doesn't use `clock_gettime` in the implementation of the Fortran library.
Use the same code path also on MinGW by undefining `CLOCKID`.
Reviewed By: vzakhari
Differential Revision: https://reviews.llvm.org/D149051
Added:
Modified:
flang/runtime/time-intrinsic.cpp
Removed:
################################################################################
diff --git a/flang/runtime/time-intrinsic.cpp b/flang/runtime/time-intrinsic.cpp
index 5f7b50964fe2..68d63253139f 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -56,7 +56,12 @@ template <typename Unused = void> double GetCpuTime(fallback_implementation) {
return -1.0;
}
-#if defined CLOCK_PROCESS_CPUTIME_ID
+#if defined __MINGW32__
+// clock_gettime is implemented in the pthread library for MinGW.
+// Using it here would mean that all programs that link libFortranRuntime are
+// required to also link to pthread. Instead, don't use the function.
+#undef CLOCKID
+#elif defined CLOCK_PROCESS_CPUTIME_ID
#define CLOCKID CLOCK_PROCESS_CPUTIME_ID
#elif defined CLOCK_THREAD_CPUTIME_ID
#define CLOCKID CLOCK_THREAD_CPUTIME_ID
More information about the flang-commits
mailing list