2 # UNSUPPORTED: system-windows
5 # RUN: rm -rf %t; split-file %s %t && cd %t
7 ############ Test merging multiple categories into a single category ############
8 ## Create a dylib with a fake base class to link against in when merging between categories
9 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o a64_fakedylib.o a64_fakedylib.s
10 # RUN: %lld -arch arm64 a64_fakedylib.o -o a64_fakedylib.dylib -dylib
12 ## Create our main testing dylib - linking against the fake dylib above
13 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_cat_minimal.o merge_cat_minimal.s
14 # RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_no_merge.dylib a64_fakedylib.dylib merge_cat_minimal.o
15 # RUN: %lld -arch arm64 -dylib -o merge_cat_minimal_merge.dylib -objc_category_merging a64_fakedylib.dylib merge_cat_minimal.o
17 ## Now verify that the flag caused category merging to happen appropriatelly
18 # RUN: llvm-objdump --objc-meta-data --macho merge_cat_minimal_no_merge.dylib | FileCheck %s --check-prefixes=NO_MERGE_CATS
19 # RUN: llvm-objdump --objc-meta-data --macho merge_cat_minimal_merge.dylib | FileCheck %s --check-prefixes=MERGE_CATS
21 ############ Test merging multiple categories into the base class ############
22 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_base_class_minimal.o merge_base_class_minimal.s
23 # RUN: %lld -arch arm64 -dylib -o merge_base_class_minimal_yes_merge.dylib -objc_category_merging merge_base_class_minimal.o merge_cat_minimal.o
24 # RUN: %lld -arch arm64 -dylib -o merge_base_class_minimal_no_merge.dylib merge_base_class_minimal.o merge_cat_minimal.o
26 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_no_merge.dylib | FileCheck %s --check-prefixes=NO_MERGE_INTO_BASE
27 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE
29 ############ Test merging swift category into the base class ############
30 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o MyBaseClassSwiftExtension.o MyBaseClassSwiftExtension.s
31 # RUN: %lld -no_objc_relative_method_lists -arch arm64 -dylib -o merge_base_class_swift_minimal_yes_merge.dylib -objc_category_merging MyBaseClassSwiftExtension.o merge_base_class_minimal.o
32 # RUN: llvm-objdump --objc-meta-data --macho merge_base_class_swift_minimal_yes_merge.dylib | FileCheck %s --check-prefixes=YES_MERGE_INTO_BASE_SWIFT
34 ############ Test merging skipped due to invalid category name ############
35 # Modify __OBJC_$_CATEGORY_MyBaseClass_$_Category01's name to point to L_OBJC_IMAGE_INFO+3
36 # RUN: awk '/^__OBJC_\$_CATEGORY_MyBaseClass_\$_Category01:/ { print; getline; sub(/^[ \t]*\.quad[ \t]+l_OBJC_CLASS_NAME_$/, "\t.quad\tL_OBJC_IMAGE_INFO+3"); print; next } { print }' merge_cat_minimal.s > merge_cat_minimal_bad_name.s
38 # Assemble the modified source
39 # RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos -o merge_cat_minimal_bad_name.o merge_cat_minimal_bad_name.s
41 # Run lld and check for the specific warning
42 # RUN: %no-fatal-warnings-lld -arch arm64 -dylib -objc_category_merging -o merge_cat_minimal_merge.dylib a64_fakedylib.dylib merge_cat_minimal_bad_name.o 2>&1 | FileCheck %s --check-prefix=MERGE_WARNING
44 # Check that lld emitted the warning about skipping category merging
45 MERGE_WARNING
: warning
: ObjC category merging skipped for class symbol
' _OBJC_CLASS_$_MyBaseClass'
47 #### Check merge categories enabled ###
48 # Check that the original categories are not there
49 MERGE_CATS-
NOT: __OBJC_$_CATEGORY_MyBaseClass_$_Category01
50 MERGE_CATS-
NOT: __OBJC_$_CATEGORY_MyBaseClass_$_Category02
52 # Check that the merged cateogry is there, in the correct format
53 MERGE_CATS
: __OBJC_$_CATEGORY_MyBaseClass
(Category01|Category02
)
54 MERGE_CATS-NEXT
: name
{{.*}} Category01|Category02
55 MERGE_CATS
: instanceMethods
56 MERGE_CATS-NEXT
: entsize
12 (relative
)
57 MERGE_CATS-NEXT
: count
2
58 MERGE_CATS-NEXT
: name
{{.*}} cat01_InstanceMethod
59 MERGE_CATS-NEXT
: types
{{.*}} v16@0:8
60 MERGE_CATS-NEXT
: imp
{{.*}} -[MyBaseClass(Category01) cat01_InstanceMethod]
61 MERGE_CATS-NEXT
: name
{{.*}} cat02_InstanceMethod
62 MERGE_CATS-NEXT
: types
{{.*}} v16@0:8
63 MERGE_CATS-NEXT
: imp
{{.*}} -[MyBaseClass(Category02) cat02_InstanceMethod]
64 MERGE_CATS-NEXT
: classMethods
0x0
65 MERGE_CATS-NEXT
: protocols
0x0
66 MERGE_CATS-NEXT
: instanceProperties
0x0
68 #### Check merge categories disabled ###
69 # Check that the merged category is not there
70 NO_MERGE_CATS-
NOT: __OBJC_$_CATEGORY_MyBaseClass
(Category01|Category02
)
72 # Check that the original categories are there
73 NO_MERGE_CATS
: __OBJC_$_CATEGORY_MyBaseClass_$_Category01
74 NO_MERGE_CATS
: __OBJC_$_CATEGORY_MyBaseClass_$_Category02
77 #### Check merge cateogires into base class is disabled ####
78 NO_MERGE_INTO_BASE
: __OBJC_$_CATEGORY_MyBaseClass_$_Category01
79 NO_MERGE_INTO_BASE
: __OBJC_$_CATEGORY_MyBaseClass_$_Category02
81 #### Check merge cateogires into base class is enabled and categories are merged into base class ####
82 YES_MERGE_INTO_BASE-
NOT: __OBJC_$_CATEGORY_MyBaseClass_$_Category01
83 YES_MERGE_INTO_BASE-
NOT: __OBJC_$_CATEGORY_MyBaseClass_$_Category02
85 YES_MERGE_INTO_BASE
: _OBJC_CLASS_$_MyBaseClass
86 YES_MERGE_INTO_BASE-NEXT
: _OBJC_METACLASS_$_MyBaseClass
87 YES_MERGE_INTO_BASE
: baseMethods
88 YES_MERGE_INTO_BASE-NEXT
: entsize
12 (relative
)
89 YES_MERGE_INTO_BASE-NEXT
: count
3
90 YES_MERGE_INTO_BASE-NEXT
: name
{{.*}} cat01_InstanceMethod
91 YES_MERGE_INTO_BASE-NEXT
: types
{{.*}} v16@0:8
92 YES_MERGE_INTO_BASE-NEXT
: imp
{{.*}} -[MyBaseClass(Category01) cat01_InstanceMethod]
93 YES_MERGE_INTO_BASE-NEXT
: name
{{.*}} cat02_InstanceMethod
94 YES_MERGE_INTO_BASE-NEXT
: types
{{.*}} v16@0:8
95 YES_MERGE_INTO_BASE-NEXT
: imp
{{.*}} -[MyBaseClass(Category02) cat02_InstanceMethod]
96 YES_MERGE_INTO_BASE-NEXT
: name
{{.*}} baseInstanceMethod
97 YES_MERGE_INTO_BASE-NEXT
: types
{{.*}} v16@0:8
98 YES_MERGE_INTO_BASE-NEXT
: imp
{{.*}} -[MyBaseClass baseInstanceMethod]
101 #### Check merge swift category into base class ###
102 YES_MERGE_INTO_BASE_SWIFT
: _OBJC_CLASS_$_MyBaseClass
103 YES_MERGE_INTO_BASE_SWIFT-NEXT
: _OBJC_METACLASS_$_MyBaseClass
104 YES_MERGE_INTO_BASE_SWIFT
: baseMethods
105 YES_MERGE_INTO_BASE_SWIFT-NEXT
: entsize
24
106 YES_MERGE_INTO_BASE_SWIFT-NEXT
: count
2
107 YES_MERGE_INTO_BASE_SWIFT-NEXT
: name
{{.*}} swiftMethod
108 YES_MERGE_INTO_BASE_SWIFT-NEXT
: types
{{.*}} v16@0:8
109 YES_MERGE_INTO_BASE_SWIFT-NEXT
: imp _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyFTo
110 YES_MERGE_INTO_BASE_SWIFT-NEXT
: name
{{.*}} baseInstanceMethod
111 YES_MERGE_INTO_BASE_SWIFT-NEXT
: types
{{.*}} v16@0:8
112 YES_MERGE_INTO_BASE_SWIFT-NEXT
: imp
-[MyBaseClass baseInstanceMethod
]
117 .section __DATA,__objc_data
118 .globl _OBJC_CLASS_$_MyBaseClass
119 _OBJC_CLASS_$_MyBaseClass
:
122 #--- merge_cat_minimal.s
124 ;
================== Generated from ObjC
: ==================
125 ; __attribute__
((objc_root_class
))
126 ; @interface MyBaseClass
127 ;
- (void
)baseInstanceMethod;
130 ; @interface MyBaseClass
(Category01
)
131 ;
- (void
)cat01_InstanceMethod;
134 ; @implementation MyBaseClass
(Category01
)
135 ;
- (void
)cat01_InstanceMethod
{}
138 ; @interface MyBaseClass
(Category02
)
139 ;
- (void
)cat02_InstanceMethod;
142 ; @implementation MyBaseClass
(Category02
)
143 ;
- (void
)cat02_InstanceMethod
{}
145 ;
================== Generated from ObjC
: ==================
147 .section __TEXT,__text,regular,pure_instructions
148 .p2align 2 ; -- Begin function -[MyBaseClass(Category01) cat01_InstanceMethod]
149 "-[MyBaseClass(Category01) cat01_InstanceMethod]": ; @
"\01-[MyBaseClass(Category01) cat01_InstanceMethod]"
154 .p2align 2 ; -- Begin function -[MyBaseClass(Category02) cat02_InstanceMethod]
155 "-[MyBaseClass(Category02) cat02_InstanceMethod]": ; @
"\01-[MyBaseClass(Category02) cat02_InstanceMethod]"
160 .section __TEXT,__objc_classname,cstring_literals
161 l_OBJC_CLASS_NAME_
: ; @OBJC_CLASS_NAME_
163 .section __TEXT,__objc_methname,cstring_literals
164 l_OBJC_METH_VAR_NAME_
: ; @OBJC_METH_VAR_NAME_
165 .asciz "cat01_InstanceMethod"
166 .section __TEXT,__objc_methtype,cstring_literals
167 l_OBJC_METH_VAR_TYPE_
: ; @OBJC_METH_VAR_TYPE_
169 .section __DATA,__objc_const
170 .p2align 3, 0x0 ; @"_OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category01"
171 __OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category01
:
174 .quad l_OBJC_METH_VAR_NAME_
175 .quad l_OBJC_METH_VAR_TYPE_
176 .quad "-[MyBaseClass(Category01) cat01_InstanceMethod]"
177 .p2align 3, 0x0 ; @"_OBJC_$_CATEGORY_MyBaseClass_$_Category01"
178 __OBJC_$_CATEGORY_MyBaseClass_$_Category01
:
179 .quad l_OBJC_CLASS_NAME_
180 .quad _OBJC_CLASS_$_MyBaseClass
181 .quad __OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category01
188 .section __DATA,__objc_const
189 l_OBJC_CLASS_NAME_.1
: ; @OBJC_CLASS_NAME_.1
191 .section __TEXT,__objc_methname,cstring_literals
192 l_OBJC_METH_VAR_NAME_.2
: ; @OBJC_METH_VAR_NAME_.2
193 .asciz "cat02_InstanceMethod"
194 .section __DATA,__objc_const
195 .p2align 3, 0x0 ; @"_OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category02"
196 __OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category02
:
199 .quad l_OBJC_METH_VAR_NAME_.2
200 .quad l_OBJC_METH_VAR_TYPE_
201 .quad "-[MyBaseClass(Category02) cat02_InstanceMethod]"
202 .p2align 3, 0x0 ; @"_OBJC_$_CATEGORY_MyBaseClass_$_Category02"
203 __OBJC_$_CATEGORY_MyBaseClass_$_Category02
:
204 .quad l_OBJC_CLASS_NAME_.1
205 .quad _OBJC_CLASS_$_MyBaseClass
206 .quad __OBJC_$_CATEGORY_INSTANCE_METHODS_MyBaseClass_$_Category02
213 .section __DATA,__objc_catlist,regular,no_dead_strip
214 .p2align 3, 0x0 ; @"OBJC_LABEL_CATEGORY_$"
215 l_OBJC_LABEL_CATEGORY_$
:
216 .quad __OBJC_$_CATEGORY_MyBaseClass_$_Category01
217 .quad __OBJC_$_CATEGORY_MyBaseClass_$_Category02
218 .section __DATA,__objc_imageinfo,regular,no_dead_strip
222 .subsections_via_symbols
225 .addrsig_sym __OBJC_$_CATEGORY_MyBaseClass_$_Category01
227 #--- merge_base_class_minimal.s
228 ; clang
-c merge_base_class_minimal.mm
-O3
-target arm64-apple-macos
-arch arm64
-S
-o merge_base_class_minimal.s
229 ;
================== Generated from ObjC
: ==================
230 ; __attribute__
((objc_root_class
))
231 ; @interface MyBaseClass
232 ;
- (void
)baseInstanceMethod;
235 ; @implementation MyBaseClass
236 ;
- (void
)baseInstanceMethod
{}
238 ;
================== Generated from ObjC
==================
239 .section __TEXT,__text,regular,pure_instructions
240 .build_version macos, 11, 0
242 "-[MyBaseClass baseInstanceMethod]":
247 .section __DATA,__objc_data
248 .globl _OBJC_CLASS_$_MyBaseClass
250 _OBJC_CLASS_$_MyBaseClass
:
251 .quad _OBJC_METACLASS_$_MyBaseClass
255 .quad __OBJC_CLASS_RO_$_MyBaseClass
256 .globl _OBJC_METACLASS_$_MyBaseClass
258 _OBJC_METACLASS_$_MyBaseClass
:
259 .quad _OBJC_METACLASS_$_MyBaseClass
260 .quad _OBJC_CLASS_$_MyBaseClass
263 .quad __OBJC_METACLASS_RO_$_MyBaseClass
264 .section __TEXT,__objc_classname,cstring_literals
267 .section __DATA,__objc_const
269 __OBJC_METACLASS_RO_$_MyBaseClass
:
275 .quad l_OBJC_CLASS_NAME_
281 .section __TEXT,__objc_methname,cstring_literals
282 l_OBJC_METH_VAR_NAME_
:
283 .asciz "baseInstanceMethod"
284 .section __TEXT,__objc_methtype,cstring_literals
285 l_OBJC_METH_VAR_TYPE_
:
287 .section __DATA,__objc_const
289 __OBJC_$_INSTANCE_METHODS_MyBaseClass
:
292 .quad l_OBJC_METH_VAR_NAME_
293 .quad l_OBJC_METH_VAR_TYPE_
294 .quad "-[MyBaseClass baseInstanceMethod]"
296 __OBJC_CLASS_RO_$_MyBaseClass
:
302 .quad l_OBJC_CLASS_NAME_
303 .quad __OBJC_$_INSTANCE_METHODS_MyBaseClass
308 .section __DATA,__objc_classlist,regular,no_dead_strip
310 l_OBJC_LABEL_CLASS_$
:
311 .quad _OBJC_CLASS_$_MyBaseClass
312 .section __DATA,__objc_imageinfo,regular,no_dead_strip
316 .subsections_via_symbols
319 #--- MyBaseClassSwiftExtension.s
320 ; xcrun
-sdk macosx swiftc
-emit-assembly MyBaseClassSwiftExtension.swift
-import-objc-header YourProject-Bridging-Header.h
-o MyBaseClassSwiftExtension.s
321 ;
================== Generated from Swift
: ==================
323 ; extension MyBaseClass
{
324 ; @objc func swiftMethod
() {
327 ;
================== Generated from Swift
===================
328 .private_extern _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyF
329 .globl _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyF
331 _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyF
:
338 _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyFTo
:
344 .section __TEXT,__cstring,cstring_literals
346 l_.str.25
.MyBaseClassSwiftExtension:
347 .asciz "MyBaseClassSwiftExtension"
349 .section __TEXT,__objc_methname,cstring_literals
350 "L_selector_data(swiftMethod)":
353 .section __TEXT,__cstring,cstring_literals
357 .section __DATA,__objc_data
359 __CATEGORY_INSTANCE_METHODS_MyBaseClass_$_MyBaseClassSwiftExtension
:
362 .quad "L_selector_data(swiftMethod)"
363 .quad "l_.str.7.v16@0:8"
364 .quad _$sSo11MyBaseClassC0abC14SwiftExtensionE11swiftMethodyyFTo
366 .section __DATA,__objc_const
368 __CATEGORY_MyBaseClass_$_MyBaseClassSwiftExtension
:
369 .quad l_.str.25.MyBaseClassSwiftExtension
370 .quad _OBJC_CLASS_$_MyBaseClass
371 .quad __CATEGORY_INSTANCE_METHODS_MyBaseClass_$_MyBaseClassSwiftExtension
379 .section __DATA,__objc_catlist,regular,no_dead_strip
382 .quad __CATEGORY_MyBaseClass_$_MyBaseClassSwiftExtension
385 .no_dead_strip l_entry_point
387 .subsections_via_symbols