summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/profile
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2019-11-27 15:47:44 +0100
committerHans Wennborg <hans@chromium.org>2019-11-27 15:55:13 +0100
commit900d8a9a3b4efeefddd310e92219741d98e7270b (patch)
tree605b3709edb47424836ce178bd6ddcf91a42c730 /compiler-rt/lib/profile
parent0f4383faa75fdeaeebe0c5156f927e9f88d61d53 (diff)
downloadbcm5719-llvm-900d8a9a3b4efeefddd310e92219741d98e7270b.tar.gz
bcm5719-llvm-900d8a9a3b4efeefddd310e92219741d98e7270b.zip
[profile] Fix file contention causing dropped counts on Windows under -fprofile-generate
See PR43425: https://bugs.llvm.org/show_bug.cgi?id=43425 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. To fix this, I changed to open without exclusive access and then take a lock. Patch by Michael Holman! Differential revision: https://reviews.llvm.org/D70330
Diffstat (limited to 'compiler-rt/lib/profile')
-rw-r--r--compiler-rt/lib/profile/InstrProfilingUtil.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c
index 13301f341fc..bf5a9670fe1 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -207,8 +207,9 @@ COMPILER_RT_VISIBILITY FILE *lprofOpenFileEx(const char *ProfileName) {
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 @@ COMPILER_RT_VISIBILITY FILE *lprofOpenFileEx(const char *ProfileName) {
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);
OpenPOWER on IntegriCloud