Skip to content

Commit

Permalink
[flang] Avoid dependency of runtime library on pthread for MinGW
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mmuetzel authored and vzakhari committed Apr 25, 2023
1 parent 71f862b commit 3299647
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion flang/runtime/time-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3299647

Please sign in to comment.