[llvm] r359781 - [llvm-strip]Add --no-strip-all to disable --strip-all behaviour (including default stripping)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 04:53:02 PDT 2019


Author: jhenderson
Date: Thu May  2 04:53:02 2019
New Revision: 359781

URL: http://llvm.org/viewvc/llvm-project?rev=359781&view=rev
Log:
[llvm-strip]Add --no-strip-all to disable --strip-all behaviour (including default stripping)

If certain switches are not specified, llvm-strip behaves as if
--strip-all were specified. This means that for testing, when we don't
want the stripping behaviour, we have to specify one of these switches,
which can be confusing. This change adds --no-strip-all to allow an
alternative way of suppressing the default stripping, in a less
confusing manner.

Reviewed by: jakehehrlich, MaskRay

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

Added:
    llvm/trunk/test/tools/llvm-objcopy/ELF/no-strip-all.test
Modified:
    llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/remove-linked-section.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
    llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-link.test
    llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
    llvm/trunk/tools/llvm-objcopy/StripOpts.td

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test Thu May  2 04:53:02 2019
@@ -6,9 +6,7 @@
 # RUN: llvm-objcopy %t %t2
 # RUN: llvm-objcopy --only-keep-debug %t %t3
 # RUN: cmp %t2 %t3
-# Run llvm-strip with --strip-symbol on a non-existent symbol to prevent
-# defaulting to --strip-all.
-# RUN: llvm-strip --only-keep-debug --strip-symbol foo %t -o %t4
+# RUN: llvm-strip --only-keep-debug --no-strip-all %t -o %t4
 # RUN: cmp %t2 %t4
 
 !ELF

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test Thu May  2 04:53:02 2019
@@ -1,15 +1,13 @@
 # RUN: not llvm-objcopy -R .dynstr %p/Inputs/dynsym.so %t 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 # RUN: cp  %p/Inputs/dynsym.so %t2
-## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
-## TODO: Implement a better way to suppress --strip-all behavior.
-# RUN: not llvm-strip --strip-debug -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 
 # ERR: Section .dynstr cannot be removed because it is referenced by the section .dynsym
 
 # RUN: llvm-objcopy --allow-broken-links -R .dynstr %p/Inputs/dynsym.so %t3
 # RUN: llvm-objdump --section-headers %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
 # RUN: cp  %p/Inputs/dynsym.so %t4
-# RUN: llvm-strip --strip-debug --allow-broken-links -R .dynstr %t4
+# RUN: llvm-strip --no-strip-all --allow-broken-links -R .dynstr %t4
 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
 
 # SECTIONS: .dynsym

Added: llvm/trunk/test/tools/llvm-objcopy/ELF/no-strip-all.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/no-strip-all.test?rev=359781&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/no-strip-all.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/no-strip-all.test Thu May  2 04:53:02 2019
@@ -0,0 +1,49 @@
+## --no-strip-all disables the --strip-all llvm-strip switch.
+## It also disables the default --strip-all behaviour.
+
+# RUN: yaml2obj %s -o %t.o
+
+## Base case: no switches, should strip. Used as a sanity check for later test cases.
+# RUN: llvm-strip %t.o -o %t1.o
+# RUN: llvm-readobj --file-headers --sections %t1.o | FileCheck %s --check-prefix=ALL
+
+## --no-strip-all alone disables stripping.
+# RUN: llvm-strip --no-strip-all %t.o -o %t2.o
+# RUN: llvm-readobj --file-headers --sections %t2.o | FileCheck %s --check-prefix=NO-STRIP
+
+## --no-strip-all wins if last.
+# RUN: llvm-strip --strip-all --no-strip-all %t.o -o %t3.o
+# RUN: cmp %t2.o %t3.o
+
+## --strip-all wins if last.
+# RUN: llvm-strip --no-strip-all --strip-all %t.o -o %t4.o
+# RUN: cmp %t1.o %t4.o
+
+## The last instance of --no-strip-all is used in the comparison.
+# RUN: llvm-strip --no-strip-all --strip-all --no-strip-all %t.o -o %t5.o
+# RUN: cmp %t2.o %t5.o
+
+## The last instance of --strip-all is used in the comparison.
+# RUN: llvm-strip --strip-all --no-strip-all --strip-all %t.o -o %t6.o
+# RUN: cmp %t1.o %t6.o
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections:
+  - Name:  .alloc
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC ]
+
+# ALL: SectionHeaderCount: 3
+# ALL: Name: .alloc
+# ALL: Name: .shstrtab
+
+# NO-STRIP: SectionHeaderCount: 5
+# NO-STRIP: Name: .alloc
+# NO-STRIP: Name: .symtab
+# NO-STRIP: Name: .strtab
+# NO-STRIP: Name: .shstrtab

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test Thu May  2 04:53:02 2019
@@ -1,9 +1,7 @@
 # RUN: yaml2obj %s > %t
 # RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 # RUN: cp %t %t3
-## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
-## TODO: Implement a better way to suppress --strip-all behavior.
-# RUN: not llvm-strip --strip-debug -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 
 !ELF
 FileHeader:
@@ -38,7 +36,7 @@ Symbols:
 # RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t4
 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
 # RUN: cp %t %t5
-# RUN: llvm-strip --strip-debug --allow-broken-links -R .symtab %t5
+# RUN: llvm-strip --no-strip-all --allow-broken-links -R .symtab %t5
 # RUN: llvm-readobj --sections %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
 
 # SECTIONS:        Name: .rel.text

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/remove-linked-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/remove-linked-section.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/remove-linked-section.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/remove-linked-section.test Thu May  2 04:53:02 2019
@@ -1,9 +1,7 @@
 # RUN: yaml2obj %s -o %t.o
 # RUN: not llvm-objcopy -R .foo %t.o %t1 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 # RUN: cp %t.o %t2
-## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
-## TODO: Implement a better way to suppress --strip-all behavior.
-# RUN: not llvm-strip --strip-debug -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 
 --- !ELF
 FileHeader:
@@ -23,7 +21,7 @@ Sections:
 # RUN: llvm-objcopy --allow-broken-links -R .foo %t.o %t3
 # RUN: llvm-readobj --sections %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
 # RUN: cp %t.o %t4
-# RUN: llvm-strip --strip-debug --allow-broken-links -R .foo %t4
+# RUN: llvm-strip --no-strip-all --allow-broken-links -R .foo %t4
 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
 
 # SECTIONS:      Name: .bar

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test Thu May  2 04:53:02 2019
@@ -1,9 +1,7 @@
 # RUN: yaml2obj %s > %t
 # RUN: not llvm-objcopy -R .strtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 # RUN: cp %t %t3
-## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
-## TODO: Implement a better way to suppress --strip-all behavior.
-# RUN: not llvm-strip --strip-debug -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
 
 !ELF
 FileHeader:
@@ -17,7 +15,7 @@ FileHeader:
 # RUN: llvm-objcopy --allow-broken-links -R .strtab %t %t4
 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
 # RUN: cp %t %t5
-# RUN: llvm-strip --strip-debug --allow-broken-links -R .strtab %t %t5
+# RUN: llvm-strip --no-strip-all --allow-broken-links -R .strtab %t %t5
 # RUN: llvm-objdump --section-headers %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
 
 # SECTIONS: .symtab

Modified: llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-link.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-link.test?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-link.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/symtab-link.test Thu May  2 04:53:02 2019
@@ -2,7 +2,7 @@
 # RUN: llvm-objcopy %t %t2
 # RUN: llvm-readobj --sections %t2 | FileCheck %s
 # RUN: cp %t %t3
-# RUN: llvm-strip --strip-debug %t3
+# RUN: llvm-strip --no-strip-all %t3
 # RUN: llvm-readobj --sections %t3 | FileCheck %s
 
 !ELF

Modified: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp Thu May  2 04:53:02 2019
@@ -730,7 +730,8 @@ Expected<DriverConfig> parseStripOptions
             ? DiscardType::All
             : DiscardType::Locals;
   Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded);
-  Config.StripAll = InputArgs.hasArg(STRIP_strip_all);
+  if (auto Arg = InputArgs.getLastArg(STRIP_strip_all, STRIP_no_strip_all))
+    Config.StripAll = Arg->getOption().getID() == STRIP_strip_all;
   Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
   Config.OnlyKeepDebug = InputArgs.hasArg(STRIP_only_keep_debug);
   Config.KeepFileSymbols = InputArgs.hasArg(STRIP_keep_file_symbols);
@@ -747,8 +748,9 @@ Expected<DriverConfig> parseStripOptions
   for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
     Config.SymbolsToKeep.emplace_back(Arg->getValue(), UseRegexp);
 
-  if (!Config.StripDebug && !Config.StripUnneeded &&
-      Config.DiscardMode == DiscardType::None && !Config.StripAllGNU && Config.SymbolsToRemove.empty())
+  if (!InputArgs.hasArg(STRIP_no_strip_all) && !Config.StripDebug &&
+      !Config.StripUnneeded && Config.DiscardMode == DiscardType::None &&
+      !Config.StripAllGNU && Config.SymbolsToRemove.empty())
     Config.StripAll = true;
 
   Config.DeterministicArchives =

Modified: llvm/trunk/tools/llvm-objcopy/StripOpts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/StripOpts.td?rev=359781&r1=359780&r2=359781&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/StripOpts.td (original)
+++ llvm/trunk/tools/llvm-objcopy/StripOpts.td Thu May  2 04:53:02 2019
@@ -42,6 +42,8 @@ def strip_all : Flag<["--"], "strip-all"
                 HelpText<"Remove non-allocated sections outside segments. "
                          ".gnu.warning* sections are not removed">;
 def s : Flag<["-"], "s">, Alias<strip_all>;
+def no_strip_all : Flag<["--"], "no-strip-all">,
+                   HelpText<"Disable --strip-all">;
 
 def strip_all_gnu : Flag<["--"], "strip-all-gnu">,
                     HelpText<"Compatible with GNU strip's --strip-all">;




More information about the llvm-commits mailing list