[PATCH] D70330: [profile] Fix file contention causing dropped counts on Windows under -fprofile-generate
Michael Holman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 11:26:49 PST 2019
Holman created this revision.
Holman added reviewers: davidxl, hans.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.
When writing profile data on Windows we were opening profile file with exclusive read/write access.
In case we are trying to write to the file from multiple processes simultaneously, subsequent calls to `CreateFileA` would return INVALID_HANDLE_VALUE.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70330
Files:
compiler-rt/lib/profile/InstrProfilingUtil.c
Index: compiler-rt/lib/profile/InstrProfilingUtil.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingUtil.c
+++ compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -207,8 +207,9 @@
f = fdopen(fd, "r+b");
#elif defined(_WIN32)
// FIXME: Use the wide variants to handle Unicode filenames.
- HANDLE h = CreateFileA(ProfileName, GENERIC_READ | GENERIC_WRITE, 0, 0,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ HANDLE h = CreateFileA(ProfileName, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, 0);
if (h == INVALID_HANDLE_VALUE)
return NULL;
@@ -218,6 +219,10 @@
return NULL;
}
+ if (lprofLockFd(fd) != 0)
+ PROF_WARN("Data may be corrupted during profile merging : %s\n",
+ "Fail to obtain file lock due to system limit.");
+
f = _fdopen(fd, "r+b");
if (f == 0) {
CloseHandle(h);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70330.229424.patch
Type: text/x-patch
Size: 1023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191115/27624c30/attachment-0001.bin>
More information about the llvm-commits
mailing list