summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test8
-rw-r--r--llvm/tools/llvm-objcopy/StripOpts.td7
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp3
3 files changed, 18 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test b/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test
index 6cb5f855b55..c0f22b489b1 100644
--- a/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test
+++ b/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test
@@ -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
diff --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td
index 1d7a1aec14d..7c8862f5406 100644
--- a/llvm/tools/llvm-objcopy/StripOpts.td
+++ b/llvm/tools/llvm-objcopy/StripOpts.td
@@ -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>;
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index dbe8f8c10ac..6aac11af1bb 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -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;
}
OpenPOWER on IntegriCloud