Building mixed-language programs with Apple's Objective-C garbage-collection feature is difficult #843

bos opened this Issue May 24, 2012 · 1 comment


None yet

3 participants

bos commented May 24, 2012

(Imported from Trac #853, reported by @dankna on 2011-05-31)

Ideally, there would be a single flag to set the ObjC garbage collection mode. The three possibilities are, semantically, disabled, optional, and mandatory; I was experimenting with the mandatory mode, but there will be related issues with the others.

One might expect the following to work:

ld-options: -fobjc-gc-only

In fact this will compile successfully but the linked object will have very subtle heap corruption due to the lack of a write barrier (which is implemented by gcc by hooking all field accessors, transparently to the developer). Why yes, this /did/ take me a while to track down! It is necessary to also add:

cc-options: -fobjc-gc-only

But once this is added, it is impossible to link any Haskell objects in, because they do not contain the magic flag which tells the linker they are GC-aware. We therefore need:

ghc-options: -optc-fobjc-gc-only

(I think this might force compilation via C when it wouldn't otherwise be used, which is of course undesirable, but I haven't looked into it.)

This is somewhat of an ugly situation, but fortuitously, it is simple to remedy - Cabal merely needs to understand what needs to be done and do it!

I propose to put the new field in BuildInfo?, as it applies to both libraries and executables; to call it "objc-gc:", and to give it the values "Disabled", "Optional", and "Mandatory". I expect to have a patch for this ready sometime tomorrow.

@ghost ghost was assigned May 24, 2012
jsl commented Feb 28, 2015

Since this ticket doesn't have any activity in the last few years, I propose closing. Please re-open or create a new ticket if this is something that is still desired.

@ttuegel ttuegel closed this Feb 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment