[PATCH] D53954: [llvm-strip] Support --keep and --strip-all-gnu from llvm-objcopy

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 1 08:23:04 PDT 2018


rupprecht updated this revision to Diff 172125.
rupprecht added a comment.

- Fix typos


Repository:
  rL LLVM

https://reviews.llvm.org/D53954

Files:
  test/tools/llvm-objcopy/basic-keep.test
  test/tools/llvm-objcopy/strip-all-gnu.test
  tools/llvm-objcopy/CopyConfig.cpp
  tools/llvm-objcopy/ObjcopyOpts.td
  tools/llvm-objcopy/StripOpts.td


Index: tools/llvm-objcopy/StripOpts.td
===================================================================
--- tools/llvm-objcopy/StripOpts.td
+++ tools/llvm-objcopy/StripOpts.td
@@ -22,6 +22,9 @@
 def s : Flag<["-"], "s">,
         Alias<strip_all>;
 
+def strip_all_gnu : Flag<["-", "--"], "strip-all-gnu">,
+                    HelpText<"Compatible with GNU strip's --strip-all">;
+
 def strip_debug : Flag<["-", "--"], "strip-debug">,
                   HelpText<"Remove debugging symbols only">;
 
@@ -41,6 +44,8 @@
 def R : JoinedOrSeparate<["-"], "R">,
         Alias<remove_section>;
 
+defm keep : Eq<"keep">, MetaVarName<"section">, HelpText<"Keep <section>">;
+
 defm keep_symbol : Eq<"keep-symbol">,
                    MetaVarName<"symbol">,
                    HelpText<"Do not remove symbol <symbol>">;
Index: tools/llvm-objcopy/ObjcopyOpts.td
===================================================================
--- tools/llvm-objcopy/ObjcopyOpts.td
+++ tools/llvm-objcopy/ObjcopyOpts.td
@@ -74,7 +74,7 @@
 def S : Flag<["-"], "S">,
         Alias<strip_all>;
 def strip_all_gnu : Flag<["-", "--"], "strip-all-gnu">,
-                    HelpText<"Compaitable with GNU objcopy's --strip-all">;
+                    HelpText<"Compatible with GNU objcopy's --strip-all">;
 def strip_debug : Flag<["-", "--"], "strip-debug">,
                   HelpText<"Remove all debug information">;
 def strip_dwo : Flag<["-", "--"], "strip-dwo">,
@@ -138,7 +138,7 @@
 def K : JoinedOrSeparate<["-"], "K">,
         Alias<keep_symbol>;
 def only_keep_debug : Flag<["-", "--"], "only-keep-debug">,
-                          HelpText<"Currently ignored. Only for compaitability with GNU objcopy.">;
+                          HelpText<"Currently ignored. Only for compatibility with GNU objcopy.">;
 def strip_unneeded : Flag<["-", "--"], "strip-unneeded">,
                       HelpText<"Remove all symbols not needed by relocations">;
 def keep_file_symbols : Flag<["-", "--"], "keep-file-symbols">,
Index: tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- tools/llvm-objcopy/CopyConfig.cpp
+++ tools/llvm-objcopy/CopyConfig.cpp
@@ -401,10 +401,15 @@
   Config.DiscardAll = InputArgs.hasArg(STRIP_discard_all);
   Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded);
   Config.StripAll = InputArgs.hasArg(STRIP_strip_all);
+  Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
 
-  if (!Config.StripDebug && !Config.StripUnneeded && !Config.DiscardAll)
+  if (!Config.StripDebug && !Config.StripUnneeded && !Config.DiscardAll &&
+      !Config.StripAllGNU)
     Config.StripAll = true;
 
+  for (auto Arg : InputArgs.filtered(STRIP_keep))
+    Config.Keep.push_back(Arg->getValue());
+
   for (auto Arg : InputArgs.filtered(STRIP_remove_section))
     Config.ToRemove.push_back(Arg->getValue());
 
Index: test/tools/llvm-objcopy/strip-all-gnu.test
===================================================================
--- test/tools/llvm-objcopy/strip-all-gnu.test
+++ test/tools/llvm-objcopy/strip-all-gnu.test
@@ -1,7 +1,9 @@
 # RUN: yaml2obj %s > %t
 # RUN: cp %t %t1
 # RUN: llvm-objcopy --strip-all-gnu %t %t2
+# RUN: llvm-strip --strip-all-gnu %t -o %t3
 # RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s
+# RUN: cmp %t2 %t3
 
 !ELF
 FileHeader:
Index: test/tools/llvm-objcopy/basic-keep.test
===================================================================
--- test/tools/llvm-objcopy/basic-keep.test
+++ test/tools/llvm-objcopy/basic-keep.test
@@ -1,6 +1,8 @@
 # RUN: yaml2obj %s > %t
 # RUN: llvm-objcopy -strip-non-alloc -keep=.test %t %t2
+# RUN: llvm-strip --strip-all -keep=.test %t -o %t3
 # RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s
+# RUN: cmp %t2 %t3
 
 !ELF
 FileHeader:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53954.172125.patch
Type: text/x-patch
Size: 3800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/cba5712f/attachment.bin>


More information about the llvm-commits mailing list