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);