344 lines · plain
1# REQUIRES: x862 3# RUN: rm -rf %t; split-file %s %t4# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/empty.o5# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/default.s -o %t/default.o6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/lazydef.s -o %t/lazydef.o7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %t/too-many-warnings.s -o %t/too-many-warnings.o8# RUN: llvm-ar --format=darwin rcs %t/lazydef.a %t/lazydef.o9 10## Check that mixing exported and unexported symbol options yields an error11# 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 %s14#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 %s18#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 %s22#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 %s26#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 %s30 31# CONFLICT: error: cannot use both -exported_symbol* and -unexported_symbol* options32 33# CONFLICT-NO-EXPORTS: error: cannot use both -exported_symbol* and -no_exported_symbols options34 35## Check that an exported literal name with no symbol definition yields an error36## but that an exported glob-pattern with no matching symbol definition is OK37# 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 %s41 42# UNDEF: error: undefined symbol: absent_literal43# UNDEF-NEXT: >>> referenced by -exported_symbol(s_list)44# UNDEF-NOT: error: {{.*}} absent_gl{{.}}b45 46## Check that dynamic_lookup suppresses the error47# RUN: %lld -dylib %t/default.o -undefined dynamic_lookup -o %t/dyn-lookup \48# RUN: -exported_symbol absent_literal49# RUN: llvm-objdump --macho --syms %t/dyn-lookup | FileCheck %s --check-prefix=DYN50# DYN: *UND* absent_literal51 52## Check that exported literal symbols are present in output's53## symbol table, even lazy symbols which would otherwise be omitted54# RUN: %lld -dylib %t/default.o %t/lazydef.a -o %t/lazydef \55# RUN: -exported_symbol _keep_globl \56# RUN: -exported_symbol _keep_lazy57# RUN: llvm-objdump --syms %t/lazydef | \58# RUN: FileCheck --check-prefix=EXPORT %s59 60# EXPORT-DAG: g F __TEXT,__text _keep_globl61# EXPORT-DAG: g F __TEXT,__text _keep_lazy62 63## Check that exported symbol is global64# 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 %s67 68# PRIVATE: warning: cannot export hidden symbol _private_extern69 70## Check that we still hide the other symbols despite the warning71# RUN: llvm-objdump --macho --exports-trie %t/hidden-export | \72# RUN: FileCheck --check-prefix=EMPTY-TRIE %s73# EMPTY-TRIE: Exports trie:74# EMPTY-TRIE-EMPTY:75 76## Check that the export trie is unaltered77# RUN: %lld -dylib %t/default.o -o %t/default78# RUN: llvm-objdump --macho --exports-trie %t/default | \79# RUN: FileCheck --check-prefix=DEFAULT %s80 81# DEFAULT-LABEL: Exports trie:82# DEFAULT-DAG: _hide_globl83# DEFAULT-DAG: _keep_globl84# DEFAULT-NOT: _private_extern85 86## Check that the export trie is shaped by an allow list and then87## by a deny list. Both lists are designed to yield the same result.88 89## Check the allow list90# RUN: %lld -dylib %t/default.o -o %t/allowed \91# RUN: -exported_symbol _keep_globl92# RUN: llvm-objdump --macho --exports-trie %t/allowed | \93# RUN: FileCheck --check-prefix=TRIE %s94# RUN: llvm-nm -m %t/allowed | \95# RUN: FileCheck --check-prefix=NM %s96 97## Check the deny list98# RUN: %lld -dylib %t/default.o -o %t/denied \99# RUN: -unexported_symbol _hide_globl100# RUN: llvm-objdump --macho --exports-trie %t/denied | \101# RUN: FileCheck --check-prefix=TRIE %s102# RUN: llvm-nm -m %t/denied | \103# RUN: FileCheck --check-prefix=NM %s104 105# TRIE-LABEL: Exports trie:106# TRIE-DAG: _keep_globl107# TRIE-NOT: _hide_globl108# TRIE-NOT: _private_extern109 110# NM-DAG: external _keep_globl111# NM-DAG: non-external (was a private external) _hide_globl112# NM-DAG: non-external (was a private external) _private_extern113 114# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \115# RUN: %t/symdefs.s -o %t/symdefs.o116 117## Check that only string-literal patterns match118## Check that comments and blank lines are stripped from symbol list119# RUN: %lld -dylib %t/symdefs.o -o %t/literal \120# RUN: -exported_symbols_list %t/literals.txt \121# RUN: -exported_symbol singleton122# RUN: llvm-objdump --macho --exports-trie %t/literal | \123# RUN: FileCheck --check-prefix=LITERAL %s124 125# LITERAL-DAG: literal_only126# LITERAL-DAG: literal_also127# LITERAL-DAG: globby_also128# LITERAL-DAG: singleton129# LITERAL-NOT: globby_only130 131## Check that only glob patterns match132## Check that comments and blank lines are stripped from symbol list133# RUN: %lld -dylib %t/symdefs.o -o %t/globby \134# RUN: -exported_symbols_list %t/globbys.txt135# RUN: llvm-objdump --macho --exports-trie %t/globby | \136# RUN: FileCheck --check-prefix=GLOBBY %s137 138# GLOBBY-DAG: literal_also139# GLOBBY-DAG: globby_only140# GLOBBY-DAG: globby_also141# GLOBBY-NOT: literal_only142 143# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \144# RUN: %t/autohide.s -o %t/autohide.o145# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \146# RUN: %t/autohide-private-extern.s -o %t/autohide-private-extern.o147# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \148# RUN: %t/glob-private-extern.s -o %t/glob-private-extern.o149# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \150# RUN: %t/weak-private-extern.s -o %t/weak-private-extern.o151## Test that we can export the autohide symbol but not when it's also152## private-extern153# RUN: %lld -dylib -exported_symbol "_foo" %t/autohide.o -o %t/exp-autohide.dylib154# RUN: llvm-nm -g %t/exp-autohide.dylib | FileCheck %s --check-prefix=EXP-AUTOHIDE155 156# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \157# RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE158 159# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \160# RUN: %t/glob-private-extern.o -o /dev/null 2>&1 | \161# RUN: FileCheck %s --check-prefix=AUTOHIDE-PRIVATE162 163# RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \164# RUN: %t/weak-private-extern.o -o /dev/null 2>&1 | \165# RUN: FileCheck %s --check-prefix=AUTOHIDE-PRIVATE166 167## Test that exported hidden symbols are still treated as a liveness root.168## This previously used to crash when enabling -dead_strip since it's unconventional169## to add treat private extern symbols as a liveness root.170# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \171# RUN: -dead_strip -o %t/exported-hidden172# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP173 174# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \175# RUN: -dead_strip %t/glob-private-extern.o -o %t/exported-hidden176# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP177 178# RUN: %no-fatal-warnings-lld -dylib -exported_symbol "_foo" %t/autohide.o \179# RUN: -dead_strip %t/weak-private-extern.o -o %t/exported-hidden180# RUN: llvm-nm -m %t/exported-hidden | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE-DEAD-STRIP181 182# EXP-AUTOHIDE: T _foo183# AUTOHIDE-PRIVATE: error: cannot export hidden symbol _foo184# AUTOHIDE-PRIVATE-DEAD-STRIP: (__TEXT,__text) non-external (was a private external) _foo185 186## Test not exporting any symbols187# RUN: %lld -dylib %t/symdefs.o -o %t/noexports -exported_symbols_list /dev/null188# RUN: llvm-objdump --macho --exports-trie %t/noexports | FileCheck --check-prefix=NOEXPORTS %s189# RUN: %lld -dylib %t/symdefs.o -o %t/noexports -no_exported_symbols190# RUN: llvm-objdump --macho --exports-trie %t/noexports | FileCheck --check-prefix=NOEXPORTS %s191 192# NOEXPORTS-NOT: globby_also193# NOEXPORTS-NOT: globby_only194# NOEXPORTS-NOT: literal_also195# NOEXPORTS-NOT: literal_only196 197# RUN: %lld -dylib %t/default.o -o %t/libdefault.dylib198# RUN: %lld -dylib %t/empty.o %t/libdefault.dylib -exported_symbol _keep_globl \199# RUN: -exported_symbol _undef -exported_symbol _tlv \200# RUN: -undefined dynamic_lookup -o %t/reexport-dylib201# RUN: llvm-objdump --macho --exports-trie %t/reexport-dylib202 203# REEXPORT: Exports trie:204# REEXPORT-NEXT: [re-export] _tlv [per-thread] (from libdefault)205# REEXPORT-NEXT: [re-export] _keep_globl (from libdefault)206# REEXPORT-NEXT: [re-export] _undef (from unknown)207 208## -unexported_symbol will not make us re-export symbols in dylibs.209# RUN: %lld -dylib %t/default.o -o %t/libdefault.dylib210# RUN: %lld -dylib %t/empty.o %t/libdefault.dylib -unexported_symbol _tlv \211# RUN: -o %t/unexport-dylib212# RUN: llvm-objdump --macho --exports-trie %t/unexport-dylib | FileCheck %s \213# RUN: --check-prefix=EMPTY-TRIE214 215## Check that warnings are truncated to the first 3 only.216# RUN: %no-fatal-warnings-lld -dylib %t/too-many-warnings.o -o %t/too-many.out \217# RUN: -exported_symbol "_private_extern*" 2>&1 | \218# RUN: FileCheck --check-prefix=TRUNCATE %s219 220# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}221# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}222# TRUNCATE: warning: cannot export hidden symbol _private_extern{{.+}}223# TRUNCATE: warning: <... 7 more similar warnings...>224# TRUNCATE-EMPTY:225 226#--- default.s227 228.globl _keep_globl, _hide_globl, _tlv229_keep_globl:230 retq231_hide_globl:232 retq233.private_extern _private_extern234_private_extern:235 retq236_private:237 retq238 239.section __DATA,__thread_vars,thread_local_variables240_tlv:241 242#--- lazydef.s243 244.globl _keep_lazy245_keep_lazy:246 retq247 248#--- symdefs.s249 250.globl literal_only, literal_also, globby_only, globby_also, singleton251literal_only:252 retq253literal_also:254 retq255globby_only:256 retq257globby_also:258 retq259singleton:260 retq261 262#--- literals.txt263 264 literal_only # comment265 literal_also266 267# globby_only268 globby_also269 270#--- globbys.txt271 272# literal_only273 l?ter[aeiou]l_*[^y] # comment274 275 *gl?bby_*276 277#--- autohide.s278.globl _foo279.weak_def_can_be_hidden _foo280_foo:281 retq282 283#--- autohide-private-extern.s284.globl _foo285.weak_def_can_be_hidden _foo286.private_extern _foo287_foo:288 retq289 290#--- glob-private-extern.s291.global _foo292.private_extern _foo293_foo:294 retq295 296#--- weak-private-extern.s297.global _foo298.weak_definition _foo299.private_extern _foo300_foo:301 retq302 303#--- too-many-warnings.s304.private_extern _private_extern1305.private_extern _private_extern2306.private_extern _private_extern3307.private_extern _private_extern4308.private_extern _private_extern5309.private_extern _private_extern6310.private_extern _private_extern7311.private_extern _private_extern8312.private_extern _private_extern9313.private_extern _private_extern10314 315_private_extern1:316 retq317 318_private_extern2:319 retq320 321_private_extern3:322 retq323 324_private_extern4:325 retq326 327_private_extern5:328 retq329 330_private_extern6:331 retq332 333_private_extern7:334 retq335 336_private_extern8:337 retq338 339_private_extern9:340 retq341 342_private_extern10:343 retq344