summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorAlexander Shaposhnikov <shal1t712@gmail.com>2018-02-09 23:33:31 +0000
committerAlexander Shaposhnikov <shal1t712@gmail.com>2018-02-09 23:33:31 +0000
commitfedb01603c66fe662ecab2c51e3fe4deb8544bf6 (patch)
tree42fa93f548676f0b389e6a8e2e3923eed253be41 /llvm
parent99db883d55313ac98439b8031383abf82dcaafde (diff)
downloadbcm5719-llvm-fedb01603c66fe662ecab2c51e3fe4deb8544bf6.tar.gz
bcm5719-llvm-fedb01603c66fe662ecab2c51e3fe4deb8544bf6.zip
[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
Diffstat (limited to 'llvm')
-rw-r--r--llvm/test/tools/llvm-objcopy/strip-dwo-inplace.test29
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp8
2 files changed, 34 insertions, 3 deletions
diff --git a/llvm/test/tools/llvm-objcopy/strip-dwo-inplace.test b/llvm/test/tools/llvm-objcopy/strip-dwo-inplace.test
new file mode 100644
index 00000000000..31bbd36a31a
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/strip-dwo-inplace.test
@@ -0,0 +1,29 @@
+# RUN: cp %p/Inputs/dwarf.dwo %t
+# RUN: llvm-objcopy -strip-dwo %t
+# RUN: llvm-readobj -file-headers -sections %t | FileCheck %s
+
+CHECK: SectionHeaderCount: 24
+
+CHECK: Name: .text
+CHECK: Name: .rodata.str1.1
+CHECK: Name: .debug_str
+CHECK: Name: .debug_abbrev
+CHECK: Name: .debug_info
+CHECK: Name: .debug_ranges
+CHECK: Name: .debug_macinfo
+CHECK: Name: .debug_addr
+CHECK: Name: .debug_pubnames
+CHECK: Name: .debug_pubtypes
+CHECK: Name: .comment
+CHECK: Name: .note.GNU-stack
+CHECK: Name: .debug_frame
+CHECK: Name: .debug_line
+CHECK: Name: .symtab
+CHECK: Name: .rela.text
+CHECK: Name: .rela.debug_info
+CHECK: Name: .rela.debug_addr
+CHECK: Name: .rela.debug_pubnames
+CHECK: Name: .rela.debug_pubtypes
+CHECK: Name: .rela.debug_frame
+CHECK: Name: .rela.debug_line
+CHECK: Name: .strtab
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 8f5243cefa0..7d230390872 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -72,8 +72,8 @@ LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
} // 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 @@ int main(int argc, char **argv) {
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();
OpenPOWER on IntegriCloud