llvm-project
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:
228retq
229_hide_globl:
230retq
231.private_extern _private_extern
232_private_extern:
233retq
234_private:
235retq
236
237.section __DATA,__thread_vars,thread_local_variables
238_tlv:
239
240#--- lazydef.s
241
242.globl _keep_lazy
243_keep_lazy:
244retq
245
246#--- symdefs.s
247
248.globl literal_only, literal_also, globby_only, globby_also
249literal_only:
250retq
251literal_also:
252retq
253globby_only:
254retq
255globby_also:
256retq
257
258#--- literals.txt
259
260literal_only # comment
261literal_also
262
263# globby_only
264globby_also
265
266#--- globbys.txt
267
268# literal_only
269l?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:
277retq
278
279#--- autohide-private-extern.s
280.globl _foo
281.weak_def_can_be_hidden _foo
282.private_extern _foo
283_foo:
284retq
285
286#--- glob-private-extern.s
287.global _foo
288.private_extern _foo
289_foo:
290retq
291
292#--- weak-private-extern.s
293.global _foo
294.weak_definition _foo
295.private_extern _foo
296_foo:
297retq
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:
312retq
313
314_private_extern2:
315retq
316
317_private_extern3:
318retq
319
320_private_extern4:
321retq
322
323_private_extern5:
324retq
325
326_private_extern6:
327retq
328
329_private_extern7:
330retq
331
332_private_extern8:
333retq
334
335_private_extern9:
336retq
337
338_private_extern10:
339retq
340