Skip to content

Objective C Support

Hugo edited this page Sep 25, 2026 · 1 revision

Objective-C Support

On macOS, .m and .mm sources — or -x objective-c and -x objective-c++ — are compiled against the Apple Objective-C runtime. Objective-C++ sources also link the C++ standard library. The usual clang flags apply, such as -fobjc-arc, and Foundation programs link with -framework Foundation.

./cc --instrument --ct-modules=alloc -fobjc-arc -framework Foundation -o app main.m

What each module does with Objective-C

trace

Methods are printed under their Objective-C name, such as -[Greeter greet:], not under the mangled C function name the compiler emits for them.

alloc

Two things are tracked in an Objective-C program:

  1. malloc/free and C++ new/delete called from methods, exactly as in C and C++ code.
  2. The Objective-C objects the program creates with +alloc, +allocWithZone:, +new or [[X alloc] init], with or without ARC, until the Objective-C runtime deallocates them.

Objects still alive at exit are reported with the other leaks.

To see deallocations, the runtime replaces -[NSObject dealloc] at start-up with a wrapper that calls the original.

Limits

  • Objects of Apple's system classes (Foundation, CoreFoundation, libobjc) and of classes outside the NSObject hierarchy, such as NSProxy subclasses, are not tracked: some live for the whole process or are released without going through -[NSObject dealloc], and would read as leaks.
  • Only macOS with the Apple runtime is tested. Linux (GNUstep) and Windows are not.

How it is wired

The Objective-C entry points live in their own group of the runtime ABI (CT_RUNTIME_OBJC_ENTRY_POINTS in include/coretrace/runtime_abi.h):

void __ct_objc_track(void* object, const void* cls, const char* site);

The compiler emits these calls for Apple targets only, and only the Apple build of the runtime defines them. They call into libobjc, so they are deliberately kept out of the entry points the runtime always links: an instrumented C program must not end up depending on the Objective-C runtime.

Implementation: src/runtime/ct_runtime_objc.cpp, with unit coverage in test/unit/runtime_objc_test.cpp.

See also

Clone this wiki locally