[PATCH] D47505: [llvm-strip] Add -o option

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 16:40:21 PDT 2018


alexshap created this revision.
alexshap added reviewers: jhenderson, paulsemel, jakehehrlich.

This diff implements -o <file> option https://sourceware.org/binutils/docs/binutils/strip.html .

Test plan: make check-all


Repository:
  rL LLVM

https://reviews.llvm.org/D47505

Files:
  test/tools/llvm-objcopy/strip-all.test
  tools/llvm-objcopy/StripOpts.td
  tools/llvm-objcopy/llvm-objcopy.cpp


Index: tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- tools/llvm-objcopy/llvm-objcopy.cpp
+++ tools/llvm-objcopy/llvm-objcopy.cpp
@@ -578,7 +578,9 @@
 
   CopyConfig Config;
   Config.InputFilename = Positional[0];
-  Config.OutputFilename = Positional[0];
+  Config.OutputFilename = InputArgs.hasArg(STRIP_output)
+                              ? InputArgs.getLastArg(STRIP_output)->getValue()
+                              : Positional[0];
 
   // Strip debug info only.
   Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug);
Index: tools/llvm-objcopy/StripOpts.td
===================================================================
--- tools/llvm-objcopy/StripOpts.td
+++ tools/llvm-objcopy/StripOpts.td
@@ -7,6 +7,10 @@
 
 def help : Flag<["-", "--"], "help">;
 
+defm output : Eq<"o">,
+              MetaVarName<"output">,
+              HelpText<"Output file">;
+
 def strip_debug : Flag<["-", "--"], "strip-debug">,
                   HelpText<"Remove debugging symbols only">;
 
Index: test/tools/llvm-objcopy/strip-all.test
===================================================================
--- test/tools/llvm-objcopy/strip-all.test
+++ test/tools/llvm-objcopy/strip-all.test
@@ -1,15 +1,18 @@
 # RUN: yaml2obj %s > %t
+# RUN: cp %t %t3
 # RUN: llvm-objcopy --strip-all %t %t2
 # RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s
 
-# We run yaml2obj again rather than copy %t to avoid interfering
-# with llvm-objcopy's test (which potentially could have corrupted/updated the binary).
+# Verify that the previous llvm-objcopy's run has not modifed the input.
+# RUN: cmp %t %t3
 
-# RUN: yaml2obj %s > %t3
 # RUN: llvm-strip %t3 
-# RUN: llvm-readobj -file-headers -sections %t3 | FileCheck %s
 # RUN: cmp %t2 %t3
 
+# RUN: cp %t %t4
+# RUN: llvm-strip %t4 -o %t5
+# RUN: cmp %t2 %t5
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47505.149004.patch
Type: text/x-patch
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/1ec05c23/attachment.bin>


More information about the llvm-commits mailing list