Index: test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test =================================================================== --- test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test +++ test/tools/llvm-objcopy/ELF/basic-only-keep-debug.test @@ -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 Index: test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test =================================================================== --- test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test +++ test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test @@ -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 Index: test/tools/llvm-objcopy/ELF/no-strip-all.test =================================================================== --- test/tools/llvm-objcopy/ELF/no-strip-all.test +++ test/tools/llvm-objcopy/ELF/no-strip-all.test @@ -0,0 +1,55 @@ +## --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: cp %t.o %t1.o +# RUN: llvm-strip %t1.o +# RUN: llvm-readobj --file-headers --sections %t1.o | FileCheck %s --check-prefix=ALL + +## --no-strip-all alone disables stripping. +# RUN: cp %t.o %t2.o +# RUN: llvm-strip --no-strip-all %t2.o +# RUN: llvm-readobj --file-headers --sections %t2.o | FileCheck %s --check-prefix=NO-STRIP + +## --no-strip-all wins if last. +# RUN: cp %t.o %t3.o +# RUN: llvm-strip --strip-all --no-strip-all %t3.o +# RUN: cmp %t2.o %t3.o + +## --strip-all wins if last. +# RUN: cp %t.o %t4.o +# RUN: llvm-strip --no-strip-all --strip-all %t4.o +# RUN: cmp %t1.o %t4.o + +## The last instance of --no-strip-all is used in the comparison. +# RUN: cp %t.o %t5.o +# RUN: llvm-strip --no-strip-all --strip-all --no-strip-all %t5.o +# RUN: cmp %t2.o %t5.o + +## The last instance of --strip-all is used in the comparison. +# RUN: cp %t.o %t6.o +# RUN: llvm-strip --strip-all --no-strip-all --strip-all %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 Index: test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test =================================================================== --- test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test +++ test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test @@ -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 @@ # 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 Index: test/tools/llvm-objcopy/ELF/remove-linked-section.test =================================================================== --- test/tools/llvm-objcopy/ELF/remove-linked-section.test +++ test/tools/llvm-objcopy/ELF/remove-linked-section.test @@ -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 @@ # 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 Index: test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test =================================================================== --- test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test +++ test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test @@ -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 @@ # 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 Index: test/tools/llvm-objcopy/ELF/symtab-link.test =================================================================== --- test/tools/llvm-objcopy/ELF/symtab-link.test +++ test/tools/llvm-objcopy/ELF/symtab-link.test @@ -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 Index: tools/llvm-objcopy/CopyConfig.cpp =================================================================== --- tools/llvm-objcopy/CopyConfig.cpp +++ tools/llvm-objcopy/CopyConfig.cpp @@ -719,7 +719,8 @@ ? 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); @@ -736,8 +737,9 @@ 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 = Index: tools/llvm-objcopy/StripOpts.td =================================================================== --- tools/llvm-objcopy/StripOpts.td +++ tools/llvm-objcopy/StripOpts.td @@ -42,6 +42,8 @@ HelpText<"Remove non-allocated sections outside segments. " ".gnu.warning* sections are not removed">; def s : Flag<["-"], "s">, Alias; +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">;