Repository navigation
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.mMethods are printed under their Objective-C name, such as -[Greeter greet:], not under the
mangled C function name the compiler emits for them.
Two things are tracked in an Objective-C program:
-
malloc/freeand C++new/deletecalled from methods, exactly as in C and C++ code. - The Objective-C objects the program creates with
+alloc,+allocWithZone:,+newor[[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.
- Objects of Apple's system classes (Foundation, CoreFoundation, libobjc) and of classes outside
the
NSObjecthierarchy, such asNSProxysubclasses, 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.
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.
- Instrumentation — the passes and the runtime ABI
- Runtime Library — hook implementations and environment overrides
Start
Architecture
Instrumentation
Platforms
Developer