[lld] r301422 - Move code to emit error messages from Filesystem.cpp to Driver.cpp.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 09:14:47 PDT 2017
Author: ruiu
Date: Wed Apr 26 11:14:46 2017
New Revision: 301422
URL: http://llvm.org/viewvc/llvm-project?rev=301422&view=rev
Log:
Move code to emit error messages from Filesystem.cpp to Driver.cpp.
isFileWritable() checked if a file is writable and then emitted
an error message if it is not writable. So it did more than the
name says. This patch moves error() calls to Driver.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Filesystem.cpp
lld/trunk/ELF/Filesystem.h
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=301422&r1=301421&r2=301422&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Apr 26 11:14:46 2017
@@ -912,9 +912,11 @@ template <class ELFT> void LinkerDriver:
// Fail early if the output file or map file is not writable. If a user has a
// long link, e.g. due to a large LTO link, they do not wish to run it and
// find that it failed because there was a mistake in their command-line.
- if (!isFileWritable(Config->OutputFile, "output file"))
- return;
- if (!isFileWritable(Config->MapFile, "map file"))
+ if (auto E = tryCreateFile(Config->OutputFile))
+ error("cannot open output file " + Config->OutputFile + ": " + E.message());
+ if (auto E = tryCreateFile(Config->MapFile))
+ error("cannot open map file " + Config->MapFile + ": " + E.message());
+ if (ErrorCount)
return;
// Use default entry point name if no name was given via the command
Modified: lld/trunk/ELF/Filesystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Filesystem.cpp?rev=301422&r1=301421&r2=301422&view=diff
==============================================================================
--- lld/trunk/ELF/Filesystem.cpp (original)
+++ lld/trunk/ELF/Filesystem.cpp Wed Apr 26 11:14:46 2017
@@ -13,7 +13,6 @@
#include "Filesystem.h"
#include "Config.h"
-#include "Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileOutputBuffer.h"
#include <thread>
@@ -58,22 +57,18 @@ void elf::unlinkAsync(StringRef Path) {
std::thread([=] { ::remove(TempPath.str().str().c_str()); }).detach();
}
-// Returns true if a given file seems to be writable.
+// Simulate file creation to see if Path is writable.
//
// Determining whether a file is writable or not is amazingly hard,
// and after all the only reliable way of doing that is to actually
// create a file. But we don't want to do that in this function
// because LLD shouldn't update any file if it will end in a failure.
-// We also don't want to reimplement heuristics. So we'll let
-// FileOutputBuffer do the work.
+// We also don't want to reimplement heuristics to determine if a
+// file is writable. So we'll let FileOutputBuffer do the work.
//
// FileOutputBuffer doesn't touch a desitnation file until commit()
// is called. We use that class without calling commit() to predict
// if the given file is writable.
-bool elf::isFileWritable(StringRef Path, StringRef Desc) {
- if (auto EC = FileOutputBuffer::create(Path, 1).getError()) {
- error("cannot open " + Desc + " " + Path + ": " + EC.message());
- return false;
- }
- return true;
+std::error_code elf::tryCreateFile(StringRef Path) {
+ return FileOutputBuffer::create(Path, 1).getError();
}
Modified: lld/trunk/ELF/Filesystem.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Filesystem.h?rev=301422&r1=301421&r2=301422&view=diff
==============================================================================
--- lld/trunk/ELF/Filesystem.h (original)
+++ lld/trunk/ELF/Filesystem.h Wed Apr 26 11:14:46 2017
@@ -15,7 +15,7 @@
namespace lld {
namespace elf {
void unlinkAsync(StringRef Path);
-bool isFileWritable(StringRef Path, StringRef FileDescription);
+std::error_code tryCreateFile(StringRef Path);
}
}
More information about the llvm-commits
mailing list