Bug 6358 - Using an ARC library in iOS 4.x causes a crash
Summary: Using an ARC library in iOS 4.x causes a crash
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-08-01 14:39 UTC by Nic Wise
Modified: 2012-08-09 14:05 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

sample for this case (5.95 MB, application/zip)
2012-08-01 14:40 UTC, Nic Wise
Xcode screenshot (295.62 KB, image/png)
2012-08-08 21:41 UTC, Sebastien Pouliot

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Nic Wise 2012-08-01 14:39:34 UTC
This came out of Desk case 14586: https://xamarin.desk.com/agent/case/14586

The customer has a XMPP library which uses ARC, and has wrapped it in a small Obj-C wrapper. If this runs in iOS5, it works fine. If it's run in iOS4, it crashes on the device with this error:

dyld: lazy symbol binding failed: Symbol not found: _objc_release
Referenced from:
Expected in: /usr/lib/libobjc.A.dylib

dyld: Symbol not found: _objc_release
Referenced from:
Expected in: /usr/lib/libobjc.A.dylib

(as reported, I cant repro as I dont have a device)

I have distilled the sample down to the Obj-C wrapper which just NSLogs a line when it init's, and one when setupLogging is called. This works on iOS5 and crashes on iOS4 in the simulator:

2012-08-01 14:37:17.471 nictest[22406:1207] hello from init

  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend (intptr,intptr) <IL 0x00026, 0xffffffff>
  at XmppBinding.XMPP.sharedInstance () <IL 0x0000a, 0x0001f>
  at nictest.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication,MonoTouch.Foundation.NSDictionary) [0x00015] in /Users/nic/Desktop/sample/MT/nictest/AppDelegate.cs:33
  at (wrapper runtime-invoke) <Module>.runtime_invoke_bool__this___object_object (object,intptr,intptr,intptr) <IL 0x00066, 0xffffffff>
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at nictest.Application.Main (string[]) [0x00000] in /Users/nic/Desktop/sample/MT/nictest/Main.cs:17
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

	0   nictest                             0x0009081c mono_handle_native_sigsegv + 284
	1   nictest                             0x00005938 mono_sigsegv_signal_handler + 248
	2   libsystem_c.dylib                   0x920cb59b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libobjc.A.dylib                     0x02a9ad9b _class_initialize + 380
	5   libobjc.A.dylib                     0x02aa273f prepareForMethodLookup + 73
	6   libobjc.A.dylib                     0x02a99069 lookUpMethod + 86
	7   libobjc.A.dylib                     0x02a991d6 _class_lookupMethodAndLoadCache + 40
	8   libobjc.A.dylib                     0x02aac0e3 objc_msgSend + 87
	9   ???                                 0x077f2448 0x0 + 125772872
	10  ???                                 0x077f0ca0 0x0 + 125766816
	11  ???                                 0x077f0ddf 0x0 + 125767135
	12  nictest                             0x00009cf2 mono_jit_runtime_invoke + 722

(more stacktrace)

I have asked the customer (Nick) to confirm that this sample also does the same on his device, and to add himself into this bug.
Comment 1 Nic Wise 2012-08-01 14:40:31 UTC
Created attachment 2286 [details]
sample for this case
Comment 2 Nic Wise 2012-08-01 14:43:15 UTC
I should also add that:

xcode sample, ios5: works
xcode sample, ios4: works (simulator)
MT sample, ios5: works
MT sample, ios4: doesnt' work (simulator)
Comment 3 Nick Rubell 2012-08-01 15:03:47 UTC
Yes, I confirm this sample does the same. I am getting the dyld: Symbol not found: _objc_release error.
Comment 4 Sebastien Pouliot 2012-08-08 21:41:11 UTC
Created attachment 2332 [details]
Xcode screenshot

Nic[k], I can duplicate the issue with the attached MonoTouch solution.

However when I tried the Xcode sample it failed with xcode/simulator for me (see screenshot).

2012-08-08 21:33:34.742 testtest[48130:207] hello from init
dyld: lazy symbol binding failed: Symbol not found: _objc_release
  Referenced from: /Users/sebastienpouliot/Library/Application Support/iPhone Simulator/4.3.2/Applications/0F9A3028-D6B5-42D1-9298-D096A27BF2B3/testtest.app/testtest
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

dyld: Symbol not found: _objc_release
  Referenced from: /Users/sebastienpouliot/Library/Application Support/iPhone Simulator/4.3.2/Applications/0F9A3028-D6B5-42D1-9298-D096A27BF2B3/testtest.app/testtest
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation

That looks pretty much like the original report (but from Xcode).
Comment 5 Nick Rubell 2012-08-08 21:59:59 UTC
Is there any workaround? 

I have another XCode project, it uses ARC and it works fine on iOS 4. Maybe this is related to how MonoTouch generates the project?
Comment 6 Sebastien Pouliot 2012-08-09 09:39:33 UTC
There might be a workaround with MonoTouch but the above (comment #4) failed using Xcode alone.

It could be that the version of Xcode used to compile the native library plays a role (which is why it would work in some cases while it fails for me).

Some people with the same issue (still w/Xcode) reported using "-fobjc-arc" helped (at least in some cases*). However it did not help when I tried it with the above sample (MT version)* but it's still worth a try with your application.

* Likely because newer versions of Xcode does not include this option anymore, see: http://stackoverflow.com/q/8756418/220643

Another answer (to the same SO question) suggest to link against libarclite_iphoneos.a (or libarclite_iphonesimulator.a for the simulator, sadly Apple gave them different names).

This (using libarclite_iphonesimulator.a) worked for me using the MonoTouch sample and the iOS simulator for iOS 4.3.

Please let us know if one of the above solution is working for you so we can close the bug (and be able to suggest this again if the same situation occurs).
Comment 7 Nick Rubell 2012-08-09 13:44:13 UTC
Thank you, Sebastien. Adding the library explicitly helped.
What I did, since my Xcode version is 4.3.2, I added the following line to "Additional mtouch arguments" to my "iPhone" configuration and it worked:

 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc -larclite_iphoneos

As of the simulator, -larclite_iphonesimulator shall be used.
Comment 8 Sebastien Pouliot 2012-08-09 14:05:34 UTC
Yes, that's the best way to do it since Apple used different names (so [LinkWith] can't be used). 

I'm glad this worked in your case too :-) I'm still a bit surprised I had such different results with my (older) Xcode.