aboutsummaryrefslogtreecommitdiff
path: root/clang/test/InstallAPI/mismatching-objc-class-symbols.test
blob: ee35f81c58b3caa6964fb62d8a3cc66957728f7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
; RUN: yaml2obj %t/swift-objc-class.yaml -o %t/libswift-objc.dylib

// Try out dylib that only has 1 symbol for a ObjCClass, with no declarations in header. 
; RUN: clang-installapi -target arm64-apple-macos14 -dynamiclib \
; RUN: -install_name tmp.dylib --verify-against=%t/libswift-objc.dylib \
; RUN: -I%t/usr/include %t/inputs.json -o %t/missing.tbd \
; RUN: --verify-mode=ErrorsAndWarnings 2>&1 | FileCheck --check-prefix MISSING_DECL %s
; RUN: llvm-readtapi --compare %t/missing.tbd %t/missing-expected.tbd 

// Try out a dylib that only has 1 symbol for a ObjCClass, 
// but a complete ObjCClass decl in header.
; RUN: clang-installapi -target arm64-apple-macos14 -dynamiclib \
; RUN: -install_name tmp.dylib --verify-against=%t/libswift-objc.dylib \
; RUN: -I%t/usr/include %t/inputs.json -o %t/mismatching.tbd \
; RUN: --verify-mode=Pedantic -DFULL_DECL 2>&1 | FileCheck --check-prefix MISMATCH_DECL %s
; RUN: llvm-readtapi -compare %t/mismatching.tbd  %t/mismatching-expected.tbd

// Try out a dylib that only has 1 symbol for a ObjCClass, but is represented in header. 
; RUN: clang-installapi -target arm64-apple-macos14 -dynamiclib \
; RUN: -install_name tmp.dylib --verify-against=%t/libswift-objc.dylib \
; RUN: -I%t/usr/include %t/inputs.json -o %t/matching.tbd \
; RUN: --verify-mode=Pedantic \
; RUN: -DHAS_META_DECL 2>&1 | FileCheck --allow-empty %s

; MISSING_DECL:        violations found for arm64
; MISSING_DECL-NEXT:   warning: no declaration was found for exported symbol 'Metaclass of Suggestion' in dynamic library

; MISMATCH_DECL:       violations found for arm64-apple-macos14
; MISMATCH_DECL:       warning: declaration has external linkage, but dynamic library doesn't have symbol 'Class of Suggestion'

; CHECK-NOT:           error
; CHECK-NOT:           warning 


;--- usr/include/mismatch.h
#if HAS_META_DECL
int metaclass __asm("_OBJC_METACLASS_$_Suggestion");
#endif 

#if FULL_DECL
@interface Suggestion 
@end
#endif

;--- inputs.json.in
{
  "headers": [ {
    "path" : "DSTROOT/usr/include/mismatch.h",
    "type" : "public"
  }
  ],
  "version": "3"
}

;--- missing-expected.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ arm64-macos ]
flags:           [ not_app_extension_safe ]
install-name:    tmp.dylib
current-version: 0
compatibility-version: 0
...

;--- mismatching-expected.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ arm64-macos ]
flags:           [ not_app_extension_safe ]
install-name:    tmp.dylib
current-version: 0
compatibility-version: 0
exports:
  - targets:         [ arm64-macos ]
    objc-classes:    [ Suggestion ]
...

;--- swift-objc-class.yaml
--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x100000C
  cpusubtype:      0x0
  filetype:        0x6
  ncmds:           13
  sizeofcmds:      752
  flags:           0x100085
  reserved:        0x0
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         __TEXT
    vmaddr:          0
    vmsize:          16384
    fileoff:         0
    filesize:        16384
    maxprot:         5
    initprot:        5
    nsects:          2
    flags:           0
    Sections:
      - sectname:        __text
        segname:         __TEXT
        addr:            0x330
        size:            0
        offset:          0x330
        align:           0
        reloff:          0x0
        nreloc:          0
        flags:           0x80000000
        reserved1:       0x0
        reserved2:       0x0
        reserved3:       0x0
        content:         ''
      - sectname:        __const
        segname:         __TEXT
        addr:            0x330
        size:            1
        offset:          0x330
        align:           0
        reloff:          0x0
        nreloc:          0
        flags:           0x0
        reserved1:       0x0
        reserved2:       0x0
        reserved3:       0x0
        content:         '61'
  - cmd:             LC_SEGMENT_64
    cmdsize:         72
    segname:         __LINKEDIT
    vmaddr:          16384
    vmsize:          416
    fileoff:         16384
    filesize:        416
    maxprot:         1
    initprot:        1
    nsects:          0
    flags:           0
  - cmd:             LC_DYLD_INFO_ONLY
    cmdsize:         48
    rebase_off:      0
    rebase_size:     0
    bind_off:        0
    bind_size:       0
    weak_bind_off:   0
    weak_bind_size:  0
    lazy_bind_off:   0
    lazy_bind_size:  0
    export_off:      16384
    export_size:     40
  - cmd:             LC_SYMTAB
    cmdsize:         24
    symoff:          16432
    nsyms:           2
    stroff:          16464
    strsize:         48
  - cmd:             LC_DYSYMTAB
    cmdsize:         80
    ilocalsym:       0
    nlocalsym:       0
    iextdefsym:      0
    nextdefsym:      1
    iundefsym:       1
    nundefsym:       1
    tocoff:          0
    ntoc:            0
    modtaboff:       0
    nmodtab:         0
    extrefsymoff:    0
    nextrefsyms:     0
    indirectsymoff:  0
    nindirectsyms:   0
    extreloff:       0
    nextrel:         0
    locreloff:       0
    nlocrel:         0
  - cmd:             LC_ID_DYLIB
    cmdsize:         40
    dylib:
      name:            24
      timestamp:       0
      current_version: 0
      compatibility_version: 0
    Content:         tmp.dylib
    ZeroPadBytes:    7
  - cmd:             LC_UUID
    cmdsize:         24
    uuid:            4C4C4443-5555-3144-A142-97179769CBE0
  - cmd:             LC_BUILD_VERSION
    cmdsize:         32
    platform:        1
    minos:           917504
    sdk:             983040
    ntools:          1
    Tools:
      - tool:            4
        version:         1245184
  - cmd:             LC_LOAD_DYLIB
    cmdsize:         96
    dylib:
      name:            24
      timestamp:       0
      current_version: 197656576
      compatibility_version: 19660800
    Content:         '/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation'
    ZeroPadBytes:    3
  - cmd:             LC_LOAD_DYLIB
    cmdsize:         56
    dylib:
      name:            24
      timestamp:       0
      current_version: 88473600
      compatibility_version: 65536
    Content:         '/usr/lib/libSystem.B.dylib'
    ZeroPadBytes:    6
  - cmd:             LC_FUNCTION_STARTS
    cmdsize:         16
    dataoff:         16424
    datasize:        8
  - cmd:             LC_DATA_IN_CODE
    cmdsize:         16
    dataoff:         16432
    datasize:        0
  - cmd:             LC_CODE_SIGNATURE
    cmdsize:         16
    dataoff:         16512
    datasize:        288
LinkEditData:
  ExportTrie:
    TerminalSize:    0
    NodeOffset:      0
    Name:            ''
    Flags:           0x0
    Address:         0x0
    Other:           0x0
    ImportName:      ''
    Children:
      - TerminalSize:    3
        NodeOffset:      32
        Name:            '_OBJC_METACLASS_$_Suggestion'
        Flags:           0x0
        Address:         0x330
        Other:           0x0
        ImportName:      ''
  NameList:
    - n_strx:          2
      n_type:          0xF
      n_sect:          2
      n_desc:          0
      n_value:         816
    - n_strx:          31
      n_type:          0x1
      n_sect:          0
      n_desc:          512
      n_value:         0
  StringTable:
    - ' '
    - '_OBJC_METACLASS_$_Suggestion'
    - dyld_stub_binder
  FunctionStarts:  [ 0x330 ]
...
// Generated from: 
// xcrun -sdk macosx clang tmp.c -dynamiclib -install_name tmp.dylib
// tmp.c: 
// __attribute__((visibility("default")))
// const char Meta __asm("_OBJC_METACLASS_$_Suggestion") = 'a';