]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-config.h
objc4-818.2.tar.gz
[apple/objc4.git] / runtime / objc-config.h
1 /*
2 * Copyright (c) 1999-2002, 2005-2008 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _OBJC_CONFIG_H_
25 #define _OBJC_CONFIG_H_
26
27 #include <TargetConditionals.h>
28
29 // Avoid the !NDEBUG double negative.
30 #if !NDEBUG
31 # define DEBUG 1
32 #else
33 # define DEBUG 0
34 #endif
35
36 // Define SUPPORT_GC_COMPAT=1 to enable compatibility where GC once was.
37 // OBJC_NO_GC and OBJC_NO_GC_API in objc-api.h mean something else.
38 #if !TARGET_OS_OSX
39 # define SUPPORT_GC_COMPAT 0
40 #else
41 # define SUPPORT_GC_COMPAT 1
42 #endif
43
44 // Define SUPPORT_ZONES=1 to enable malloc zone support in NXHashTable.
45 #if !(TARGET_OS_OSX || TARGET_OS_MACCATALYST)
46 # define SUPPORT_ZONES 0
47 #else
48 # define SUPPORT_ZONES 1
49 #endif
50
51 // Define SUPPORT_MOD=1 to use the mod operator in NXHashTable and objc-sel-set
52 #if defined(__arm__)
53 # define SUPPORT_MOD 0
54 #else
55 # define SUPPORT_MOD 1
56 #endif
57
58 // Define SUPPORT_PREOPT=1 to enable dyld shared cache optimizations
59 #if TARGET_OS_WIN32
60 # define SUPPORT_PREOPT 0
61 #else
62 # define SUPPORT_PREOPT 1
63 #endif
64
65 // Define SUPPORT_TAGGED_POINTERS=1 to enable tagged pointer objects
66 // Be sure to edit tagged pointer SPI in objc-internal.h as well.
67 #if !__LP64__
68 # define SUPPORT_TAGGED_POINTERS 0
69 #else
70 # define SUPPORT_TAGGED_POINTERS 1
71 #endif
72
73 // Define SUPPORT_MSB_TAGGED_POINTERS to use the MSB
74 // as the tagged pointer marker instead of the LSB.
75 // Be sure to edit tagged pointer SPI in objc-internal.h as well.
76 #if !SUPPORT_TAGGED_POINTERS || ((TARGET_OS_OSX || TARGET_OS_MACCATALYST) && __x86_64__)
77 # define SUPPORT_MSB_TAGGED_POINTERS 0
78 #else
79 # define SUPPORT_MSB_TAGGED_POINTERS 1
80 #endif
81
82 // Define SUPPORT_INDEXED_ISA=1 on platforms that store the class in the isa
83 // field as an index into a class table.
84 // Note, keep this in sync with any .s files which also define it.
85 // Be sure to edit objc-abi.h as well.
86 #if __ARM_ARCH_7K__ >= 2 || (__arm64__ && !__LP64__)
87 # define SUPPORT_INDEXED_ISA 1
88 #else
89 # define SUPPORT_INDEXED_ISA 0
90 #endif
91
92 // Define SUPPORT_PACKED_ISA=1 on platforms that store the class in the isa
93 // field as a maskable pointer with other data around it.
94 #if (!__LP64__ || TARGET_OS_WIN32 || \
95 (TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST && !__arm64__))
96 # define SUPPORT_PACKED_ISA 0
97 #else
98 # define SUPPORT_PACKED_ISA 1
99 #endif
100
101 // Define SUPPORT_NONPOINTER_ISA=1 on any platform that may store something
102 // in the isa field that is not a raw pointer.
103 #if !SUPPORT_INDEXED_ISA && !SUPPORT_PACKED_ISA
104 # define SUPPORT_NONPOINTER_ISA 0
105 #else
106 # define SUPPORT_NONPOINTER_ISA 1
107 #endif
108
109 // Define SUPPORT_FIXUP=1 to repair calls sites for fixup dispatch.
110 // Fixup messaging itself is no longer supported.
111 // Be sure to edit objc-abi.h as well (objc_msgSend*_fixup)
112 #if !(defined(__x86_64__) && (TARGET_OS_OSX || TARGET_OS_SIMULATOR))
113 # define SUPPORT_FIXUP 0
114 #else
115 # define SUPPORT_FIXUP 1
116 #endif
117
118 // Define SUPPORT_ZEROCOST_EXCEPTIONS to use "zero-cost" exceptions for OBJC2.
119 // Be sure to edit objc-exception.h as well (objc_add/removeExceptionHandler)
120 #if defined(__arm__) && __USING_SJLJ_EXCEPTIONS__
121 # define SUPPORT_ZEROCOST_EXCEPTIONS 0
122 #else
123 # define SUPPORT_ZEROCOST_EXCEPTIONS 1
124 #endif
125
126 // Define SUPPORT_ALT_HANDLERS if you're using zero-cost exceptions
127 // but also need to support AppKit's alt-handler scheme
128 // Be sure to edit objc-exception.h as well (objc_add/removeExceptionHandler)
129 #if !SUPPORT_ZEROCOST_EXCEPTIONS || !TARGET_OS_OSX
130 # define SUPPORT_ALT_HANDLERS 0
131 #else
132 # define SUPPORT_ALT_HANDLERS 1
133 #endif
134
135 // Define SUPPORT_RETURN_AUTORELEASE to optimize autoreleased return values
136 #if TARGET_OS_WIN32
137 # define SUPPORT_RETURN_AUTORELEASE 0
138 #else
139 # define SUPPORT_RETURN_AUTORELEASE 1
140 #endif
141
142 // Define SUPPORT_STRET on architectures that need separate struct-return ABI.
143 #if defined(__arm64__)
144 # define SUPPORT_STRET 0
145 #else
146 # define SUPPORT_STRET 1
147 #endif
148
149 // Define SUPPORT_MESSAGE_LOGGING to enable NSObjCMessageLoggingEnabled
150 #if !TARGET_OS_OSX
151 # define SUPPORT_MESSAGE_LOGGING 0
152 #else
153 # define SUPPORT_MESSAGE_LOGGING 1
154 #endif
155
156 // Define SUPPORT_AUTORELEASEPOOL_DEDDUP_PTRS to combine consecutive pointers to the same object in autorelease pools
157 #if !__LP64__
158 # define SUPPORT_AUTORELEASEPOOL_DEDUP_PTRS 0
159 #else
160 # define SUPPORT_AUTORELEASEPOOL_DEDUP_PTRS 1
161 #endif
162
163 // Define HAVE_TASK_RESTARTABLE_RANGES to enable usage of
164 // task_restartable_ranges_synchronize()
165 #if TARGET_OS_SIMULATOR || defined(__i386__) || defined(__arm__) || !TARGET_OS_MAC
166 # define HAVE_TASK_RESTARTABLE_RANGES 0
167 #else
168 # define HAVE_TASK_RESTARTABLE_RANGES 1
169 #endif
170
171 // OBJC_INSTRUMENTED controls whether message dispatching is dynamically
172 // monitored. Monitoring introduces substantial overhead.
173 // NOTE: To define this condition, do so in the build command, NOT by
174 // uncommenting the line here. This is because objc-class.h heeds this
175 // condition, but objc-class.h can not #include this file (objc-config.h)
176 // because objc-class.h is public and objc-config.h is not.
177 //#define OBJC_INSTRUMENTED
178
179 // The runtimeLock is a mutex always held hence the cache lock is
180 // redundant and can be elided.
181 //
182 // If the runtime lock ever becomes a rwlock again,
183 // the cache lock would need to be used again
184 #define CONFIG_USE_CACHE_LOCK 0
185
186 // Determine how the method cache stores IMPs.
187 #define CACHE_IMP_ENCODING_NONE 1 // Method cache contains raw IMP.
188 #define CACHE_IMP_ENCODING_ISA_XOR 2 // Method cache contains ISA ^ IMP.
189 #define CACHE_IMP_ENCODING_PTRAUTH 3 // Method cache contains ptrauth'd IMP.
190
191 #if __PTRAUTH_INTRINSICS__
192 // Always use ptrauth when it's supported.
193 #define CACHE_IMP_ENCODING CACHE_IMP_ENCODING_PTRAUTH
194 #elif defined(__arm__)
195 // 32-bit ARM uses no encoding.
196 #define CACHE_IMP_ENCODING CACHE_IMP_ENCODING_NONE
197 #else
198 // Everything else uses ISA ^ IMP.
199 #define CACHE_IMP_ENCODING CACHE_IMP_ENCODING_ISA_XOR
200 #endif
201
202 #define CACHE_MASK_STORAGE_OUTLINED 1
203 #define CACHE_MASK_STORAGE_HIGH_16 2
204 #define CACHE_MASK_STORAGE_LOW_4 3
205 #define CACHE_MASK_STORAGE_HIGH_16_BIG_ADDRS 4
206
207 #if defined(__arm64__) && __LP64__
208 #if TARGET_OS_OSX || TARGET_OS_SIMULATOR
209 #define CACHE_MASK_STORAGE CACHE_MASK_STORAGE_HIGH_16_BIG_ADDRS
210 #else
211 #define CACHE_MASK_STORAGE CACHE_MASK_STORAGE_HIGH_16
212 #endif
213 #elif defined(__arm64__) && !__LP64__
214 #define CACHE_MASK_STORAGE CACHE_MASK_STORAGE_LOW_4
215 #else
216 #define CACHE_MASK_STORAGE CACHE_MASK_STORAGE_OUTLINED
217 #endif
218
219 // Constants used for signing/authing isas. This doesn't quite belong
220 // here, but the asm files can't import other headers.
221 #define ISA_SIGNING_DISCRIMINATOR 0x6AE1
222 #define ISA_SIGNING_DISCRIMINATOR_CLASS_SUPERCLASS 0xB5AB
223
224 #define ISA_SIGNING_KEY ptrauth_key_process_independent_data
225
226 // ISA signing authentication modes. Set ISA_SIGNING_AUTH_MODE to one
227 // of these to choose how ISAs are authenticated.
228 #define ISA_SIGNING_STRIP 1 // Strip the signature whenever reading an ISA.
229 #define ISA_SIGNING_AUTH 2 // Authenticate the signature on all ISAs.
230
231
232 // ISA signing modes. Set ISA_SIGNING_SIGN_MODE to one of these to
233 // choose how ISAs are signed.
234 #define ISA_SIGNING_SIGN_NONE 1 // Sign no ISAs.
235 #define ISA_SIGNING_SIGN_ONLY_SWIFT 2 // Only sign ISAs of Swift objects.
236 #define ISA_SIGNING_SIGN_ALL 3 // Sign all ISAs.
237
238 #if __has_feature(ptrauth_objc_isa_strips) || __has_feature(ptrauth_objc_isa_signs) || __has_feature(ptrauth_objc_isa_authenticates)
239 # if __has_feature(ptrauth_objc_isa_authenticates)
240 # define ISA_SIGNING_AUTH_MODE ISA_SIGNING_AUTH
241 # else
242 # define ISA_SIGNING_AUTH_MODE ISA_SIGNING_STRIP
243 # endif
244 # if __has_feature(ptrauth_objc_isa_signs)
245 # define ISA_SIGNING_SIGN_MODE ISA_SIGNING_SIGN_ALL
246 # else
247 # define ISA_SIGNING_SIGN_MODE ISA_SIGNING_SIGN_NONE
248 # endif
249 #else
250 # if __has_feature(ptrauth_objc_isa)
251 # define ISA_SIGNING_AUTH_MODE ISA_SIGNING_AUTH
252 # define ISA_SIGNING_SIGN_MODE ISA_SIGNING_SIGN_ALL
253 # else
254 # define ISA_SIGNING_AUTH_MODE ISA_SIGNING_STRIP
255 # define ISA_SIGNING_SIGN_MODE ISA_SIGNING_SIGN_NONE
256 # endif
257 #endif
258
259 // When set, an unsigned superclass pointer is treated as Nil, which
260 // will treat the class as if its superclass was weakly linked and
261 // not loaded, and cause uses of the class to resolve to Nil.
262 #define SUPERCLASS_SIGNING_TREAT_UNSIGNED_AS_NIL 0
263
264 #if defined(__arm64__) && TARGET_OS_IOS && !TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST
265 #define CONFIG_USE_PREOPT_CACHES 1
266 #else
267 #define CONFIG_USE_PREOPT_CACHES 0
268 #endif
269
270 // When set to 1, small methods in the shared cache have a direct
271 // offset to a selector. When set to 0, small methods in the shared
272 // cache have the same format as other small methods, with an offset
273 // to a selref.
274 #define CONFIG_SHARED_CACHE_RELATIVE_DIRECT_SELECTORS 1
275
276 #endif