]> granicus.if.org Git - llvm/commitdiff
[llvm-strip] Support --strip-sections
authorWolfgang Pieb <Wolfgang.Pieb@sony.com>
Thu, 8 Aug 2019 00:35:16 +0000 (00:35 +0000)
committerWolfgang Pieb <Wolfgang.Pieb@sony.com>
Thu, 8 Aug 2019 00:35:16 +0000 (00:35 +0000)
llvm-objcopy already supports --strip-sections. It is a good fit for its alias llvm-strip
to support it as well.

Reviewers: rupprecht, jhenderson

Differential Revision: https://reviews.llvm.org/D65787

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368241 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-objcopy/ELF/strip-sections.test
tools/llvm-objcopy/CopyConfig.cpp
tools/llvm-objcopy/StripOpts.td

index 492a08215213877b29058f74b0af18eea74c90db..40032d93a3dd156422cdc784e329174573e97ddd 100644 (file)
@@ -8,6 +8,11 @@
 # RUN: llvm-objcopy %t %t3
 # RUN: od -t x1 -j 4096 -N 12 %t3 | FileCheck %s --check-prefix=VALIDATE
 
+## Check that llvm-strip --strip-sections is equivalent to
+## llvm-objcopy --strip-sections. 
+# RUN: llvm-strip --strip-sections %t -o %t4
+# RUN: cmp %t2 %t4
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64
index 4001aac4ed479f62eef0372d1bc795b2e479239d..3cd95665139077515c3871ee599ceba7d835ae43 100644 (file)
@@ -810,6 +810,7 @@ parseStripOptions(ArrayRef<const char *> ArgsArr,
         InputArgs.hasFlag(STRIP_discard_all, STRIP_discard_locals)
             ? DiscardType::All
             : DiscardType::Locals;
+  Config.StripSections = InputArgs.hasArg(STRIP_strip_sections);
   Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded);
   if (auto Arg = InputArgs.getLastArg(STRIP_strip_all, STRIP_no_strip_all))
     Config.StripAll = Arg->getOption().getID() == STRIP_strip_all;
index 1d06bb3dfb384c3323c983d4b21e4ea4fd955b89..e46d9e8bf10d90e47b79fc1f0c75fa8a38ec7e1d 100644 (file)
@@ -52,6 +52,9 @@ def strip_debug : Flag<["--"], "strip-debug">,
 def d : Flag<["-"], "d">, Alias<strip_debug>;
 def g : Flag<["-"], "g">, Alias<strip_debug>;
 def S : Flag<["-"], "S">, Alias<strip_debug>;
+def strip_sections
+    : Flag<["--"], "strip-sections">,
+      HelpText<"Remove all section headers and all sections not in segments">;
 def strip_unneeded : Flag<["--"], "strip-unneeded">,
                      HelpText<"Remove all symbols not needed by relocations">;