Index: include/llvm/Support/MemoryBuffer.h =================================================================== --- include/llvm/Support/MemoryBuffer.h +++ include/llvm/Support/MemoryBuffer.h @@ -132,6 +132,8 @@ getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile = false); + static void enableMemoryMapping(bool enable); + //===--------------------------------------------------------------------===// // Provided for performance analysis. //===--------------------------------------------------------------------===// Index: lib/Support/MemoryBuffer.cpp =================================================================== --- lib/Support/MemoryBuffer.cpp +++ lib/Support/MemoryBuffer.cpp @@ -39,6 +39,12 @@ // MemoryBuffer implementation itself. //===----------------------------------------------------------------------===// +static bool MemoryMappingEnabled = true; + +void MemoryBuffer::enableMemoryMapping(bool enable) { + MemoryMappingEnabled = enable; +} + MemoryBuffer::~MemoryBuffer() { } /// init - Initialize this MemoryBuffer as a reference to externally allocated @@ -312,6 +318,9 @@ bool RequiresNullTerminator, int PageSize, bool IsVolatile) { + if (!MemoryMappingEnabled) + return false; + // mmap may leave the buffer without null terminator if the file size changed // by the time the last page is mapped in, so avoid it if the file size is // likely to change.