[PATCH] D48051: LTO: Work around a Windows kernel bug by keeping file handles open for memory mapped files.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 11 13:36:50 PDT 2018


pcc created this revision.
pcc added reviewers: zturner, rnk.
Herald added subscribers: steven_wu, hiraditya, mehdi_amini.

The Windows kernel appears to have a bug where if you open a file,
write to it, map it into memory and close the file handle, the
contents of the memory mapping can sometimes be incorrect. That
was what we did when adding an entry to the ThinLTO cache using the
TempFile and MemoryBuffer classes, and it was causing intermittent
build failures on Chromium's ThinLTO bots on Windows. More details
are in the associated Chromium bug (crbug.com/786127).

A viable workaround for the bug seems to be to keep a handle to the
file open while the mapping is active. So this patch changes the
mapped_file_region class to duplicate the file handle when mapping
the file and close it upon unmapping it.

One gotcha is that the file handle that we keep open must not have
been created with FILE_FLAG_DELETE_ON_CLOSE, as otherwise the operating
system will prevent other processes from opening the file. We currently
create such a file handle in TempFile::keep() as part of the process of
clearing the file's delete-on-close bit, but then we immediately close
it again. So this patch splits keep() into two functions:

- keep() reopens the file
- close() closes the file handle

That allows us to move the call to MemoryBuffer::getOpenFile()
between the calls to keep() and close().


https://reviews.llvm.org/D48051

Files:
  llvm/include/llvm/Support/FileSystem.h
  llvm/lib/LTO/Caching.cpp
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/lib/Support/FileOutputBuffer.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/tools/bugpoint/BugDriver.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48051.150831.patch
Type: text/x-patch
Size: 10723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180611/749918f2/attachment.bin>


More information about the llvm-commits mailing list