Let --discard-all imply --strip-debug.
authorSid Manning <sidneym@quicinc.com>
Fri, 3 May 2019 14:14:01 +0000 (14:14 +0000)
committerSid Manning <sidneym@quicinc.com>
Fri, 3 May 2019 14:14:01 +0000 (14:14 +0000)
This will match gnu strip's behavior.

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

llvm-svn: 359887

llvm/test/tools/llvm-objcopy/ELF/discard-all-debug.test [new file with mode: 0644]
llvm/tools/llvm-objcopy/CopyConfig.cpp

diff --git a/llvm/test/tools/llvm-objcopy/ELF/discard-all-debug.test b/llvm/test/tools/llvm-objcopy/ELF/discard-all-debug.test
new file mode 100644 (file)
index 0000000..57814e9
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: cp %p/Inputs/dwarf.dwo %t
+# RUN: llvm-strip --keep-symbol=.L.str --discard-all %t -o %t1
+# RUN: llvm-readobj --file-headers --sections %t1 | FileCheck --implicit-check-not=.debug_ %s
+# RUN: llvm-objcopy --keep-symbol=.L.str --discard-all %t %t2
+# RUN: llvm-readobj --file-headers --sections %t2 | FileCheck --implicit-check-not=.debug_ %s
index bece673..3ea4a95 100644 (file)
@@ -584,6 +584,8 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
   Config.KeepFileSymbols = InputArgs.hasArg(OBJCOPY_keep_file_symbols);
   Config.DecompressDebugSections =
       InputArgs.hasArg(OBJCOPY_decompress_debug_sections);
+  if (Config.DiscardMode == DiscardType::All)
+    Config.StripDebug = true;
   for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol))
     Config.SymbolsToLocalize.emplace_back(Arg->getValue(), UseRegex);
   for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbols))
@@ -753,6 +755,9 @@ Expected<DriverConfig> parseStripOptions(ArrayRef<const char *> ArgsArr) {
       !Config.StripAllGNU && Config.SymbolsToRemove.empty())
     Config.StripAll = true;
 
+  if (Config.DiscardMode == DiscardType::All)
+    Config.StripDebug = true;
+
   Config.DeterministicArchives =
       InputArgs.hasFlag(STRIP_enable_deterministic_archives,
                         STRIP_disable_deterministic_archives, /*default=*/true);