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
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
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
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
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
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
31 # CONFLICT: error: cannot use both -exported_symbol* and -unexported_symbol* options
33 # CONFLICT-NO-EXPORTS: error: cannot use both -exported_symbol* and -no_exported_symbols options
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
42 # UNDEF: error: undefined symbol: absent_literal
43 # UNDEF-NEXT: >>> referenced by -exported_symbol(s_list)
44 # UNDEF-NOT: error: {{.*}} absent_gl{{.}}b
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
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
60 # EXPORT-DAG: g F __TEXT,__text _keep_globl
61 # EXPORT-DAG: g F __TEXT,__text _keep_lazy
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
68 # PRIVATE: warning: cannot export hidden symbol _private_extern
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:
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
81 # DEFAULT-LABEL: Exports trie:
82 # DEFAULT-DAG: _hide_globl
83 # DEFAULT-DAG: _keep_globl
84 # DEFAULT-NOT: _private_extern
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.
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
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
105 # TRIE-LABEL: Exports trie:
106 # TRIE-DAG: _keep_globl
107 # TRIE-NOT: _hide_globl
108 # TRIE-NOT: _private_extern
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
114 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
115 # RUN: %t/symdefs.s -o %t/symdefs.o
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
124 # LITERAL-DAG: literal_only
125 # LITERAL-DAG: literal_also
126 # LITERAL-DAG: globby_also
127 # LITERAL-NOT: globby_only
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
136 # GLOBBY-DAG: literal_also
137 # GLOBBY-DAG: globby_only
138 # GLOBBY-DAG: globby_also
139 # GLOBBY-NOT: literal_only
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
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
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
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
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
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
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
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
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
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
190 # NOEXPORTS-NOT: globby_also
191 # NOEXPORTS-NOT: globby_only
192 # NOEXPORTS-NOT: literal_also
193 # NOEXPORTS-NOT: literal_only
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
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)
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
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
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...>
226 .globl _keep_globl, _hide_globl, _tlv
231 .private_extern _private_extern
237 .section __DATA,__thread_vars,thread_local_variables
248 .globl literal_only, literal_also, globby_only, globby_also
260 literal_only
# comment
269 l?ter
[aeiou
]l_
*[^y
] # comment
275 .weak_def_can_be_hidden _foo
279 #--- autohide-private-extern.s
281 .weak_def_can_be_hidden _foo
286 #--- glob-private-extern.s
292 #--- weak-private-extern.s
294 .weak_definition _foo
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