From 30ba0a0c950a0cdf23a70fce6c16d501c5f238c8 Mon Sep 17 00:00:00 2001 From: David Major Date: Wed, 9 Jan 2019 23:36:32 +0000 Subject: [PATCH] Don't require a null terminator when loading objects When a null terminator is required and the file size is a multiple of the system page size, MemoryBuffer will prefer pread() over mmap(), which can result in excessive memory usage. Patch by Mike Hommey! Differential Revision: https://reviews.llvm.org/D56475 llvm-svn: 350774 --- llvm/lib/Object/Binary.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp index d7c2592..fe41987 100644 --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -88,7 +88,8 @@ Expected> object::createBinary(MemoryBufferRef Buffer, Expected> object::createBinary(StringRef Path) { ErrorOr> FileOrErr = - MemoryBuffer::getFileOrSTDIN(Path); + MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, + /*RequiresNullTerminator=*/false); if (std::error_code EC = FileOrErr.getError()) return errorCodeToError(EC); std::unique_ptr &Buffer = FileOrErr.get(); -- 2.7.4