Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically determine a Cocoa plugin bundle's garbage collection settings?

On Mac OS X using Objective-C 2, plugin bundles can be compiled with one of three garbage collection settings:

  1. Not Supported
  2. Supported (-fobjc-gc)
  3. Required (-fobjc-gc-only)

How can one programmatically query a compiled plugin bundle to determine which of these three settings was used?

like image 399
smokris Avatar asked Jan 19 '10 05:01

smokris


1 Answers

It's part of the __OBJC segment but I don't know of any API that exposes it.

Garbage collected:

cristi:tmp diciu$ otool -v -o ./a.out 
./a.out:
Contents of (__DATA,__objc_classrefs) section
00000001000010b0 0x0
Contents of (__DATA,__objc_imageinfo) section
  version 0
    flags 0x6 OBJC_IMAGE_SUPPORTS_GC

Non garbage collected:

cristi:tmp diciu$ otool -v -o ./a.out 
./a.out:
Contents of (__DATA,__objc_classrefs) section
00000001000010b0 0x0
Contents of (__DATA,__objc_imageinfo) section
  version 0
    flags 0x0

The runtime does this using private functions: see gc_enforcer and it's use of * _objcInfoRequiresGC*

like image 161
diciu Avatar answered Sep 20 '22 10:09

diciu