1// Test that we can handle calls to methods on categories.
2// The following assembly defines an ObjC class Foo with an instance method
3// -foo, then uses a category (Bar) to add an extra instance method -bar.
4// The main function calls both -foo and -bar on an instance of Foo to check
5// that the calls behave as expected.
6//
7// RUN: %clang -c -o %t.o %s
8// RUN: %llvm_jitlink -preload libobjc.A.dylib %t.o
9//
10// REQUIRES: jit-compatible-osx-swift-runtime
11
12 .section __TEXT,__text,regular,pure_instructions
13 .build_version macos, 14, 0
14 .p2align 2
15"-[Foo foo]":
16 mov w0, #1
17 ret
18
19 .p2align 2
20"-[Foo(Bar) bar]":
21 mov w0, #1
22 ret
23
24 .globl _main
25 .p2align 2
26_main:
27 stp x20, x19, [sp, #-32]!
28 stp x29, x30, [sp, #16]
29 add x29, sp, #16
30Lloh0:
31 adrp x8, _OBJC_CLASSLIST_REFERENCES_$_@PAGE
32Lloh1:
33 ldr x0, [x8, _OBJC_CLASSLIST_REFERENCES_$_@PAGEOFF]
34 bl _objc_alloc_init
35 mov x19, x0
36Lloh2:
37 adrp x8, _OBJC_SELECTOR_REFERENCES_@PAGE
38Lloh3:
39 ldr x1, [x8, _OBJC_SELECTOR_REFERENCES_@PAGEOFF]
40 bl _objc_msgSend
41 cmp w0, #1
42 b.ne LBB2_2
43
44Lloh4:
45 adrp x8, _OBJC_SELECTOR_REFERENCES_.3@PAGE
46Lloh5:
47 ldr x1, [x8, _OBJC_SELECTOR_REFERENCES_.3@PAGEOFF]
48 mov x0, x19
49 bl _objc_msgSend
50 cmp w0, #1
51 cset w0, ne
52 ldp x29, x30, [sp, #16]
53 ldp x20, x19, [sp], #32
54 ret
55LBB2_2:
56 mov w0, #1
57 ldp x29, x30, [sp, #16]
58 ldp x20, x19, [sp], #32
59 ret
60 .loh AdrpLdr Lloh2, Lloh3
61 .loh AdrpLdr Lloh0, Lloh1
62 .loh AdrpLdr Lloh4, Lloh5
63
64 .section __TEXT,__objc_classname,cstring_literals
65l_OBJC_CLASS_NAME_:
66 .asciz "Foo"
67
68 .section __DATA,__objc_const
69 .p2align 3, 0x0
70__OBJC_METACLASS_RO_$_Foo:
71 .long 1
72 .long 40
73 .long 40
74 .space 4
75 .quad 0
76 .quad l_OBJC_CLASS_NAME_
77 .quad 0
78 .quad 0
79 .quad 0
80 .quad 0
81 .quad 0
82
83 .section __DATA,__objc_data
84 .globl _OBJC_METACLASS_$_Foo
85 .p2align 3, 0x0
86_OBJC_METACLASS_$_Foo:
87 .quad _OBJC_METACLASS_$_NSObject
88 .quad _OBJC_METACLASS_$_NSObject
89 .quad __objc_empty_cache
90 .quad 0
91 .quad __OBJC_METACLASS_RO_$_Foo
92
93 .section __TEXT,__objc_methname,cstring_literals
94l_OBJC_METH_VAR_NAME_:
95 .asciz "foo"
96
97 .section __TEXT,__objc_methtype,cstring_literals
98l_OBJC_METH_VAR_TYPE_:
99 .asciz "i16@0:8"
100
101 .section __DATA,__objc_const
102 .p2align 3, 0x0
103__OBJC_$_INSTANCE_METHODS_Foo:
104 .long 24
105 .long 1
106 .quad l_OBJC_METH_VAR_NAME_
107 .quad l_OBJC_METH_VAR_TYPE_
108 .quad "-[Foo foo]"
109
110 .p2align 3, 0x0
111__OBJC_CLASS_RO_$_Foo:
112 .long 0
113 .long 8
114 .long 8
115 .space 4
116 .quad 0
117 .quad l_OBJC_CLASS_NAME_
118 .quad __OBJC_$_INSTANCE_METHODS_Foo
119 .quad 0
120 .quad 0
121 .quad 0
122 .quad 0
123
124 .section __DATA,__objc_data
125 .globl _OBJC_CLASS_$_Foo
126 .p2align 3, 0x0
127_OBJC_CLASS_$_Foo:
128 .quad _OBJC_METACLASS_$_Foo
129 .quad _OBJC_CLASS_$_NSObject
130 .quad __objc_empty_cache
131 .quad 0
132 .quad __OBJC_CLASS_RO_$_Foo
133
134 .section __TEXT,__objc_classname,cstring_literals
135l_OBJC_CLASS_NAME_.1:
136 .asciz "Bar"
137
138 .section __TEXT,__objc_methname,cstring_literals
139l_OBJC_METH_VAR_NAME_.2:
140 .asciz "bar"
141
142 .section __DATA,__objc_const
143 .p2align 3, 0x0
144__OBJC_$_CATEGORY_INSTANCE_METHODS_Foo_$_Bar:
145 .long 24
146 .long 1
147 .quad l_OBJC_METH_VAR_NAME_.2
148 .quad l_OBJC_METH_VAR_TYPE_
149 .quad "-[Foo(Bar) bar]"
150
151 .p2align 3, 0x0
152__OBJC_$_CATEGORY_Foo_$_Bar:
153 .quad l_OBJC_CLASS_NAME_.1
154 .quad _OBJC_CLASS_$_Foo
155 .quad __OBJC_$_CATEGORY_INSTANCE_METHODS_Foo_$_Bar
156 .quad 0
157 .quad 0
158 .quad 0
159 .quad 0
160 .long 64
161 .space 4
162
163 .section __DATA,__objc_classrefs,regular,no_dead_strip
164 .p2align 3, 0x0
165_OBJC_CLASSLIST_REFERENCES_$_:
166 .quad _OBJC_CLASS_$_Foo
167
168 .section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
169 .p2align 3, 0x0
170_OBJC_SELECTOR_REFERENCES_:
171 .quad l_OBJC_METH_VAR_NAME_
172
173 .p2align 3, 0x0
174_OBJC_SELECTOR_REFERENCES_.3:
175 .quad l_OBJC_METH_VAR_NAME_.2
176
177 .section __DATA,__objc_classlist,regular,no_dead_strip
178 .p2align 3, 0x0
179l_OBJC_LABEL_CLASS_$:
180 .quad _OBJC_CLASS_$_Foo
181
182 .section __DATA,__objc_catlist,regular,no_dead_strip
183 .p2align 3, 0x0
184l_OBJC_LABEL_CATEGORY_$:
185 .quad __OBJC_$_CATEGORY_Foo_$_Bar
186
187 .section __DATA,__objc_imageinfo,regular,no_dead_strip
188L_OBJC_IMAGE_INFO:
189 .long 0
190 .long 64
191
192.subsections_via_symbols
193

source code of compiler-rt/test/orc/TestCases/Darwin/arm64/objc-category.S