[compiler-rt] [compiler-rt][profile] Use `flock` shim on Windows even if detection fails (PR #112695)

Yuta Saito via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 04:45:50 PDT 2024


https://github.com/kateinoigakukun created https://github.com/llvm/llvm-project/pull/112695

This is a follow-up fix for d4efc3e097f40afbe8ae275150f49bb08fc04572, which introduced CMake-time feature test for `flock`. The feature test always fails on Windows, but we still need to use the `flock` shim provided by WindowsMMap.h regardless of the feature test result.

>From 6f68229e992eca24078c793b1de2b14f0384df91 Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun at gmail.com>
Date: Thu, 17 Oct 2024 11:36:43 +0000
Subject: [PATCH] [compiler-rt][profile] Use `flock` shim on Windows even if
 detection fails

This is a follow-up fix for d4efc3e097f40afbe8ae275150f49bb08fc04572, which
introduced CMake-time feature test for `flock`. The feature test always
fails on Windows, but we still need to use the `flock` shim provided by
WindowsMMap.h regardless of the feature test result.
---
 compiler-rt/lib/profile/InstrProfilingUtil.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c
index 95ec4080ba2504..c637b9d0b893cd 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -152,7 +152,8 @@ COMPILER_RT_VISIBILITY int lprofLockFd(int fd) {
     }
   }
   return 0;
-#elif defined(COMPILER_RT_HAS_FLOCK)
+#elif defined(COMPILER_RT_HAS_FLOCK) || defined(_WIN32)
+  // Windows doesn't have flock but WindowsMMap.h provides a shim
   flock(fd, LOCK_EX);
   return 0;
 #else
@@ -179,7 +180,8 @@ COMPILER_RT_VISIBILITY int lprofUnlockFd(int fd) {
     }
   }
   return 0;
-#elif defined(COMPILER_RT_HAS_FLOCK)
+#elif defined(COMPILER_RT_HAS_FLOCK) || defined(_WIN32)
+  // Windows doesn't have flock but WindowsMMap.h provides a shim
   flock(fd, LOCK_UN);
   return 0;
 #else



More information about the llvm-commits mailing list