Skip to content

Commit

Permalink
Don't require a null terminator when loading objects
Browse files Browse the repository at this point in the history
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
  • Loading branch information
David Major committed Jan 9, 2019
1 parent f3a4770 commit 30ba0a0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/Object/Binary.cpp
Expand Up @@ -88,7 +88,8 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,

Expected<OwningBinary<Binary>> object::createBinary(StringRef Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Path);
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
/*RequiresNullTerminator=*/false);
if (std::error_code EC = FileOrErr.getError())
return errorCodeToError(EC);
std::unique_ptr<MemoryBuffer> &Buffer = FileOrErr.get();
Expand Down

0 comments on commit 30ba0a0

Please sign in to comment.