aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2019-02-21 17:05:19 +0000
committerJordan Rupprecht <rupprecht@google.com>2019-02-21 17:05:19 +0000
commitad29d29130a62f71bc0b00e8743f5fb6e1e41258 (patch)
tree5b4d99389cd313ff69493e4730a4e1aaabb2898b /llvm/tools/llvm-objcopy/llvm-objcopy.cpp
parent[WebAssembly] Don't create MSSymbolWasm object for non-symbols (diff)
downloadllvm-project-ad29d29130a62f71bc0b00e8743f5fb6e1e41258.tar.gz
llvm-project-ad29d29130a62f71bc0b00e8743f5fb6e1e41258.tar.bz2
llvm-project-ad29d29130a62f71bc0b00e8743f5fb6e1e41258.zip
[llvm-objcopy][NFC] More error cleanup
Summary: This removes calls to `error()`/`reportError()` in the main driver (llvm-objcopy.cpp) as well as the associated argv-parsing (CopyConfig.cpp). `logAllUnhandledErrors()` is now the main way to print errors. There are still a few uses from within the per-arch drivers, so we can't delete them yet... but almost! Reviewers: jhenderson, alexshap, espindola Reviewed By: jhenderson Subscribers: emaste, arichardson, jakehehrlich, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58316 llvm-svn: 354600
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp58
1 files changed, 37 insertions, 21 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index fdf1c305b61e..28d7ee2e2a9f 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -183,70 +183,86 @@ static Error executeObjcopyOnArchive(const CopyConfig &Config,
Config.DeterministicArchives, Ar.isThin());
}
-static void restoreDateOnFile(StringRef Filename,
- const sys::fs::file_status &Stat) {
+static Error restoreDateOnFile(StringRef Filename,
+ const sys::fs::file_status &Stat) {
int FD;
if (auto EC =
sys::fs::openFileForWrite(Filename, FD, sys::fs::CD_OpenExisting))
- reportError(Filename, EC);
+ return createFileError(Filename, EC);
if (auto EC = sys::fs::setLastAccessAndModificationTime(
FD, Stat.getLastAccessedTime(), Stat.getLastModificationTime()))
- reportError(Filename, EC);
+ return createFileError(Filename, EC);
if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD))
- reportError(Filename, EC);
+ return createFileError(Filename, EC);
+
+ return Error::success();
}
/// The function executeObjcopy does the higher level dispatch based on the type
/// of input (raw binary, archive or single object file) and takes care of the
/// format-agnostic modifications, i.e. preserving dates.
-static void executeObjcopy(const CopyConfig &Config) {
+static Error executeObjcopy(const CopyConfig &Config) {
sys::fs::file_status Stat;
if (Config.PreserveDates)
if (auto EC = sys::fs::status(Config.InputFilename, Stat))
- reportError(Config.InputFilename, EC);
+ return createFileError(Config.InputFilename, EC);
if (Config.InputFormat == "binary") {
auto BufOrErr = MemoryBuffer::getFile(Config.InputFilename);
if (!BufOrErr)
- reportError(Config.InputFilename, BufOrErr.getError());
+ return createFileError(Config.InputFilename, BufOrErr.getError());
FileBuffer FB(Config.OutputFilename);
if (Error E = executeObjcopyOnRawBinary(Config, *BufOrErr->get(), FB))
- error(std::move(E));
+ return E;
} else {
Expected<OwningBinary<llvm::object::Binary>> BinaryOrErr =
createBinary(Config.InputFilename);
if (!BinaryOrErr)
- reportError(Config.InputFilename, BinaryOrErr.takeError());
+ return createFileError(Config.InputFilename, BinaryOrErr.takeError());
if (Archive *Ar = dyn_cast<Archive>(BinaryOrErr.get().getBinary())) {
if (Error E = executeObjcopyOnArchive(Config, *Ar))
- error(std::move(E));
+ return E;
} else {
FileBuffer FB(Config.OutputFilename);
if (Error E = executeObjcopyOnBinary(Config,
*BinaryOrErr.get().getBinary(), FB))
- error(std::move(E));
+ return E;
}
}
if (Config.PreserveDates) {
- restoreDateOnFile(Config.OutputFilename, Stat);
+ if (Error E = restoreDateOnFile(Config.OutputFilename, Stat))
+ return E;
if (!Config.SplitDWO.empty())
- restoreDateOnFile(Config.SplitDWO, Stat);
+ if (Error E = restoreDateOnFile(Config.SplitDWO, Stat))
+ return E;
}
+
+ return Error::success();
}
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
ToolName = argv[0];
- DriverConfig DriverConfig;
- if (sys::path::stem(ToolName).contains("strip"))
- DriverConfig = parseStripOptions(makeArrayRef(argv + 1, argc));
- else
- DriverConfig = parseObjcopyOptions(makeArrayRef(argv + 1, argc));
- for (const CopyConfig &CopyConfig : DriverConfig.CopyConfigs)
- executeObjcopy(CopyConfig);
+ bool IsStrip = sys::path::stem(ToolName).contains("strip");
+ Expected<DriverConfig> DriverConfig =
+ IsStrip ? parseStripOptions(makeArrayRef(argv + 1, argc))
+ : parseObjcopyOptions(makeArrayRef(argv + 1, argc));
+ if (!DriverConfig) {
+ logAllUnhandledErrors(DriverConfig.takeError(),
+ WithColor::error(errs(), ToolName));
+ return 1;
+ }
+ for (const CopyConfig &CopyConfig : DriverConfig->CopyConfigs) {
+ if (Error E = executeObjcopy(CopyConfig)) {
+ logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
+ return 1;
+ }
+ }
+
+ return 0;
}