[llvm-objcopy] Make modifications in-place if output is not specified
If the output file is not specified make the modifications in-place
(like binutils objcopy does). In particular, this fixes
the behavior of Clang -gsplit-dwarf (if Clang is configured to use llvm-objcopy),
previously it was creating .dwo files, but still leaving *dwo* sections in
the original binary.
Test plan: make check-all
Differential revision: https://reviews.llvm.org/D42873
llvm-svn: 324783
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 8f5243c..7d23039 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -72,8 +72,8 @@
} // end namespace llvm
static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input>"));
-static cl::opt<std::string> OutputFilename(cl::Positional, cl::desc("<output>"),
- cl::init("-"));
+static cl::opt<std::string> OutputFilename(cl::Positional, cl::desc("[ <output> ]"));
+
static cl::opt<std::string>
OutputFormat("O", cl::desc("Set output format to one of the following:"
"\n\tbinary"));
@@ -340,7 +340,9 @@
auto Reader = CreateReader();
auto Obj = Reader->create();
- auto Writer = CreateWriter(*Obj, OutputFilename);
+ StringRef Output =
+ OutputFilename.getNumOccurrences() ? OutputFilename : InputFilename;
+ auto Writer = CreateWriter(*Obj, Output);
HandleArgs(*Obj, *Reader);
Writer->finalize();
Writer->write();