1# REQUIRES: aarch64
2
3## --no-leading-lines is needed for .tbd files.
4# RUN: rm -rf %t; split-file --no-leading-lines %s %t
5
6# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %t/foo.o %t/foo.s
7# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o %t/bar.o %t/bar.s
8
9## MH_APP_EXTENSION_SAFE is only set on dylibs, and only if requested.
10# RUN: %lld -arch arm64 -dylib -o %t/foo.dylib %t/foo.o
11# RUN: llvm-otool -hv %t/foo.dylib | FileCheck --check-prefix=NOAPPEXT %s
12# RUN: %lld -arch arm64 -dylib -o %t/foo-appext.dylib %t/foo.o \
13# RUN:     -application_extension
14# RUN: llvm-otool -hv %t/foo-appext.dylib | FileCheck --check-prefix=APPEXT %s
15# RUN: %lld -arch arm64 -dylib -o %t/foo-noappext.dylib %t/foo.o \
16# RUN:     -application_extension -no_application_extension
17# RUN: llvm-otool -hv %t/foo-noappext.dylib \
18# RUN:     | FileCheck --check-prefix=NOAPPEXT %s
19# RUN: %lld -arch arm64 -bundle -o %t/foo.so %t/foo.o \
20# RUN:     -application_extension
21# RUN: llvm-otool -hv %t/foo.so | FileCheck --check-prefix=NOAPPEXT %s
22
23# APPEXT: APP_EXTENSION_SAFE
24# NOAPPEXT-NOT: APP_EXTENSION_SAFE
25
26## The warning is emitted for all target types.
27# RUN: %lld -arch arm64 -dylib -o %t/bar.dylib %t/bar.o \
28# RUN:     -application_extension %t/foo-appext.dylib
29# RUN: %lld -arch arm64 -dylib -o %t/bar.dylib %t/bar.o \
30# RUN:     -application_extension -L %t -ltbd-appext
31# RUN: not %lld -arch arm64 -dylib -o %t/bar.dylib %t/bar.o \
32# RUN:     -application_extension %t/foo-noappext.dylib \
33# RUN:     2>&1 | FileCheck --check-prefix=WARN %s
34# RUN: not %lld -arch arm64 -dylib -o %t/bar.dylib %t/bar.o \
35# RUN:     -application_extension -L %t -ltbd-noappext \
36# RUN:     2>&1 | FileCheck --check-prefix=WARN %s
37# RUN: not %lld -arch arm64 -bundle -o %t/bar.so %t/bar.o \
38# RUN:     -application_extension %t/foo-noappext.dylib \
39# RUN:     2>&1 | FileCheck --check-prefix=WARN %s
40# RUN: not %lld -arch arm64 -bundle -o %t/bar.so %t/bar.o \
41# RUN:     -application_extension -L %t -ltbd-noappext \
42# RUN:     2>&1 | FileCheck --check-prefix=WARN %s
43
44# WARN: using '-application_extension' with unsafe dylib:
45
46## Test we warn on dylibs loaded indirectly via reexports.
47# RUN: not %lld -arch arm64 -dylib -o %t/bar.dylib %t/bar.o \
48# RUN:     -application_extension -L %t -lbaz-noappext-reexport \
49# RUN:     -u _baz 2>&1 | FileCheck --check-prefix=WARN %s
50
51#--- foo.s
52.globl _foo
53.p2align 2
54_foo:
55  ret
56
57#--- libtbd-appext.tbd
58--- !tapi-tbd
59tbd-version: 4
60targets: [ arm64-macos ]
61uuids:
62  - target: arm64-macos
63    value:  2E994C7F-3F03-3A07-879C-55690D22BEDA
64install-name:     '/usr/lib/libtbd-appext.dylib'
65exports:
66  - targets:      [ arm64-macos ]
67    symbols:      [ _foo ]
68...
69
70#--- libtbd-noappext.tbd
71--- !tapi-tbd
72tbd-version: 4
73targets: [ arm64-macos ]
74flags: [ not_app_extension_safe ]
75uuids:
76  - target: arm64-macos
77    value:  2E994C7F-3F03-3A07-879C-55690D22BEDA
78install-name:     '/usr/lib/libtbd-noappext.dylib'
79exports:
80  - targets:      [ arm64-macos ]
81    symbols:      [ _foo ]
82...
83
84#--- bar.s
85.globl _bar
86.p2align 2
87_bar:
88  ret
89
90#--- libbaz-noappext-reexport.tbd
91--- !tapi-tbd
92tbd-version:      4
93targets:          [ arm64-macos ]
94uuids:
95  - target:       arm64-macos
96    value:        00000000-0000-0000-0000-000000000001
97install-name:     '/usr/lib/libbaz.dylib'
98reexported-libraries:
99  - targets:      [ arm64-macos ]
100    libraries:    [ '/usr/lib/libbaz-noappext-reexported.dylib']
101--- !tapi-tbd
102tbd-version:      4
103targets:          [ arm64-macos ]
104flags: [ not_app_extension_safe ]
105uuids:
106  - target:       arm64-macos
107    value:        00000000-0000-0000-0000-000000000003
108install-name:     '/usr/lib/libbaz-noappext-reexported.dylib'
109parent-umbrella:
110  - targets:      [ arm64-macos ]
111    umbrella:     baz
112exports:
113  - targets:      [ arm64-macos ]
114    symbols:      [ _baz ]
115...
116