[PATCH] D28107: [ELF] - Do not create huge garbage files on section offset overflow.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 25 07:52:48 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
Herald added a subscriber: fhahn.

This can be reproduced easily on 32bit configuration with using testcase from https://reviews.llvm.org/D27712.
I believe there are other ways to achieve the same effect. Like having corrupted huge
sections sizes which we do not handle too.

But at last this is what we can fix easily as at the moment of issue ErrorCount > 0 already.

Issue is next:
FileSize is 0xfffffffffffff210 because of address/offsets calculation overflow.
And we trigger "unable to move location counter backward for: .text" in that case.

It works with a remark. FileSize it then passed as size_t and under win32 configuration truncates to 4gb,
that results in a creating temp 4gb files named "locationcountererr.s.tmp1.tmpXXXX" or alike,
that is a SSD space eater on each testcase run:

  ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
      FileOutputBuffer::create(Config->OutputFile, FileSize,
                               FileOutputBuffer::F_executable);

I suggest to add a simple check not only after openFile, but also before.


https://reviews.llvm.org/D28107

Files:
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -214,6 +214,8 @@
     fixAbsoluteSymbols();
   }
 
+  if (ErrorCount)
+    return;
   // Write the result down to a file.
   openFile();
   if (ErrorCount)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28107.82475.patch
Type: text/x-patch
Size: 287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161225/5139e69a/attachment.bin>


More information about the llvm-commits mailing list