xref: /llvm-project/clang/test/InstallAPI/availability.test (revision 936519f25cb4fabc19f1241e838e938926801156)
1; RUN: rm -rf %t
2; RUN: split-file %s %t
3; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
4
5; RUN: yaml2obj %t/Availability.yaml -o %t/System/Library/Frameworks/Availability.framework/Availability
6
7; RUN: clang-installapi \
8; RUN: --target=x86_64-apple-macos13 \
9; RUN: -install_name /System/Library/Frameworks/Availability.framework/Versions/A/Availability \
10; RUN: -current_version 1 -compatibility_version 1 \
11; RUN: -F %t/System/Library/Frameworks \
12; RUN: %t/inputs.json -o %t/output.tbd \
13; RUN: --verify-against=%t/System/Library/Frameworks/Availability.framework/Availability \
14; RUN: --verify-mode=ErrorsOnly --filetype=tbd-v5 2> %t/errors.log
15; RUN: FileCheck -allow-empty -check-prefix=ERRORSONLY -input-file %t/errors.log %s
16
17; RUN: clang-installapi \
18; RUN: --target=x86_64-apple-macos13 \
19; RUN: -install_name /System/Library/Frameworks/Availability.framework/Versions/A/Availability \
20; RUN: -current_version 1 -compatibility_version 1 \
21; RUN: -F %t/System/Library/Frameworks \
22; RUN: %t/inputs.json -o %t/output-warnings.tbd \
23; RUN: --verify-against=%t/System/Library/Frameworks/Availability.framework/Availability \
24; RUN: --verify-mode=ErrorsAndWarnings 2> %t/errors.log
25; RUN: FileCheck -check-prefixes=VIOLATIONS,ERRORSANDWARNINGS -input-file %t/errors.log %s
26
27; RUN: not clang-installapi \
28; RUN: --target=x86_64-apple-macos13 \
29; RUN: -install_name /System/Library/Frameworks/Availability.framework/Versions/A/Availability \
30; RUN: -current_version 1 -compatibility_version 1 \
31; RUN: -F %t/System/Library/Frameworks \
32; RUN: %t/inputs.json -o %t/output-pedantic.tbd \
33; RUN: --verify-against=%t/System/Library/Frameworks/Availability.framework/Availability \
34; RUN: --verify-mode=Pedantic 2> %t/errors.log
35; RUN: FileCheck -check-prefixes=VIOLATIONS,PEDANTIC -input-file %t/errors.log %s
36
37; ERRORSONLY-NOT:        error
38; ERRORSONLY-NOT:        warning
39
40; ERRORSANDWARNINGS-NOT: error
41; VIOLATIONS:            warning: violations found for x86_64-apple-macos
42; VIOLATIONS:            declaration 'publicGlobalVariable' is marked unavailable, but symbol is exported in dynamic library
43; VIOLATIONS-NEXT:       extern int publicGlobalVariable NS_AVAILABLE
44; VIOLATIONS:            declaration 'Foo' is marked unavailable, but symbol is exported in dynamic library
45; VIOLATIONS-NEXT:       @interface Foo : NSObject
46; VIOLATIONS:            declaration 'publicGlobalVariable3' is marked unavailable, but symbol is exported in dynamic library
47; VIOLATIONS-NEXT:       extern int publicGlobalVariable3 __attribute__((unavailable))
48; VIOLATIONS:            declaration 'privateGlobalVariable' is marked unavailable, but symbol is exported in dynamic library
49; VIOLATIONS-NEXT:       extern int privateGlobalVariable;
50
51; ERRORSANDWARNINGS-NOT: warning
52; PEDANTIC-NOT:          error
53
54;--- inputs.json.in
55{
56  "headers": [ {
57    "path" : "DSTROOT/System/Library/Frameworks/Availability.framework/Headers/Availability.h",
58    "type" : "public"
59  },
60  {
61    "path" : "DSTROOT/System/Library/Frameworks/Availability.framework/PrivateHeaders/AvailabilityPrivate.h",
62    "type" : "private"
63  }
64  ],
65  "version": "3"
66}
67
68;--- System/Library/Frameworks/Availability.framework/Headers/AV_Defines.h
69#ifndef AV_DEFINES
70#define AV_DEFINES
71
72#define NS_AVAILABLE __attribute__((availability(macosx,introduced=NA)))
73
74@interface NSObject
75@end
76
77#endif //AV_DEFINES
78
79;--- System/Library/Frameworks/Availability.framework/PrivateHeaders/AvailabilityPrivate.h
80#import <Availability/AV_Defines.h>
81// Test private global variable.
82NS_AVAILABLE
83extern int privateGlobalVariable;
84
85;--- System/Library/Frameworks/Availability.framework/Headers/Availability.h
86#import <Availability/AV_Defines.h>
87extern int publicGlobalVariable NS_AVAILABLE;
88
89// Test public ObjC class
90NS_AVAILABLE
91@interface Foo : NSObject
92@end
93
94// Test unavailable attribute.
95#ifdef __i386__
96#define UNAVAILABLE_I386 __attribute__((unavailable))
97#else
98#define UNAVAILABLE_I386
99#endif
100extern int publicGlobalVariable2 UNAVAILABLE_I386;
101
102extern int publicGlobalVariable3 __attribute__((unavailable))
103__attribute__((availability(macosx, introduced = 10.9)));
104
105// Test obsoleted with exported variable.
106extern int publicGlobalVariable4 __attribute__((availability(
107    macosx, introduced = 10.9, deprecated = 10.10, obsoleted = 10.11)));
108// Test obsoleted with non-existent variable.
109extern int publicGlobalVariable5 __attribute__((availability(
110    macosx, introduced = 10.9, deprecated = 10.10, obsoleted = 10.11)));
111
112#ifdef __i386__
113#define OBSOLETE_I386 __attribute__((availability(macosx, obsoleted = 10.11)))
114#else
115#define OBSOLETE_I386
116#endif
117extern int publicGlobalVariable6 OBSOLETE_I386;
118
119
120/// Created from:
121// int publicGlobalVariable; int privateGlobalVariable;
122//
123// @implementation Foo
124// @end
125//
126// #ifndef __i386__
127// int publicGlobalVariable2;
128// #endif
129//
130// int publicGlobalVariable3;
131// int publicGlobalVariable4;
132//
133// #ifndef __i386__
134// int publicGlobalVariable6;
135// #endif
136;--- Availability.yaml
137--- !mach-o
138FileHeader:
139  magic:           0xFEEDFACF
140  cputype:         0x1000007
141  cpusubtype:      0x3
142  filetype:        0x6
143  ncmds:           14
144  sizeofcmds:      1312
145  flags:           0x100085
146  reserved:        0x0
147LoadCommands:
148  - cmd:             LC_SEGMENT_64
149    cmdsize:         232
150    segname:         __TEXT
151    vmaddr:          0
152    vmsize:          8192
153    fileoff:         0
154    filesize:        8192
155    maxprot:         5
156    initprot:        5
157    nsects:          2
158    flags:           0
159    Sections:
160      - sectname:        __text
161        segname:         __TEXT
162        addr:            0x1140
163        size:            0
164        offset:          0x1140
165        align:           0
166        reloff:          0x0
167        nreloc:          0
168        flags:           0x80000000
169        reserved1:       0x0
170        reserved2:       0x0
171        reserved3:       0x0
172        content:         ''
173      - sectname:        __cstring
174        segname:         __TEXT
175        addr:            0x1140
176        size:            4
177        offset:          0x1140
178        align:           0
179        reloff:          0x0
180        nreloc:          0
181        flags:           0x2
182        reserved1:       0x0
183        reserved2:       0x0
184        reserved3:       0x0
185        content:         466F6F00
186  - cmd:             LC_SEGMENT_64
187    cmdsize:         232
188    segname:         __DATA_CONST
189    vmaddr:          8192
190    vmsize:          4096
191    fileoff:         8192
192    filesize:        4096
193    maxprot:         3
194    initprot:        3
195    nsects:          2
196    flags:           16
197    Sections:
198      - sectname:        __objc_classlist
199        segname:         __DATA_CONST
200        addr:            0x2000
201        size:            8
202        offset:          0x2000
203        align:           3
204        reloff:          0x0
205        nreloc:          0
206        flags:           0x10000000
207        reserved1:       0x0
208        reserved2:       0x0
209        reserved3:       0x0
210        content:         B830000000000000
211      - sectname:        __objc_imageinfo
212        segname:         __DATA_CONST
213        addr:            0x2008
214        size:            8
215        offset:          0x2008
216        align:           0
217        reloff:          0x0
218        nreloc:          0
219        flags:           0x0
220        reserved1:       0x0
221        reserved2:       0x0
222        reserved3:       0x0
223        content:         '0000000040000000'
224  - cmd:             LC_SEGMENT_64
225    cmdsize:         312
226    segname:         __DATA
227    vmaddr:          12288
228    vmsize:          4096
229    fileoff:         12288
230    filesize:        4096
231    maxprot:         3
232    initprot:        3
233    nsects:          3
234    flags:           0
235    Sections:
236      - sectname:        __objc_const
237        segname:         __DATA
238        addr:            0x3000
239        size:            144
240        offset:          0x3000
241        align:           3
242        reloff:          0x0
243        nreloc:          0
244        flags:           0x0
245        reserved1:       0x0
246        reserved2:       0x0
247        reserved3:       0x0
248        content:         '010000002800000028000000000000000000000000000000401100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000008000000000000000000000000000000401100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
249      - sectname:        __objc_data
250        segname:         __DATA
251        addr:            0x3090
252        size:            80
253        offset:          0x3090
254        align:           3
255        reloff:          0x0
256        nreloc:          0
257        flags:           0x0
258        reserved1:       0x0
259        reserved2:       0x0
260        reserved3:       0x0
261        content:         '0000000000000000000000000000000000000000000000000000000000000000003000000000000090300000000000000000000000000000000000000000000000000000000000004830000000000000'
262      - sectname:        __common
263        segname:         __DATA
264        addr:            0x30E0
265        size:            24
266        offset:          0x0
267        align:           2
268        reloff:          0x0
269        nreloc:          0
270        flags:           0x1
271        reserved1:       0x0
272        reserved2:       0x0
273        reserved3:       0x0
274  - cmd:             LC_SEGMENT_64
275    cmdsize:         72
276    segname:         __LINKEDIT
277    vmaddr:          16384
278    vmsize:          824
279    fileoff:         16384
280    filesize:        824
281    maxprot:         1
282    initprot:        1
283    nsects:          0
284    flags:           0
285  - cmd:             LC_DYLD_INFO_ONLY
286    cmdsize:         48
287    rebase_off:      16384
288    rebase_size:     16
289    bind_off:        16400
290    bind_size:       104
291    weak_bind_off:   0
292    weak_bind_size:  0
293    lazy_bind_off:   0
294    lazy_bind_size:  0
295    export_off:      16504
296    export_size:     152
297  - cmd:             LC_SYMTAB
298    cmdsize:         24
299    symoff:          16664
300    nsyms:           14
301    stroff:          16888
302    strsize:         320
303  - cmd:             LC_DYSYMTAB
304    cmdsize:         80
305    ilocalsym:       0
306    nlocalsym:       2
307    iextdefsym:      2
308    nextdefsym:      8
309    iundefsym:       10
310    nundefsym:       4
311    tocoff:          0
312    ntoc:            0
313    modtaboff:       0
314    nmodtab:         0
315    extrefsymoff:    0
316    nextrefsyms:     0
317    indirectsymoff:  0
318    nindirectsyms:   0
319    extreloff:       0
320    nextrel:         0
321    locreloff:       0
322    nlocrel:         0
323  - cmd:             LC_ID_DYLIB
324    cmdsize:         112
325    dylib:
326      name:            24
327      timestamp:       0
328      current_version: 65536
329      compatibility_version: 65536
330    Content:         '/System/Library/Frameworks/Availability.framework/Versions/A/Availability'
331    ZeroPadBytes:    7
332  - cmd:             LC_UUID
333    cmdsize:         24
334    uuid:            4C4C4470-5555-3144-A142-4EE44DA08D2F
335  - cmd:             LC_BUILD_VERSION
336    cmdsize:         32
337    platform:        1
338    minos:           851968
339    sdk:             983040
340    ntools:          1
341    Tools:
342      - tool:            4
343        version:         1245184
344  - cmd:             LC_LOAD_DYLIB
345    cmdsize:         56
346    dylib:
347      name:            24
348      timestamp:       0
349      current_version: 14942208
350      compatibility_version: 65536
351    Content:         '/usr/lib/libobjc.A.dylib'
352    ZeroPadBytes:    8
353  - cmd:             LC_LOAD_DYLIB
354    cmdsize:         56
355    dylib:
356      name:            24
357      timestamp:       0
358      current_version: 88473600
359      compatibility_version: 65536
360    Content:         '/usr/lib/libSystem.B.dylib'
361    ZeroPadBytes:    6
362  - cmd:             LC_FUNCTION_STARTS
363    cmdsize:         16
364    dataoff:         16656
365    datasize:        8
366  - cmd:             LC_DATA_IN_CODE
367    cmdsize:         16
368    dataoff:         16664
369    datasize:        0
370LinkEditData:
371  RebaseOpcodes:
372    - Opcode:          REBASE_OPCODE_SET_TYPE_IMM
373      Imm:             1
374    - Opcode:          REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
375      Imm:             1
376      ExtraData:       [ 0x0 ]
377    - Opcode:          REBASE_OPCODE_DO_REBASE_IMM_TIMES
378      Imm:             1
379    - Opcode:          REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
380      Imm:             2
381      ExtraData:       [ 0x18 ]
382    - Opcode:          REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
383      Imm:             0
384      ExtraData:       [ 0x2, 0x40 ]
385    - Opcode:          REBASE_OPCODE_ADD_ADDR_IMM_SCALED
386      Imm:             1
387    - Opcode:          REBASE_OPCODE_DO_REBASE_IMM_TIMES
388      Imm:             2
389    - Opcode:          REBASE_OPCODE_ADD_ADDR_IMM_SCALED
390      Imm:             3
391    - Opcode:          REBASE_OPCODE_DO_REBASE_IMM_TIMES
392      Imm:             1
393    - Opcode:          REBASE_OPCODE_DONE
394      Imm:             0
395  BindOpcodes:
396    - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
397      Imm:             0
398      Symbol:          '_OBJC_METACLASS_$_NSObject'
399    - Opcode:          BIND_OPCODE_SET_TYPE_IMM
400      Imm:             1
401      Symbol:          ''
402    - Opcode:          BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
403      Imm:             1
404      Symbol:          ''
405    - Opcode:          BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
406      Imm:             2
407      ULEBExtraData:   [ 0x90 ]
408      Symbol:          ''
409    - Opcode:          BIND_OPCODE_DO_BIND
410      Imm:             0
411      Symbol:          ''
412    - Opcode:          BIND_OPCODE_DO_BIND
413      Imm:             0
414      Symbol:          ''
415    - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
416      Imm:             0
417      Symbol:          __objc_empty_cache
418    - Opcode:          BIND_OPCODE_SET_TYPE_IMM
419      Imm:             1
420      Symbol:          ''
421    - Opcode:          BIND_OPCODE_DO_BIND
422      Imm:             0
423      Symbol:          ''
424    - Opcode:          BIND_OPCODE_ADD_ADDR_ULEB
425      Imm:             0
426      ULEBExtraData:   [ 0x20 ]
427      Symbol:          ''
428    - Opcode:          BIND_OPCODE_DO_BIND
429      Imm:             0
430      Symbol:          ''
431    - Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
432      Imm:             0
433      Symbol:          '_OBJC_CLASS_$_NSObject'
434    - Opcode:          BIND_OPCODE_SET_TYPE_IMM
435      Imm:             1
436      Symbol:          ''
437    - Opcode:          BIND_OPCODE_ADD_ADDR_ULEB
438      Imm:             0
439      ULEBExtraData:   [ 0xFFFFFFFFFFFFFFF0 ]
440      Symbol:          ''
441    - Opcode:          BIND_OPCODE_DO_BIND
442      Imm:             0
443      Symbol:          ''
444    - Opcode:          BIND_OPCODE_DONE
445      Imm:             0
446      Symbol:          ''
447  ExportTrie:
448    TerminalSize:    0
449    NodeOffset:      0
450    Name:            ''
451    Flags:           0x0
452    Address:         0x0
453    Other:           0x0
454    ImportName:      ''
455    Children:
456      - TerminalSize:    0
457        NodeOffset:      5
458        Name:            _
459        Flags:           0x0
460        Address:         0x0
461        Other:           0x0
462        ImportName:      ''
463        Children:
464          - TerminalSize:    0
465            NodeOffset:      17
466            Name:            OBJC_
467            Flags:           0x0
468            Address:         0x0
469            Other:           0x0
470            ImportName:      ''
471            Children:
472              - TerminalSize:    3
473                NodeOffset:      49
474                Name:            'METACLASS_$_Foo'
475                Flags:           0x0
476                Address:         0x3090
477                Other:           0x0
478                ImportName:      ''
479              - TerminalSize:    3
480                NodeOffset:      54
481                Name:            'CLASS_$_Foo'
482                Flags:           0x0
483                Address:         0x30B8
484                Other:           0x0
485                ImportName:      ''
486          - TerminalSize:    0
487            NodeOffset:      59
488            Name:            p
489            Flags:           0x0
490            Address:         0x0
491            Other:           0x0
492            ImportName:      ''
493            Children:
494              - TerminalSize:    3
495                NodeOffset:      104
496                Name:            rivateGlobalVariable
497                Flags:           0x0
498                Address:         0x30E0
499                Other:           0x0
500                ImportName:      ''
501              - TerminalSize:    3
502                NodeOffset:      109
503                Name:            ublicGlobalVariable
504                Flags:           0x0
505                Address:         0x30E4
506                Other:           0x0
507                ImportName:      ''
508                Children:
509                  - TerminalSize:    3
510                    NodeOffset:      130
511                    Name:            '4'
512                    Flags:           0x0
513                    Address:         0x30F0
514                    Other:           0x0
515                    ImportName:      ''
516                  - TerminalSize:    3
517                    NodeOffset:      135
518                    Name:            '3'
519                    Flags:           0x0
520                    Address:         0x30EC
521                    Other:           0x0
522                    ImportName:      ''
523                  - TerminalSize:    3
524                    NodeOffset:      140
525                    Name:            '2'
526                    Flags:           0x0
527                    Address:         0x30E8
528                    Other:           0x0
529                    ImportName:      ''
530                  - TerminalSize:    3
531                    NodeOffset:      145
532                    Name:            '6'
533                    Flags:           0x0
534                    Address:         0x30F4
535                    Other:           0x0
536                    ImportName:      ''
537  NameList:
538    - n_strx:          2
539      n_type:          0xE
540      n_sect:          5
541      n_desc:          0
542      n_value:         12288
543    - n_strx:          28
544      n_type:          0xE
545      n_sect:          5
546      n_desc:          0
547      n_value:         12360
548    - n_strx:          50
549      n_type:          0xF
550      n_sect:          7
551      n_desc:          0
552      n_value:         12512
553    - n_strx:          73
554      n_type:          0xF
555      n_sect:          7
556      n_desc:          0
557      n_value:         12516
558    - n_strx:          95
559      n_type:          0xF
560      n_sect:          7
561      n_desc:          0
562      n_value:         12520
563    - n_strx:          118
564      n_type:          0xF
565      n_sect:          7
566      n_desc:          0
567      n_value:         12524
568    - n_strx:          141
569      n_type:          0xF
570      n_sect:          7
571      n_desc:          0
572      n_value:         12528
573    - n_strx:          164
574      n_type:          0xF
575      n_sect:          7
576      n_desc:          0
577      n_value:         12532
578    - n_strx:          187
579      n_type:          0xF
580      n_sect:          6
581      n_desc:          0
582      n_value:         12432
583    - n_strx:          209
584      n_type:          0xF
585      n_sect:          6
586      n_desc:          0
587      n_value:         12472
588    - n_strx:          227
589      n_type:          0x1
590      n_sect:          0
591      n_desc:          256
592      n_value:         0
593    - n_strx:          250
594      n_type:          0x1
595      n_sect:          0
596      n_desc:          256
597      n_value:         0
598    - n_strx:          277
599      n_type:          0x1
600      n_sect:          0
601      n_desc:          256
602      n_value:         0
603    - n_strx:          296
604      n_type:          0x1
605      n_sect:          0
606      n_desc:          512
607      n_value:         0
608  StringTable:
609    - ' '
610    - '__OBJC_METACLASS_RO_$_Foo'
611    - '__OBJC_CLASS_RO_$_Foo'
612    - _privateGlobalVariable
613    - _publicGlobalVariable
614    - _publicGlobalVariable2
615    - _publicGlobalVariable3
616    - _publicGlobalVariable4
617    - _publicGlobalVariable6
618    - '_OBJC_METACLASS_$_Foo'
619    - '_OBJC_CLASS_$_Foo'
620    - '_OBJC_CLASS_$_NSObject'
621    - '_OBJC_METACLASS_$_NSObject'
622    - __objc_empty_cache
623    - dyld_stub_binder
624    - ''
625    - ''
626    - ''
627    - ''
628    - ''
629    - ''
630    - ''
631...
632