llvm.org GIT mirror llvm / efbb95e
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359781 91177308-0d34-0410-b5e6-96231b3b80d8 James Henderson 5 months ago
9 changed file(s) with 66 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
55 # RUN: llvm-objcopy %t %t2
66 # RUN: llvm-objcopy --only-keep-debug %t %t3
77 # RUN: cmp %t2 %t3
8 # Run llvm-strip with --strip-symbol on a non-existent symbol to prevent
9 # defaulting to --strip-all.
10 # RUN: llvm-strip --only-keep-debug --strip-symbol foo %t -o %t4
8 # RUN: llvm-strip --only-keep-debug --no-strip-all %t -o %t4
119 # RUN: cmp %t2 %t4
1210
1311 !ELF
0 # RUN: not llvm-objcopy -R .dynstr %p/Inputs/dynsym.so %t 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
11 # RUN: cp %p/Inputs/dynsym.so %t2
2 ## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
3 ## TODO: Implement a better way to suppress --strip-all behavior.
4 # RUN: not llvm-strip --strip-debug -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
2 # RUN: not llvm-strip --no-strip-all -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
53
64 # ERR: Section .dynstr cannot be removed because it is referenced by the section .dynsym
75
86 # RUN: llvm-objcopy --allow-broken-links -R .dynstr %p/Inputs/dynsym.so %t3
97 # RUN: llvm-objdump --section-headers %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
108 # RUN: cp %p/Inputs/dynsym.so %t4
11 # RUN: llvm-strip --strip-debug --allow-broken-links -R .dynstr %t4
9 # RUN: llvm-strip --no-strip-all --allow-broken-links -R .dynstr %t4
1210 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
1311
1412 # SECTIONS: .dynsym
0 ## --no-strip-all disables the --strip-all llvm-strip switch.
1 ## It also disables the default --strip-all behaviour.
2
3 # RUN: yaml2obj %s -o %t.o
4
5 ## Base case: no switches, should strip. Used as a sanity check for later test cases.
6 # RUN: llvm-strip %t.o -o %t1.o
7 # RUN: llvm-readobj --file-headers --sections %t1.o | FileCheck %s --check-prefix=ALL
8
9 ## --no-strip-all alone disables stripping.
10 # RUN: llvm-strip --no-strip-all %t.o -o %t2.o
11 # RUN: llvm-readobj --file-headers --sections %t2.o | FileCheck %s --check-prefix=NO-STRIP
12
13 ## --no-strip-all wins if last.
14 # RUN: llvm-strip --strip-all --no-strip-all %t.o -o %t3.o
15 # RUN: cmp %t2.o %t3.o
16
17 ## --strip-all wins if last.
18 # RUN: llvm-strip --no-strip-all --strip-all %t.o -o %t4.o
19 # RUN: cmp %t1.o %t4.o
20
21 ## The last instance of --no-strip-all is used in the comparison.
22 # RUN: llvm-strip --no-strip-all --strip-all --no-strip-all %t.o -o %t5.o
23 # RUN: cmp %t2.o %t5.o
24
25 ## The last instance of --strip-all is used in the comparison.
26 # RUN: llvm-strip --strip-all --no-strip-all --strip-all %t.o -o %t6.o
27 # RUN: cmp %t1.o %t6.o
28
29 --- !ELF
30 FileHeader:
31 Class: ELFCLASS64
32 Data: ELFDATA2LSB
33 Type: ET_REL
34 Machine: EM_X86_64
35 Sections:
36 - Name: .alloc
37 Type: SHT_PROGBITS
38 Flags: [ SHF_ALLOC ]
39
40 # ALL: SectionHeaderCount: 3
41 # ALL: Name: .alloc
42 # ALL: Name: .shstrtab
43
44 # NO-STRIP: SectionHeaderCount: 5
45 # NO-STRIP: Name: .alloc
46 # NO-STRIP: Name: .symtab
47 # NO-STRIP: Name: .strtab
48 # NO-STRIP: Name: .shstrtab
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
22 # RUN: cp %t %t3
3 ## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
4 ## TODO: Implement a better way to suppress --strip-all behavior.
5 # RUN: not llvm-strip --strip-debug -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
3 # RUN: not llvm-strip --no-strip-all -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
64
75 !ELF
86 FileHeader:
3735 # RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t4
3836 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
3937 # RUN: cp %t %t5
40 # RUN: llvm-strip --strip-debug --allow-broken-links -R .symtab %t5
38 # RUN: llvm-strip --no-strip-all --allow-broken-links -R .symtab %t5
4139 # RUN: llvm-readobj --sections %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
4240
4341 # SECTIONS: Name: .rel.text
0 # RUN: yaml2obj %s -o %t.o
11 # RUN: not llvm-objcopy -R .foo %t.o %t1 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
22 # RUN: cp %t.o %t2
3 ## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
4 ## TODO: Implement a better way to suppress --strip-all behavior.
5 # RUN: not llvm-strip --strip-debug -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
3 # RUN: not llvm-strip --no-strip-all -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
64
75 --- !ELF
86 FileHeader:
2220 # RUN: llvm-objcopy --allow-broken-links -R .foo %t.o %t3
2321 # RUN: llvm-readobj --sections %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
2422 # RUN: cp %t.o %t4
25 # RUN: llvm-strip --strip-debug --allow-broken-links -R .foo %t4
23 # RUN: llvm-strip --no-strip-all --allow-broken-links -R .foo %t4
2624 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
2725
2826 # SECTIONS: Name: .bar
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy -R .strtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
22 # RUN: cp %t %t3
3 ## Use --strip-debug to suppress the default --strip-all behavior of llvm-strip.
4 ## TODO: Implement a better way to suppress --strip-all behavior.
5 # RUN: not llvm-strip --strip-debug -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
3 # RUN: not llvm-strip --no-strip-all -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
64
75 !ELF
86 FileHeader:
1614 # RUN: llvm-objcopy --allow-broken-links -R .strtab %t %t4
1715 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
1816 # RUN: cp %t %t5
19 # RUN: llvm-strip --strip-debug --allow-broken-links -R .strtab %t %t5
17 # RUN: llvm-strip --no-strip-all --allow-broken-links -R .strtab %t %t5
2018 # RUN: llvm-objdump --section-headers %t5 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
2119
2220 # SECTIONS: .symtab
11 # RUN: llvm-objcopy %t %t2
22 # RUN: llvm-readobj --sections %t2 | FileCheck %s
33 # RUN: cp %t %t3
4 # RUN: llvm-strip --strip-debug %t3
4 # RUN: llvm-strip --no-strip-all %t3
55 # RUN: llvm-readobj --sections %t3 | FileCheck %s
66
77 !ELF
729729 ? DiscardType::All
730730 : DiscardType::Locals;
731731 Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded);
732 Config.StripAll = InputArgs.hasArg(STRIP_strip_all);
732 if (auto Arg = InputArgs.getLastArg(STRIP_strip_all, STRIP_no_strip_all))
733 Config.StripAll = Arg->getOption().getID() == STRIP_strip_all;
733734 Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
734735 Config.OnlyKeepDebug = InputArgs.hasArg(STRIP_only_keep_debug);
735736 Config.KeepFileSymbols = InputArgs.hasArg(STRIP_keep_file_symbols);
746747 for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
747748 Config.SymbolsToKeep.emplace_back(Arg->getValue(), UseRegexp);
748749
749 if (!Config.StripDebug && !Config.StripUnneeded &&
750 Config.DiscardMode == DiscardType::None && !Config.StripAllGNU && Config.SymbolsToRemove.empty())
750 if (!InputArgs.hasArg(STRIP_no_strip_all) && !Config.StripDebug &&
751 !Config.StripUnneeded && Config.DiscardMode == DiscardType::None &&
752 !Config.StripAllGNU && Config.SymbolsToRemove.empty())
751753 Config.StripAll = true;
752754
753755 Config.DeterministicArchives =
4141 HelpText<"Remove non-allocated sections outside segments. "
4242 ".gnu.warning* sections are not removed">;
4343 def s : Flag<["-"], "s">, Alias;
44 def no_strip_all : Flag<["--"], "no-strip-all">,
45 HelpText<"Disable --strip-all">;
4446
4547 def strip_all_gnu : Flag<["--"], "strip-all-gnu">,
4648 HelpText<"Compatible with GNU strip's --strip-all">;