]> granicus.if.org Git - llvm/commitdiff
[llvm-strip] Add --strip-symbol
authorEugene Leviant <eleviant@accesssoftek.com>
Thu, 31 Jan 2019 12:16:20 +0000 (12:16 +0000)
committerEugene Leviant <eleviant@accesssoftek.com>
Thu, 31 Jan 2019 12:16:20 +0000 (12:16 +0000)
Differential revision: https://reviews.llvm.org/D57440

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

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

index ab5fee2c27198f5a26d01e44ea3e7c23a3c878d6..96c08c1a8df33964428a13135c5de10881944e03 100644 (file)
@@ -1,6 +1,8 @@
 # RUN: yaml2obj %s > %t
 # RUN: llvm-objcopy --strip-symbol baz -N bar %t %t2
 # RUN: llvm-readobj --symbols --sections %t2 | FileCheck %s
+# RUN: llvm-strip --strip-symbol baz -N bar %t -o %t3
+# RUN: llvm-readobj --symbols --sections %t3 | FileCheck %s
 
 !ELF
 FileHeader:
index e72733a01f5be3dd77c4c1da0b674e8a2c7e78b5..169a8ebb77fc1525c8fbe1a1eda1804c96f7d58d 100644 (file)
@@ -480,19 +480,22 @@ DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr) {
   Config.StripAll = InputArgs.hasArg(STRIP_strip_all);
   Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
 
-  if (!Config.StripDebug && !Config.StripUnneeded &&
-      Config.DiscardMode == DiscardType::None && !Config.StripAllGNU)
-    Config.StripAll = true;
-
   for (auto Arg : InputArgs.filtered(STRIP_keep_section))
     Config.KeepSection.push_back(Arg->getValue());
 
   for (auto Arg : InputArgs.filtered(STRIP_remove_section))
     Config.ToRemove.push_back(Arg->getValue());
 
+  for (auto Arg : InputArgs.filtered(STRIP_strip_symbol))
+    Config.SymbolsToRemove.push_back(Arg->getValue());
+
   for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
     Config.SymbolsToKeep.push_back(Arg->getValue());
 
+  if (!Config.StripDebug && !Config.StripUnneeded &&
+      Config.DiscardMode == DiscardType::None && !Config.StripAllGNU && Config.SymbolsToRemove.empty())
+    Config.StripAll = true;
+
   Config.DeterministicArchives =
       InputArgs.hasFlag(STRIP_enable_deterministic_archives,
                         STRIP_disable_deterministic_archives, /*default=*/true);
index 75f703439e952987d298dfcaa1304ca8db19bacf..f0f77254af0d9fa18f12b39b17cbc3d789f7ff88 100644 (file)
@@ -51,6 +51,10 @@ defm remove_section : Eq<"remove-section", "Remove <section>">,
                       MetaVarName<"section">;
 def R : JoinedOrSeparate<["-"], "R">, Alias<remove_section>;
 
+defm strip_symbol : Eq<"strip-symbol", "Strip <symbol>">,
+                    MetaVarName<"symbol">;
+def N : JoinedOrSeparate<["-"], "N">, Alias<strip_symbol>;
+
 defm keep_section : Eq<"keep-section", "Keep <section>">,
                     MetaVarName<"section">;
 defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol <symbol>">,