Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Non-fragile ObjC ABI: Add support for __attribute__((objc_class_stub)) #289

Conversation

slavapestov
Copy link
Member

This attribute denotes a class with resiliently-sized metadata, which
is initialized at runtime. Since there is no statically-emitted metadata
in this case, Clang must reference a "class stub" instead.

When emitting a classref load we have to call objc_loadClassRef()
instead of loading directly.

In the classref itself, the least significant bit of the class pointer
is set to 1.

The Objective-C runtime implements objc_loadClassRef() by checking if
the least significant bit of the class pointer is 1; if not, it simply
returns the class pointer. Otherwise, it calls an initialization hook
stored inside the class stub, and stores the result of the hook back
to the classref to fast path future loads.

Note that categories continue to be emitted as before; the runtime will
lazily attach categories when class stubs are realized.

This attribute denotes a class with resiliently-sized metadata, which
is initialized at runtime. Since there is no statically-emitted metadata
in this case, Clang must reference a "class stub" instead.

When emitting a classref load we have to call `objc_loadClassRef()`
instead of loading directly.

In the classref itself, the least significant bit of the class pointer
is set to 1.

The Objective-C runtime implements objc_loadClassRef() by checking if
the least significant bit of the class pointer is 1; if not, it simply
returns the class pointer. Otherwise, it calls an initialization hook
stored inside the class stub, and stores the result of the hook back
to the classref to fast path future loads.

Note that categories continue to be emitted as before; the runtime will
lazily attach categories when class stubs are realized.
@slavapestov slavapestov merged commit 54682d2 into apple:upstream-with-swift Apr 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant