Skip to content

Check if an app is using GC

hewigovens edited this page Mar 9, 2014 · 1 revision

####Basic ideas

objc runtime contains a struct called objc_image_info, you can check it out:

typedef struct {
    uint32_t version; // currently 0
    uint32_t flags;
} objc_image_info;

// masks for objc_image_info.flags
#define OBJC_IMAGE_IS_REPLACEMENT (1<<0)
#define OBJC_IMAGE_SUPPORTS_GC (1<<1)
#define OBJC_IMAGE_REQUIRES_GC (1<<2)
#define OBJC_IMAGE_OPTIMIZED_BY_DYLD (1<<3)

from objc-private.h

####Examples

otool

otool -oV /Applications/Mou.app/Contents/MacOS/Mou | tail -3
Contents of (__DATA,__objc_imageinfo) section
  version 0
    flags 0x6 OBJC_IMAGE_SUPPORTS_GC

class-dump

#pragma mark -

//
// File: /Applications/Mou.app/Contents/MacOS/Mou
// UUID: 72CC142C-54F0-3F3D-992B-30A8783E282A
//
//                           Arch: x86_64
//       Minimum Mac OS X version: 10.7.0
//                    SDK version: 10.8.0
//
// Objective-C Garbage Collection: Required
//
You can’t perform that action at this time.