Debian Codegraph @

llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test

raw
1 ## This test checks that llvm-objcopy accepts glob (or "shell wildcard") syntax
2 ## for the --wildcard (-w) flag correctly.
3
4 # RUN: yaml2obj --docnum=1 %s -o %t.o
5
6 ## * matches all characters.
7 # RUN: llvm-objcopy --remove-section='.f*' %t.o %t.glob.o
8 # RUN: llvm-readobj --sections %t.glob.o \
9 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR
10
11 ## Glob matches are full matches. ("*a" does not match ".bar").
12 # RUN: llvm-objcopy --remove-section='*a' %t.o %t.full.o
13 # RUN: llvm-readobj --sections %t.full.o \
14 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO,BAR
15
16 ## ? matches one character.
17 # RUN: llvm-objcopy --remove-section='.b?r' %t.o %t.question.o
18 # RUN: llvm-readobj --sections %t.question.o \
19 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO
20
21 ## ! (as a leading character) prevents matches, and is not dependent on
22 ## ordering.
23 # RUN: llvm-objcopy --remove-section='.???' --remove-section='!.f*' \
24 # RUN: %t.o %t.negmatch1.o
25 # RUN: llvm-readobj --sections %t.negmatch1.o \
26 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO
27 # RUN: llvm-objcopy --remove-section='!.f*' --remove-section='.???' \
28 # RUN: %t.o %t.negmatch2.o
29 # RUN: llvm-readobj --sections %t.negmatch2.o \
30 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO
31 # RUN: llvm-objcopy --remove-section='.???' --remove-section='!.f*' \
32 # RUN: --remove-section='.???' %t.o %t.negmatch3.o
33 # RUN: llvm-readobj --sections %t.negmatch3.o \
34 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO
35
36 ## [a-z] matches a range of characters.
37 # RUN: llvm-objcopy --remove-section='.[a-c][a-a][q-s]' %t.o %t.range.o
38 # RUN: llvm-readobj --sections %t.range.o \
39 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO
40
41 ## [^a-z] or [!a-z] match a negated range of characters.
42 # RUN: llvm-objcopy --remove-section='.[^x]oo' %t.o %t.negrange.1.o
43 # RUN: llvm-readobj --sections %t.negrange.1.o \
44 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR
45 # RUN: llvm-objcopy --remove-section='.[!x]oo' %t.o %t.negrange.2.o
46 # RUN: llvm-readobj --sections %t.negrange.2.o \
47 # RUN: | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR
48
49 --- !ELF
50 FileHeader:
51 Class: ELFCLASS64
52 Data: ELFDATA2LSB
53 Type: ET_REL
54 Machine: EM_X86_64
55 Sections:
56 - Name: .foo
57 Type: SHT_PROGBITS
58 - Name: .bar
59 Type: SHT_PROGBITS
60 Symbols: []
61
62 ## Use a separate test file with special characters for the following tests.
63
64 # RUN: yaml2obj --docnum=2 %s -o %t.special.o
65
66 ## \ escapes wildcard characters.
67 # RUN: llvm-objcopy --remove-section='\*' %t.special.o %t.escape.1.o
68 # RUN: llvm-readobj --sections %t.escape.1.o \
69 # RUN: | FileCheck %s --implicit-check-not=Name: \
70 # RUN: --check-prefixes=CHECK,DOT,QUESTION,LEFT-BRACKET,RIGHT-BRACKET,INVALID-GLOB,Z,XYZ,FOO
71 # RUN: llvm-objcopy --remove-section='\?' %t.special.o %t.escape.2.o
72 # RUN: llvm-readobj --sections %t.escape.2.o \
73 # RUN: | FileCheck %s --implicit-check-not=Name: \
74 # RUN: --check-prefixes=CHECK,DOT,ASTERISK,LEFT-BRACKET,RIGHT-BRACKET,INVALID-GLOB,Z,XYZ,FOO
75
76 ## Special characters are not treated like regular expression characters.
77 # RUN: llvm-objcopy --remove-section='.' %t.special.o %t.dot.o
78 # RUN: llvm-readobj --sections %t.dot.o \
79 # RUN: | FileCheck %s --implicit-check-not=Name: \
80 # RUN: --check-prefixes=CHECK,ASTERISK,QUESTION,LEFT-BRACKET,RIGHT-BRACKET,INVALID-GLOB,Z,XYZ,FOO
81
82 ## Special characters in character classes are treated literally.
83 ## [*] should not get expanded to [.*], which would match both '.' and '*'
84 # RUN: llvm-objcopy --remove-section='[*]' %t.special.o %t.class.1.o
85 # RUN: llvm-readobj --sections %t.class.1.o \
86 # RUN: | FileCheck %s --implicit-check-not=Name: \
87 # RUN: --check-prefixes=CHECK,DOT,QUESTION,LEFT-BRACKET,RIGHT-BRACKET,INVALID-GLOB,Z,XYZ,FOO
88
89 ## ] doesn't close the character class as a first character. This glob matches
90 ## a single character which is one of ']xyz'. ']' and 'z' are removed, and more explicitly,
91 ## section 'xyz]' is not removed, i.e. the glob is not interpreted as "an empty
92 ## character class followed by 'xyz]'"
93 # RUN: llvm-objcopy --remove-section='[]xyz]' %t.special.o %t.class.2.o
94 # RUN: llvm-readobj --sections %t.class.2.o \
95 # RUN: | FileCheck %s --implicit-check-not=Name: \
96 # RUN: --check-prefixes=CHECK,DOT,ASTERISK,QUESTION,LEFT-BRACKET,INVALID-GLOB,XYZ,FOO
97
98 ## An invalid glob expression is interpreted as a literal instead.
99 # RUN: llvm-objcopy --remove-section='][]' %t.special.o %t.class.3.o 2>&1 \
100 # RUN: | FileCheck %s --check-prefix=WARN
101 # RUN: llvm-readobj --sections %t.class.3.o \
102 # RUN: | FileCheck %s --implicit-check-not=Name: \
103 # RUN: --check-prefixes=CHECK,DOT,ASTERISK,QUESTION,LEFT-BRACKET,RIGHT-BRACKET,Z,XYZ,FOO
104
105 --- !ELF
106 FileHeader:
107 Class: ELFCLASS64
108 Data: ELFDATA2LSB
109 Type: ET_REL
110 Machine: EM_X86_64
111 Sections:
112 - Name: .
113 Type: SHT_PROGBITS
114 - Name: '*'
115 Type: SHT_PROGBITS
116 - Name: '?'
117 Type: SHT_PROGBITS
118 - Name: '['
119 Type: SHT_PROGBITS
120 - Name: ']'
121 Type: SHT_PROGBITS
122 - Name: '][]'
123 Type: SHT_PROGBITS
124 - Name: z
125 Type: SHT_PROGBITS
126 - Name: 'xyz]'
127 Type: SHT_PROGBITS
128 - Name: '[]xyz]'
129 Type: SHT_PROGBITS
130 - Name: .foo
131 Type: SHT_PROGBITS
132 Symbols: []
133
134 # WARN: warning: invalid glob pattern, unmatched '['
135
136 # CHECK: LoadName:
137 # CHECK: Name: (0)
138 # DOT: Name: .
139 # ASTERISK: Name: *
140 # QUESTION: Name: ?
141 # LEFT-BRACKET: Name: [
142 # RIGHT-BRACKET: Name: ]
143 # INVALID-GLOB: Name: ][]
144 # Z: Name: z
145 # XYZ: Name: xyz]
146 # XYZ: Name: []xyz]
147 # FOO: Name: .foo
148 # BAR: Name: .bar
149 # CHECK: Name: .symtab
150 # CHECK: Name: .strtab
151 # CHECK: Name: .shstrtab