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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359781
91177308-0d34-0410-b5e6-
96231b3b80d8
# 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
# 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
--- /dev/null
+## --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
# 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:
# 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
# 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:
# 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
# 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:
# 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
# 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
? 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);
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 =
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">;