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.

llvm-svn: 318060
This commit is contained in:
Rafael Espindola 2017-11-13 18:06:43 +00:00
parent bd57b8bf3f
commit a4884cc38f
3 changed files with 8 additions and 2 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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);
};