Skip to content

[5.1][Runtime] Use a #define for the value of swift_isaMask. #24676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion stdlib/public/runtime/Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "swift/Runtime/Metadata.h"
#include "llvm/Support/Compiler.h"

#if defined(__APPLE__) && defined(__MACH__)
#include <TargetConditionals.h>
#endif

// Opaque ISAs need to use object_getClass which is in runtime.h
#if SWIFT_HAS_OPAQUE_ISAS
#include <objc/runtime.h>
Expand Down Expand Up @@ -84,6 +88,24 @@ class TypeInfo {
#if SWIFT_HAS_ISA_MASKING
SWIFT_RUNTIME_EXPORT
uintptr_t swift_isaMask;

// Hardcode the mask. We have our own copy of the value, as it's hard to work
// out the proper includes from libobjc. The values MUST match the ones from
// libobjc. Debug builds check these values against objc_debug_isa_class_mask
// from libobjc.
# if TARGET_OS_SIMULATOR
// Simulators don't currently use isa masking, but we still want to emit
// swift_isaMask and the corresponding code in case that changes. libobjc's
// mask has the bottom bits clear to include pointer alignment, match that
// value here.
# define SWIFT_ISA_MASK 0xfffffffffffffff8ULL
# elif __arm64__
# define SWIFT_ISA_MASK 0x0000000ffffffff8ULL
# elif __x86_64__
# define SWIFT_ISA_MASK 0x00007ffffffffff8ULL
# else
# error Unknown architecture for masked isa.
# endif
#endif

#if SWIFT_OBJC_INTEROP
Expand Down Expand Up @@ -134,7 +156,7 @@ class TypeInfo {

#if SWIFT_HAS_ISA_MASKING
// Apply the mask.
bits &= swift_isaMask;
bits &= SWIFT_ISA_MASK;
#endif

// The result is a class pointer.
Expand Down
19 changes: 7 additions & 12 deletions stdlib/public/runtime/SwiftObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,7 @@
OBJC_EXPORT __attribute__((__weak_import__))
const uintptr_t objc_debug_isa_class_mask;

static uintptr_t computeISAMask() {
// The versions of the Objective-C runtime which use non-pointer
// ISAs also export this symbol.
if (auto runtimeSymbol = &objc_debug_isa_class_mask)
return *runtimeSymbol;
return ~uintptr_t(0);
}

SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
uintptr_t swift::swift_isaMask = computeISAMask();
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
uintptr_t swift::swift_isaMask = SWIFT_ISA_MASK;
#endif

const ClassMetadata *swift::_swift_getClass(const void *object) {
Expand Down Expand Up @@ -204,7 +194,12 @@ Class _swift_classOfObjCHeapObject(OpaqueValue *value) {


@implementation SwiftObject
+ (void)initialize {}
+ (void)initialize {
#if SWIFT_HAS_ISA_MASKING
assert(&objc_debug_isa_class_mask);
assert(objc_debug_isa_class_mask == SWIFT_ISA_MASK);
#endif
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
assert(zone == nullptr);
Expand Down