diff options
author | Dan Gohman <gohman@apple.com> | 2010-03-27 16:49:51 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-03-27 16:49:51 +0000 |
commit | ec9e342d04a3a05c334a9a44148b2837741dbd8f (patch) | |
tree | 5869b4efdefe7ff185973d4eba5d09047e55c482 /llvm/tools/llvm-ld/llvm-ld.cpp | |
parent | 8c172a51d8105abc2f506cf7d96639b8e0077d1d (diff) | |
download | bcm5719-llvm-ec9e342d04a3a05c334a9a44148b2837741dbd8f.tar.gz bcm5719-llvm-ec9e342d04a3a05c334a9a44148b2837741dbd8f.zip |
Make llvm-ld remove its output files in the event of an error.
llvm-svn: 99719
Diffstat (limited to 'llvm/tools/llvm-ld/llvm-ld.cpp')
-rw-r--r-- | llvm/tools/llvm-ld/llvm-ld.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/llvm/tools/llvm-ld/llvm-ld.cpp b/llvm/tools/llvm-ld/llvm-ld.cpp index 9956e23ddd8..4749fea4480 100644 --- a/llvm/tools/llvm-ld/llvm-ld.cpp +++ b/llvm/tools/llvm-ld/llvm-ld.cpp @@ -30,6 +30,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" @@ -124,6 +125,10 @@ static cl::opt<std::string> CO9("m", cl::Hidden, /// everywhere. static std::string progname; +/// FileRemover objects to clean up output files in the event of an error. +static FileRemover OutputRemover; +static FileRemover BitcodeOutputRemover; + /// PrintAndExit - Prints a message to standard error and exits with error code /// /// Inputs: @@ -236,10 +241,6 @@ void GenerateBitcode(Module* M, const std::string& FileName) { if (!ErrorInfo.empty()) PrintAndExit(ErrorInfo, M); - // Ensure that the bitcode file gets removed from the disk if we get a - // terminating signal. - sys::RemoveFileOnSignal(sys::Path(FileName)); - // Write it out WriteBitcodeToFile(M, Out); } @@ -582,8 +583,17 @@ int main(int argc, char **argv, char **envp) { if (!LinkAsLibrary) BitcodeOutputFilename += ".bc"; } + // Arrange for the bitcode output file to be deleted on any errors. + BitcodeOutputRemover = FileRemover(sys::Path(BitcodeOutputFilename)); + sys::RemoveFileOnSignal(sys::Path(BitcodeOutputFilename)); + + // Generate the bitcode output. GenerateBitcode(Composite.get(), BitcodeOutputFilename); + // Arrange for the output file to be deleted on any errors. + OutputRemover = FileRemover(sys::Path(OutputFilename)); + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + // If we are not linking a library, generate either a native executable // or a JIT shell script, depending upon what the user wants. if (!LinkAsLibrary) { @@ -636,7 +646,6 @@ int main(int argc, char **argv, char **envp) { // Mark the output files for removal if we get an interrupt. sys::RemoveFileOnSignal(AssemblyFile); - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); // Determine the locations of the llc and gcc programs. sys::Path llc = FindExecutable("llc", argv[0], @@ -666,7 +675,6 @@ int main(int argc, char **argv, char **envp) { // Mark the output files for removal if we get an interrupt. sys::RemoveFileOnSignal(CFile); - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); // Determine the locations of the llc and gcc programs. sys::Path llc = FindExecutable("llc", argv[0], @@ -707,6 +715,10 @@ int main(int argc, char **argv, char **envp) { PrintAndExit(ErrMsg, Composite.get()); } + // Operations which may fail are now complete. + OutputRemover.releaseFile(); + BitcodeOutputRemover.releaseFile(); + // Graceful exit return 0; } |