summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/tools/llvm-objcopy/discard-all.test19
-rw-r--r--llvm/tools/llvm-objcopy/StripOpts.td5
-rw-r--r--llvm/tools/llvm-objcopy/llvm-objcopy.cpp5
3 files changed, 26 insertions, 3 deletions
diff --git a/llvm/test/tools/llvm-objcopy/discard-all.test b/llvm/test/tools/llvm-objcopy/discard-all.test
index cf8cbafb3da..db068697262 100644
--- a/llvm/test/tools/llvm-objcopy/discard-all.test
+++ b/llvm/test/tools/llvm-objcopy/discard-all.test
@@ -1,8 +1,23 @@
# RUN: yaml2obj %s > %t
+# RUN: cp %t %t1
# RUN: llvm-objcopy --discard-all %t %t2
-# RUN: llvm-objcopy -x %t %t3
+# Verify that llvm-objcopy has not modified the input.
+# RUN: cmp %t %t1
# RUN: llvm-readobj -symbols %t2 | FileCheck %s
-# RUN: diff %t2 %t3
+
+# RUN: llvm-objcopy -x %t %t3
+# Verify that llvm-objcopy has not modified the input.
+# RUN: cmp %t %t1
+# RUN: cmp %t2 %t3
+
+# Verify that llvm-strip modifies the symbol table the same way.
+
+# RUN: cp %t %t4
+# RUN: llvm-strip --discard-all %t4
+# RUN: cmp %t2 %t4
+
+# RUN: llvm-strip -x %t
+# RUN: cmp %t2 %t
!ELF
FileHeader:
diff --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td
index df1ebfa6fd3..27fdfee8f5b 100644
--- a/llvm/tools/llvm-objcopy/StripOpts.td
+++ b/llvm/tools/llvm-objcopy/StripOpts.td
@@ -36,3 +36,8 @@ defm keep_symbol : Eq<"keep-symbol">,
def K : JoinedOrSeparate<["-"], "K">,
Alias<keep_symbol>;
+
+def discard_all : Flag<["-", "--"], "discard-all">,
+ HelpText<"Remove all local symbols except file and section symbols">;
+def x : Flag<["-"], "x">,
+ Alias<discard_all>;
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 0563af93290..46769838aba 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -585,7 +585,10 @@ CopyConfig ParseStripOptions(ArrayRef<const char *> ArgsArr) {
// Strip debug info only.
Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug);
- if (!Config.StripDebug)
+
+ Config.DiscardAll = InputArgs.hasArg(STRIP_discard_all);
+
+ if (!Config.StripDebug && !Config.DiscardAll)
Config.StripAll = true;
for (auto Arg : InputArgs.filtered(STRIP_remove_section))
OpenPOWER on IntegriCloud