Technique:Objective-C runtime metadata
| On this wiki | Facts · Code · Notes · Topics |
|---|
How Objective-C classes, methods, selectors and protocols are laid out in Mach-O sections (__objc_classlist, __objc_methname, class_t / class_ro_t, method lists), so names can be recovered from a stripped macOS or iOS binary.
Related Apple resource formats: Format:NIBArchive and Format:NSKeyedArchiver archive name classes, outlets and actions that match the selectors found here; image names in __TEXT,__cstring resolve through Format:Assets.car (compiled asset catalog).
Sections
In __DATA/__DATA_CONST (and __DATA_DIRTY): __objc_classlist (array of 8-byte pointers to class_t, one per class defined here; objc4 counts size/8), __objc_nlclslist (classes with +load), __objc_catlist (category_t pointers), __objc_protolist, __objc_classrefs and __objc_superrefs (pointers used by code), __objc_selrefs (pointers to selector strings; code loads selectors from here), __objc_imageinfo (8 bytes: version, flags), __objc_const (class_ro_t, method lists, ivar lists, protocol data), __objc_data (the class_t objects). Strings are in __TEXT: __objc_classname, __objc_methname (selector names, NUL separated), __objc_methtype (type encodings such as v16@0:8). Only __objc_classlist, __objc_classrefs and __objc_imageinfo were checked in the objc4 source; the others are from general knowledge (unverified here).
Walking classes
__objc_classlist entry -> class_t {isa, superclass, cache (two words), bits}. The low bits of bits are flags (bit 0 Swift legacy, bit 1 Swift stable ABI) and the masked pointer (FAST_DATA_MASK, see the fact) points to class_ro_t (in the file, before the class is realized). class_ro_t holds the class name, base methods, protocols, ivars and properties; the metaclass (isa) holds the class methods. On arm64e pointers carry PAC bits and chained fixups encode them: resolve pointers through the fixup chain first (Format:Mach-O).
Method lists
A method list is {uint32 entsize_and_flags, uint32 count, entries}. Classic entries (entsize 24): SEL name pointer, types pointer, IMP pointer. Small (relative) lists, flag 0x80000000 in the first word, entsize 12: three signed 32-bit offsets relative to each field's own address (name, types, imp); with 0x40000000 the name offset points directly at the selector string instead of at a selref. Message sends compile to objc_msgSend(receiver, selector) with the selector loaded from __objc_selrefs, so cross-references to a selref find all callers of that method name. Unverified: newer toolchains emit __objc_stubs entries that call objc_msgSend with a fixed selector (symbols _objc_msgSend$name).
See also Technique:Swift metadata sections, Platform:macOS, Platform:iOS. Source: apple-oss-distributions/objc4 runtime/objc-runtime-new.h.
Code & repositories
- https://github.com/apple-oss-distributions/objc4 @
fb265098298302243cd7eeaa1f63f0ba7786dd9a· license: APSL-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)
Apple's Objective-C runtime source (objc4): class/method/ivar metadata structures and runtime headers.
Tested on: source read, not run: read · checked 2026-10-18; last activity 2026-04-21