1## This test checks basic functionality of glob (or "shell wildcard") matching,
2## as well as verifying all the relevant flags in llvm-objcopy and llvm-strip
3## are configured correctly.
4## For more detailed syntax tests, see wildcard-syntax.test.
5
6# RUN: yaml2obj %s -o %t.o
7
8## Check that --regex and --wildcard cannot be used together.
9# RUN: not llvm-objcopy --regex --wildcard %t.o %t.err.o 2>&1 \
10# RUN:   | FileCheck %s --check-prefix=ERR
11# RUN: not llvm-strip --regex --wildcard %t.o -o %t.err.o 2>&1 \
12# RUN:   | FileCheck %s --check-prefix=ERR
13
14# ERR: error: --regex and --wildcard are incompatible
15
16## Check that section removal flags default to glob matches.
17
18## --keep-section:
19# RUN: llvm-objcopy --strip-all --keep-section='.f*' %t.o %t.ksec.1.o
20# RUN: llvm-readobj --sections %t.ksec.1.o \
21# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,SEC,FOO-SEC
22# RUN: llvm-strip --strip-all --keep-section='.f*' %t.o -o %t.ksec.2.o
23# RUN: cmp %t.ksec.1.o %t.ksec.2.o
24
25## --only-section:
26# RUN: llvm-objcopy --strip-all --only-section='.f*' %t.o %t.osec.1.o
27# RUN: llvm-readobj --sections %t.osec.1.o \
28# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,SEC,FOO-SEC
29
30## --remove-section:
31# RUN: llvm-objcopy --strip-debug --remove-section='.s??tab' %t.o %t.rsec.1.o
32# RUN: llvm-readobj --sections %t.rsec.1.o \
33# RUN:   | FileCheck %s --implicit-check-not=Name: \
34# RUN:       --check-prefixes=CHECK,SEC,FOO-SEC,BAR-SEC
35# RUN: llvm-strip --strip-debug --remove-section='.s??tab' %t.o -o %t.rsec.2.o
36# RUN: cmp %t.rsec.1.o %t.rsec.2.o
37
38## Check that symbol removal options default to literal matches. Adding -w
39## enables glob support for these options.
40
41## --globalize-symbol:
42# RUN: llvm-objcopy --globalize-symbol='*' %t.o %t.globsym.1.o
43# RUN: llvm-readobj --symbols %t.globsym.1.o \
44# RUN:   | FileCheck %s --implicit-check-not=Name: \
45# RUN:       --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
46
47# RUN: llvm-objcopy -w --globalize-symbol='*' %t.o %t.globsym.2.o
48# RUN: llvm-readobj --symbols %t.globsym.2.o \
49# RUN:   | FileCheck %s --implicit-check-not=Name: \
50# RUN:       --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
51
52## --keep-symbol:
53# RUN: llvm-objcopy --discard-all --keep-symbol='f*' %t.o %t.ksym.1.o
54# RUN: llvm-readobj --symbols %t.ksym.1.o \
55# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK
56# RUN: llvm-strip --discard-all --keep-symbol='f*' %t.o -o %t.ksym.2.o
57# RUN: cmp %t.ksym.1.o %t.ksym.2.o
58
59# RUN: llvm-objcopy --discard-all -w --keep-symbol='f*' %t.o %t.ksym.3.o
60# RUN: llvm-readobj --symbols %t.ksym.3.o \
61# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM
62# RUN: llvm-strip --discard-all -w --keep-symbol='f*' %t.o -o %t.ksym.4.o
63# RUN: cmp %t.ksym.3.o %t.ksym.4.o
64
65## --localize-symbol:
66## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
67# RUN: llvm-objcopy --localize-symbol='*' %t.globsym.2.o %t.localsym.1.o
68# RUN: llvm-readobj --symbols %t.localsym.1.o \
69# RUN:   | FileCheck %s --implicit-check-not=Name: \
70# RUN:       --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
71
72# RUN: llvm-objcopy -w --localize-symbol='*' %t.globsym.2.o %t.localsym.2.o
73# RUN: llvm-readobj --symbols %t.localsym.2.o \
74# RUN:   | FileCheck %s --implicit-check-not=Name: \
75# RUN:       --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
76
77## --strip-symbol:
78# RUN: llvm-objcopy --strip-symbol='f*' %t.o %t.stripsym.1.o
79# RUN: llvm-readobj --symbols %t.stripsym.1.o \
80# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM,BAR-SYM
81# RUN: llvm-strip --strip-symbol='f*' %t.o -o %t.stripsym.2.o
82# RUN: cmp %t.stripsym.1.o %t.stripsym.2.o
83
84# RUN: llvm-objcopy -w --strip-symbol='f*' %t.o %t.stripsym.3.o
85# RUN: llvm-readobj --symbols %t.stripsym.3.o \
86# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR-SYM
87# RUN: llvm-strip -w --strip-symbol='f*' %t.o -o %t.stripsym.4.o
88# RUN: cmp %t.stripsym.3.o %t.stripsym.4.o
89
90## --strip-unneeded-symbol:
91# RUN: llvm-objcopy --strip-unneeded-symbol='f*' %t.o %t.stripunsym.1.o
92# RUN: llvm-readobj --symbols %t.stripunsym.1.o \
93# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,FOO-SYM,BAR-SYM
94
95# RUN: llvm-objcopy -w --strip-unneeded-symbol='f*' %t.o %t.stripunsym.2.o
96# RUN: llvm-readobj --symbols %t.stripunsym.2.o \
97# RUN:   | FileCheck %s --implicit-check-not=Name: --check-prefixes=CHECK,BAR-SYM
98
99## --weaken-symbol:
100## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
101# RUN: llvm-objcopy --weaken-symbol='*' %t.globsym.2.o %t.weaksym.1.o
102# RUN: llvm-readobj --symbols %t.weaksym.1.o \
103# RUN:   | FileCheck %s --implicit-check-not=Name: \
104# RUN:       --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
105
106# RUN: llvm-objcopy -w --weaken-symbol='*' %t.globsym.2.o %t.weaksym.2.o
107# RUN: llvm-readobj --symbols %t.weaksym.2.o \
108# RUN:   | FileCheck %s --implicit-check-not=Name: \
109# RUN:       --check-prefixes=CHECK,WEAK,FOO-SYM,BAR-SYM
110
111## --keep-global-symbol:
112## Note: Use %t.globsym.2.o instead of %t.o since those symbols are global.
113# RUN: llvm-objcopy --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.1.o
114# RUN: llvm-readobj --symbols %t.keepgsym.1.o \
115# RUN:   | FileCheck %s --implicit-check-not=Name: \
116# RUN:       --check-prefixes=CHECK,LOCAL,FOO-SYM,BAR-SYM
117
118# RUN: llvm-objcopy -w --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.2.o
119# RUN: llvm-readobj --symbols %t.keepgsym.2.o \
120# RUN:   | FileCheck %s --implicit-check-not=Name: \
121# RUN:       --check-prefixes=CHECK,GLOBAL,FOO-SYM,BAR-SYM
122
123## Check that -w is accepted as an alias for --wildcard.
124# RUN: llvm-objcopy --wildcard --keep-global-symbol='*' %t.globsym.2.o %t.keepgsym.3.o
125# RUN: cmp %t.keepgsym.2.o %t.keepgsym.3.o
126
127# CHECK:   LoadName:
128# CHECK:   Name: (0)
129
130# FOO-SEC: Name: .foo
131
132# FOO-SYM: Name: foo
133# GLOBAL:  Binding: Global
134# WEAK:    Binding: Weak
135# LOCAL:   Binding: Local
136
137# BAR-SEC: Name: .bar
138# BAR-SYM: Name: bar
139# GLOBAL:  Binding: Global
140# WEAK:    Binding: Weak
141# LOCAL:   Binding: Local
142
143# SEC:     Name: .shstrtab
144
145!ELF
146FileHeader:
147  Class:     ELFCLASS64
148  Data:      ELFDATA2LSB
149  Type:      ET_REL
150  Machine:   EM_X86_64
151Sections:
152  - Name:    .foo
153    Type:    SHT_PROGBITS
154  - Name:    .bar
155    Type:    SHT_PROGBITS
156Symbols:
157  - Name:    foo
158    Type:    STT_FUNC
159    Section: .foo
160  - Name:    bar
161    Type:    STT_FUNC
162    Section: .foo
163