From: David Major Date: Wed, 9 Jan 2019 23:36:32 +0000 (+0000) Subject: Don't require a null terminator when loading objects X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af085b4c8a2f0b36712e58b21aab75741c53c2bf;p=llvm 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350774 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index d7c25921ec3..fe41987f5c2 100644 --- a/lib/Object/Binary.cpp +++ b/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();