From 499befab3136ec5c3a2e984d46ace5afe15c1f7b Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 4 Aug 2014 01:43:37 +0000 Subject: [PATCH] MemoryBuffer: Don't use mmap when FileSize is multiple of 4k on Cygwin. On Cygwin, getpagesize() returns 64k(AllocationGranularity). In r214580, the size of X86GenInstrInfo.inc became 1499136. FIXME: We should reorganize again getPageSize() on Win32. MapFile allocates address along AllocationGranularity but view is mapped by physical page. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214681 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/MemoryBuffer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 5f4b7daae53..522c365f3d5 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -305,6 +305,14 @@ static bool shouldUseMmap(int FD, if ((FileSize & (PageSize -1)) == 0) return false; +#if defined(__CYGWIN__) + // Don't try to map files that are exactly a multiple of the physical page size + // if we need a null terminator. + // FIXME: We should reorganize again getPageSize() on Win32. + if ((FileSize & (4096 - 1)) == 0) + return false; +#endif + return true; }