OSDN Git Service

[llvm-strip] Expose --keep-symbol option
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 23 May 2018 19:44:19 +0000 (19:44 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Wed, 23 May 2018 19:44:19 +0000 (19:44 +0000)
Expose --keep-symbol option in llvm-strip.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D47222

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

test/tools/llvm-objcopy/strip-all-and-keep-symbol.test
tools/llvm-objcopy/StripOpts.td
tools/llvm-objcopy/llvm-objcopy.cpp

index 6cb5f85..c0f22b4 100644 (file)
@@ -1,7 +1,15 @@
 # RUN: yaml2obj %s > %t
+# RUN: cp %t %t1
 # RUN: llvm-objcopy --strip-all --keep-symbol foo %t %t2
 # RUN: llvm-readobj -sections -symbols %t2 | FileCheck %s
 
+# Verify that the first run of llvm-objcopy
+# has not modified the input binary.
+# RUN: cmp %t %t1
+
+# RUN: llvm-strip -keep-symbol=foo %t1
+# RUN: cmp %t1 %t2
+
 !ELF
 FileHeader:
   Class:           ELFCLASS64
index 1d7a1ae..7c8862f 100644 (file)
@@ -16,3 +16,10 @@ defm remove_section : Eq<"remove-section">,
 
 def R : JoinedOrSeparate<["-"], "R">,
         Alias<remove_section>;
+
+defm keep_symbol : Eq<"keep-symbol">,
+                   MetaVarName<"symbol">,
+                   HelpText<"Do not remove symbol <symbol>">;
+
+def K : JoinedOrSeparate<["-"], "K">,
+        Alias<keep_symbol>;
index dbe8f8c..6aac11a 100644 (file)
@@ -557,6 +557,9 @@ CopyConfig ParseStripOptions(ArrayRef<const char *> ArgsArr) {
 
   for (auto Arg : InputArgs.filtered(STRIP_remove_section))
     Config.ToRemove.push_back(Arg->getValue());
+  
+  for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
+    Config.SymbolsToKeep.push_back(Arg->getValue());
 
   return Config;
 }