diff options
author | Petr Hosek <phosek@chromium.org> | 2017-07-20 00:13:32 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2017-07-20 00:13:32 +0000 |
commit | d00e47fd711239c6cd2ba5330cab8c075334d9e2 (patch) | |
tree | c267b1afafe97c489b19c8a4d01f992ad31bac5d /llvm/tools/llvm-objcopy/llvm-objcopy.cpp | |
parent | 6326639721963fb778f4f4371d85b1f7526832fe (diff) | |
download | bcm5719-llvm-d00e47fd711239c6cd2ba5330cab8c075334d9e2.tar.gz bcm5719-llvm-d00e47fd711239c6cd2ba5330cab8c075334d9e2.zip |
Revert "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
This reverts commit 98f9792e7ca5bbd9eb43bda72bf497957cfb6eb8.
llvm-svn: 308569
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp deleted file mode 100644 index 578d16584e8..00000000000 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ /dev/null @@ -1,99 +0,0 @@ -//===- llvm-objcopy.cpp -----------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#include "llvm-objcopy.h" -#include "Object.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/FileOutputBuffer.h" -#include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/Signals.h" -#include "llvm/Support/ToolOutputFile.h" - -#include <memory> -#include <string> -#include <system_error> - -using namespace llvm; -using namespace object; -using namespace ELF; - -// The name this program was invoked as. -static StringRef ToolName; - -namespace llvm { - -LLVM_ATTRIBUTE_NORETURN void error(Twine Message) { - errs() << ToolName << ": " << Message << ".\n"; - errs().flush(); - exit(1); -} - -LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) { - assert(EC); - errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n"; - exit(1); -} - -LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, llvm::Error E) { - assert(E); - std::string Buf; - raw_string_ostream OS(Buf); - logAllUnhandledErrors(std::move(E), OS, ""); - OS.flush(); - errs() << ToolName << ": '" << File << "': " << Buf; - exit(1); -} -} - -cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input>")); -cl::opt<std::string> OutputFilename(cl::Positional, cl::desc("<output>"), - cl::init("-")); - -void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) { - std::unique_ptr<FileOutputBuffer> Buffer; - Object<ELF64LE> Obj{ObjFile}; - Obj.finalize(); - ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = - FileOutputBuffer::create(OutputFilename, Obj.totalSize(), - FileOutputBuffer::F_executable); - if (auto EC = BufferOrErr.getError()) - error("failed to open " + OutputFilename); - else - Buffer = std::move(*BufferOrErr); - std::error_code EC; - std::unique_ptr<tool_output_file> Out = - make_unique<tool_output_file>(OutputFilename.data(), EC, sys::fs::F_None); - if (EC) - report_fatal_error(EC.message()); - Obj.write(*Buffer); - if (auto EC = Buffer->commit()) - reportError(OutputFilename, EC); - Out->keep(); -} - -int main(int argc, char **argv) { - // Print a stack trace if we signal out. - sys::PrintStackTraceOnErrorSignal(argv[0]); - PrettyStackTraceProgram X(argc, argv); - llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - cl::ParseCommandLineOptions(argc, argv, "llvm objcopy utility\n"); - ToolName = argv[0]; - if (InputFilename.empty()) { - cl::PrintHelpMessage(); - return 2; - } - Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(InputFilename); - if (!BinaryOrErr) - reportError(InputFilename, BinaryOrErr.takeError()); - Binary &Binary = *BinaryOrErr.get().getBinary(); - if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) { - CopyBinary(*o); - return 0; - } - reportError(InputFilename, object_error::invalid_file_type); -} |