[PATCH] D56475: Don't require a null terminator when loading objects

Mike Hommey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 21:38:00 PST 2019


glandium created this revision.
Herald added subscribers: llvm-commits, JDevlieghere, kristof.beyls, javed.absar, aprantl.

Requiring one doesn't cause harm in most cases, but when things align perfectly, things can go really bad.

Imagine you have a browser, built with ASAN. It uses multiple processes. It has intentional leaks, with suppressions. You run it, exit it. Each child process exits. Each with leaks, that need symbolication to match against the suppressions. So each runs llvm-symbolizer. At the same time.

Some of the addresses to symbolicate are in a shared library. That shared library contains all DWARF info, so it's rather large (close to a 1GB). Oh, and because all stars were aligned, its size is exactly a multiple of the page size. So shouldUseMmap in MemoryBuffer returns false for it. So llvm-symbolizer pread() the file instead. All instances of it. Did I say there are multiple processes? So suddenly you have n processes simultaneously allocating and filling 1GB of memory each, on CI machines that have enough memory for the job they usually run, but not enough for a sudden rush of n GB.

And things go awry. When you're lucky and the OOM killer didn't take care of killing the CI entirely, symbolication couldn't happen and the suppressions are not matched, and leaks are reported.


Repository:
  rL LLVM

https://reviews.llvm.org/D56475

Files:
  lib/Object/Binary.cpp


Index: lib/Object/Binary.cpp
===================================================================
--- lib/Object/Binary.cpp
+++ lib/Object/Binary.cpp
@@ -88,7 +88,8 @@
 
 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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56475.180789.patch
Type: text/x-patch
Size: 611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190109/95709a7e/attachment.bin>


More information about the llvm-commits mailing list