llvm-project

Форк
0
/
export-options.s 
339 строк · 11.2 Кб
1
# REQUIRES: x86
2

3
# RUN: rm -rf %t; split-file %s %t
4
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/empty.o
5
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/default.s -o %t/default.o
6
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/lazydef.s -o %t/lazydef.o
7
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/too-many-warnings.s -o %t/too-many-warnings.o
8
# RUN: llvm-ar --format=darwin rcs %t/lazydef.a %t/lazydef.o
9

10
## Check that mixing exported and unexported symbol options yields an error
11
# RUN: not %lld -dylib %t/default.o -o /dev/null \
12
# RUN:         -exported_symbol a -unexported_symbol b 2>&1 | \
13
# RUN:     FileCheck --check-prefix=CONFLICT %s
14
#
15
# RUN: not %lld -dylib %t/default.o -o /dev/null \
16
# RUN:         -exported_symbols_list /dev/null -unexported_symbol b 2>&1 | \
17
# RUN:     FileCheck --check-prefix=CONFLICT %s
18
#
19
# RUN: not %lld -dylib %t/default.o -o /dev/null \
20
# RUN:         -no_exported_symbols -unexported_symbol b 2>&1 | \
21
# RUN:     FileCheck --check-prefix=CONFLICT %s
22
#
23
# RUN: not %lld -dylib %t/default.o -o /dev/null \
24
# RUN:         -no_exported_symbols -exported_symbol b 2>&1 | \
25
# RUN:     FileCheck --check-prefix=CONFLICT-NO-EXPORTS %s
26
#
27
# RUN: not %lld -dylib %t/default.o -o /dev/null \
28
# RUN:         -no_exported_symbols -exported_symbols_list %t/literals.txt 2>&1 | \
29
# RUN:     FileCheck --check-prefix=CONFLICT-NO-EXPORTS %s
30

31
# CONFLICT: error: cannot use both -exported_symbol* and -unexported_symbol* options
32

33
# CONFLICT-NO-EXPORTS: error: cannot use both -exported_symbol* and -no_exported_symbols options
34

35
## Check that an exported literal name with no symbol definition yields an error
36
## but that an exported glob-pattern with no matching symbol definition is OK
37
# RUN: not %lld -dylib %t/default.o -o /dev/null \
38
# RUN:         -exported_symbol absent_literal \
39
# RUN:         -exported_symbol absent_gl?b 2>&1 | \
40
# RUN:     FileCheck --check-prefix=UNDEF %s
41

42
# UNDEF: error: undefined symbol: absent_literal
43
# UNDEF-NEXT: >>> referenced by -exported_symbol(s_list)
44
# UNDEF-NOT: error: {{.*}} absent_gl{{.}}b
45

46
## Check that dynamic_lookup suppresses the error
47
# RUN: %lld -dylib %t/default.o -undefined dynamic_lookup -o %t/dyn-lookup \
48
# RUN:      -exported_symbol absent_literal
49
# RUN: llvm-objdump --macho --syms %t/dyn-lookup | FileCheck %s --check-prefix=DYN
50
# DYN: *UND* absent_literal
51

52
## Check that exported literal symbols are present in output's
53
## symbol table, even lazy symbols which would otherwise be omitted
54
# RUN: %lld -dylib %t/default.o %t/lazydef.a -o %t/lazydef \
55
# RUN:         -exported_symbol _keep_globl \
56
# RUN:         -exported_symbol _keep_lazy
57
# RUN: llvm-objdump --syms %t/lazydef | \
58
# RUN:     FileCheck --check-prefix=EXPORT %s
59

60
# EXPORT-DAG: g     F __TEXT,__text _keep_globl
61
# EXPORT-DAG: g     F __TEXT,__text _keep_lazy
62

63
## Check that exported symbol is global
64
# RUN: %no-fatal-warnings-lld -dylib %t/default.o -o %t/hidden-export \
65
# RUN:         -exported_symbol _private_extern 2>&1 | \
66
# RUN:     FileCheck --check-prefix=PRIVATE %s
67

68
# PRIVATE: warning: cannot export hidden symbol _private_extern
69

70
## Check that we still hide the other symbols despite the warning
71
# RUN: llvm-objdump --macho --exports-trie %t/hidden-export | \
72
# RUN:     FileCheck --check-prefix=EMPTY-TRIE %s
73
# EMPTY-TRIE:       Exports trie:
74
# EMPTY-TRIE-EMPTY:
75

76
## Check that the export trie is unaltered
77
# RUN: %lld -dylib %t/default.o -o %t/default
78
# RUN: llvm-objdump --macho --exports-trie %t/default | \
79
# RUN:     FileCheck --check-prefix=DEFAULT %s
80

81
# DEFAULT-LABEL: Exports trie:
82
# DEFAULT-DAG:   _hide_globl
83
# DEFAULT-DAG:   _keep_globl
84
# DEFAULT-NOT:   _private_extern
85

86
## Check that the export trie is shaped by an allow list and then
87
## by a deny list. Both lists are designed to yield the same result.
88

89
## Check the allow list
90
# RUN: %lld -dylib %t/default.o -o %t/allowed \
91
# RUN:     -exported_symbol _keep_globl
92
# RUN: llvm-objdump --macho --exports-trie %t/allowed | \
93
# RUN:     FileCheck --check-prefix=TRIE %s
94
# RUN: llvm-nm -m %t/allowed | \
95
# RUN:     FileCheck --check-prefix=NM %s
96

97
## Check the deny list
98
# RUN: %lld -dylib %t/default.o -o %t/denied \
99
# RUN:     -unexported_symbol _hide_globl
100
# RUN: llvm-objdump --macho --exports-trie %t/denied | \
101
# RUN:     FileCheck --check-prefix=TRIE %s
102
# RUN: llvm-nm -m %t/denied | \
103
# RUN:     FileCheck --check-prefix=NM %s
104

105
# TRIE-LABEL: Exports trie:
106
# TRIE-DAG:   _keep_globl
107
# TRIE-NOT:   _hide_globl
108
# TRIE-NOT:   _private_extern
109

110
# NM-DAG: external _keep_globl
111
# NM-DAG: non-external (was a private external) _hide_globl
112
# NM-DAG: non-external (was a private external) _private_extern
113

114
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
115
# RUN:     %t/symdefs.s -o %t/symdefs.o
116

117
## Check that only string-literal patterns match
118
## Check that comments and blank lines are stripped from symbol list
119
# RUN: %lld -dylib %t/symdefs.o -o %t/literal \
120
# RUN:     -exported_symbols_list %t/literals.txt
121
# RUN: llvm-objdump --macho --exports-trie %t/literal | \
122
# RUN:     FileCheck --check-prefix=LITERAL %s
123

124
# LITERAL-DAG: literal_only
125
# LITERAL-DAG: literal_also
126
# LITERAL-DAG: globby_also
127
# LITERAL-NOT: globby_only
128

129
## Check that only glob patterns match
130
## Check that comments and blank lines are stripped from symbol list
131
# RUN: %lld -dylib %t/symdefs.o -o %t/globby \
132
# RUN:     -exported_symbols_list %t/globbys.txt
133
# RUN: llvm-objdump --macho --exports-trie %t/globby | \
134
# RUN:     FileCheck --check-prefix=GLOBBY %s
135

136
# GLOBBY-DAG: literal_also
137
# GLOBBY-DAG: globby_only
138
# GLOBBY-DAG: globby_also
139
# GLOBBY-NOT: literal_only
140

141
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
142
# RUN:     %t/autohide.s -o %t/autohide.o
143
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
144
# RUN:     %t/autohide-private-extern.s -o %t/autohide-private-extern.o
145
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
146
# RUN:     %t/glob-private-extern.s -o %t/glob-private-extern.o
147
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
148
# RUN:     %t/weak-private-extern.s -o %t/weak-private-extern.o
149
## Test that we can export the autohide symbol but not when it's also
150
## private-extern
151
# RUN: %lld -dylib -exported_symbol "_foo" %t/autohide.o -o %t/exp-autohide.dylib
152
# RUN: llvm-nm -g %t/exp-autohide.dylib | FileCheck %s --check-prefix=EXP-AUTOHIDE
153

154
# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \
155
# RUN:   -o /dev/null  2>&1 | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
156

157
# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \
158
# RUN:   %t/glob-private-extern.o -o /dev/null 2>&1 | \
159
# RUN:   FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
160

161
# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \
162
# RUN:   %t/weak-private-extern.o -o /dev/null 2>&1 | \
163
# RUN:   FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
164

165
## Test that exported hidden symbols are still treated as a liveness root.
166
## This previously used to crash when enabling -dead_strip since it's unconventional
167
## to add treat private extern symbols as a liveness root.
168
# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \
169
# RUN:   -dead_strip -o %t/exported-hidden
170
# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP
171

172
# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \
173
# RUN:   -dead_strip %t/glob-private-extern.o -o %t/exported-hidden
174
# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP
175

176
# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \
177
# RUN:   -dead_strip %t/weak-private-extern.o -o %t/exported-hidden
178
# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP
179

180
# EXP-AUTOHIDE: T _foo
181
# AUTOHIDE-PRIVATE: error: cannot export hidden symbol _foo
182
# AUTOHIDE-PRIVATE-DEAD-STRIP: (__TEXT,__text) non-external (was a private external) _foo
183

184
## Test not exporting any symbols
185
# RUN: %lld -dylib %t/symdefs.o -o %t/noexports -exported_symbols_list /dev/null
186
# RUN: llvm-objdump --macho --exports-trie %t/noexports | FileCheck --check-prefix=NOEXPORTS %s
187
# RUN: %lld -dylib %t/symdefs.o -o %t/noexports -no_exported_symbols
188
# RUN: llvm-objdump --macho --exports-trie %t/noexports | FileCheck --check-prefix=NOEXPORTS %s
189

190
# NOEXPORTS-NOT: globby_also
191
# NOEXPORTS-NOT: globby_only
192
# NOEXPORTS-NOT: literal_also
193
# NOEXPORTS-NOT: literal_only
194

195
# RUN: %lld -dylib %t/default.o -o %t/libdefault.dylib
196
# RUN: %lld -dylib %t/empty.o %t/libdefault.dylib -exported_symbol _keep_globl \
197
# RUN:   -exported_symbol _undef -exported_symbol _tlv \
198
# RUN:   -undefined dynamic_lookup -o %t/reexport-dylib
199
# RUN: llvm-objdump --macho --exports-trie %t/reexport-dylib
200

201
# REEXPORT:      Exports trie:
202
# REEXPORT-NEXT: [re-export] _tlv [per-thread] (from libdefault)
203
# REEXPORT-NEXT: [re-export] _keep_globl (from libdefault)
204
# REEXPORT-NEXT: [re-export] _undef (from unknown)
205

206
## -unexported_symbol will not make us re-export symbols in dylibs.
207
# RUN: %lld -dylib %t/default.o -o %t/libdefault.dylib
208
# RUN: %lld -dylib %t/empty.o %t/libdefault.dylib -unexported_symbol _tlv \
209
# RUN:   -o %t/unexport-dylib
210
# RUN: llvm-objdump --macho --exports-trie %t/unexport-dylib | FileCheck %s \
211
# RUN:   --check-prefix=EMPTY-TRIE
212

213
## Check that warnings are truncated to the first 3 only.
214
# RUN: %no-fatal-warnings-lld -dylib %t/too-many-warnings.o -o %t/too-many.out \
215
# RUN:         -exported_symbol "_private_extern*" 2>&1 | \
216
# RUN:     FileCheck --check-prefix=TRUNCATE %s
217

218
# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
219
# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
220
# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}
221
# TRUNCATE: warning: <... 7 more similar warnings...>
222
# TRUNCATE-EMPTY:
223

224
#--- default.s
225

226
.globl _keep_globl, _hide_globl, _tlv
227
_keep_globl:
228
  retq
229
_hide_globl:
230
  retq
231
.private_extern _private_extern
232
_private_extern:
233
  retq
234
_private:
235
  retq
236

237
.section __DATA,__thread_vars,thread_local_variables
238
_tlv:
239

240
#--- lazydef.s
241

242
.globl _keep_lazy
243
_keep_lazy:
244
  retq
245

246
#--- symdefs.s
247

248
.globl literal_only, literal_also, globby_only, globby_also
249
literal_only:
250
  retq
251
literal_also:
252
  retq
253
globby_only:
254
  retq
255
globby_also:
256
  retq
257

258
#--- literals.txt
259

260
  literal_only # comment
261
  literal_also
262

263
# globby_only
264
  globby_also
265

266
#--- globbys.txt
267

268
# literal_only
269
  l?ter[aeiou]l_*[^y] # comment
270

271
  *gl?bby_*
272

273
#--- autohide.s
274
.globl _foo
275
.weak_def_can_be_hidden _foo
276
_foo:
277
  retq
278

279
#--- autohide-private-extern.s
280
.globl _foo
281
.weak_def_can_be_hidden _foo
282
.private_extern _foo
283
_foo:
284
  retq
285

286
#--- glob-private-extern.s
287
.global _foo
288
.private_extern _foo
289
_foo:
290
  retq
291

292
#--- weak-private-extern.s
293
.global _foo
294
.weak_definition _foo
295
.private_extern _foo
296
_foo:
297
  retq
298

299
#--- too-many-warnings.s
300
.private_extern _private_extern1
301
.private_extern _private_extern2
302
.private_extern _private_extern3
303
.private_extern _private_extern4
304
.private_extern _private_extern5
305
.private_extern _private_extern6
306
.private_extern _private_extern7
307
.private_extern _private_extern8
308
.private_extern _private_extern9
309
.private_extern _private_extern10
310

311
_private_extern1:
312
  retq
313

314
_private_extern2:
315
  retq
316

317
_private_extern3:
318
  retq
319

320
_private_extern4:
321
  retq
322

323
_private_extern5:
324
  retq
325

326
_private_extern6:
327
  retq
328

329
_private_extern7:
330
  retq
331

332
_private_extern8:
333
  retq
334

335
_private_extern9:
336
  retq
337

338
_private_extern10:
339
  retq
340

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.