[lld] r318060 - Try harder to delete the temporary file.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 10:06:43 PST 2017


Author: rafael
Date: Mon Nov 13 10:06:43 2017
New Revision: 318060

URL: http://llvm.org/viewvc/llvm-project?rev=318060&view=rev
Log:
Try harder to delete the temporary file.

It is really hard to cover restarts in a debugger, SIGKILL or power
failures. I will try to handle them in a followup patch, but it will
not support all the systems lld has to run on.

RemoveFileOnSignal takes care of crashes.

So what is left is making sure all regular exits delete the file. This
patch does that by moving the buffer to error handling. That is a bit
of a hack, but seemed better than to generalize it to take a callback on
construction.

I will implement this on COFF on the next patch.

Modified:
    lld/trunk/Common/ErrorHandler.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/include/lld/Common/ErrorHandler.h

Modified: lld/trunk/Common/ErrorHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/ErrorHandler.cpp?rev=318060&r1=318059&r2=318060&view=diff
==============================================================================
--- lld/trunk/Common/ErrorHandler.cpp (original)
+++ lld/trunk/Common/ErrorHandler.cpp Mon Nov 13 10:06:43 2017
@@ -46,6 +46,9 @@ ErrorHandler &lld::errorHandler() {
 }
 
 void lld::exitLld(int Val) {
+  // Delete the output buffer so that any tempory file is deleted.
+  errorHandler().OutputBuffer.reset();
+
   // Dealloc/destroy ManagedStatic variables before calling
   // _exit(). In a non-LTO build, this is a nop. In an LTO
   // build allows us to get the output of -time-passes.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=318060&r1=318059&r2=318060&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Nov 13 10:06:43 2017
@@ -22,7 +22,6 @@
 #include "lld/Common/Threads.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/FileOutputBuffer.h"
 #include <climits>
 
 using namespace llvm;
@@ -38,6 +37,7 @@ namespace {
 // The writer writes a SymbolTable result to a file.
 template <class ELFT> class Writer {
 public:
+  Writer() : Buffer(errorHandler().OutputBuffer) {}
   typedef typename ELFT::Shdr Elf_Shdr;
   typedef typename ELFT::Ehdr Elf_Ehdr;
   typedef typename ELFT::Phdr Elf_Phdr;
@@ -70,7 +70,7 @@ private:
   void writeSectionsBinary();
   void writeBuildId();
 
-  std::unique_ptr<FileOutputBuffer> Buffer;
+  std::unique_ptr<FileOutputBuffer> &Buffer;
 
   void addRelIpltSymbols();
   void addStartEndSymbols();

Modified: lld/trunk/include/lld/Common/ErrorHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/ErrorHandler.h?rev=318060&r1=318059&r2=318060&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/ErrorHandler.h (original)
+++ lld/trunk/include/lld/Common/ErrorHandler.h Mon Nov 13 10:06:43 2017
@@ -31,6 +31,7 @@
 #include "lld/Common/LLVM.h"
 
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileOutputBuffer.h"
 
 namespace lld {
 
@@ -52,6 +53,8 @@ public:
   void message(const Twine &Msg);
   void warn(const Twine &Msg);
 
+  std::unique_ptr<llvm::FileOutputBuffer> OutputBuffer;
+
 private:
   void print(StringRef S, raw_ostream::Colors C);
 };




More information about the llvm-commits mailing list