I'm trying to understand why builds of my app crash, and the leading hypothesis is that the Xamarin.iOS compiler has race conditions that yield different binaries build-to-build.
I'm curious: is there a way to instruct Xamarin and
mtouch to serialize its build steps? Looking at the console output, it appears that the AOT steps are parallelized and happen in random order.
The nature of this hypothesis is unusual -- bugs are seldom in the compiler. So, here is my justification.
The crash happens when the app does interop with a C library entry point that provides an array of strings in an out parameter:
2 mono/object.c mono_string_new
3 mono/object.c mono_string_wrapper
The pointer given to
strlen is not readable (access violation), even
lldb won't read it.
What doesn't cause the crash
- The source code.
- Without making any changes to any source file, I can build an app that won't crash.
- The Mac's hardware.
- I booted to safe mode and restarted, which performs several core maintenance tasks ( http://support.apple.com/en-us/HT201262 )
- I booted to the recovery disk and repaired the partition's folder permissions and the partition itself.
- I booted to an install DVD to repair the disk and verified that S.M.A.R.T. status is "Verified".
- I used the Apple Hardware Test utility to run full diagnostics, and no issues were found.
Why it might be a race condition in the compiler
- Slightly more than 50% of the builds have this crash.
- The stack trace is always the same.
- If a build crashes, it will always crash.
- Conversely, if a build doesn't crash, it will never crash.
- Only one Mac on my team has this problem:
- Bad Mac: Mac Pro 5,1 with 2x 6-Core Intel Xeon and 16 GB RAM
- Good Macs: Mac Mini 5,1 with 1x Intel Core i5 and 8 GB RAM
- Every Mac has the same toolchain:
- OS X 10.9.5
- Xamarin Studio 5.7 (build 661)
- Mono 3.12.0 (detached/a813491)
- Xcode 6.1.1 (6611)
- Xamarin.iOS 18.104.22.168 (Business Edition)
- The previous toolchain had this same crash problem:
- OS X 10.8.5
- Xamarin Studio 4.2.5
- Mono 3.2.7
- Xcode 5.0.2
- Xamarin.iOS 22.214.171.124 (Business edition)
- When I used Instruments to turn off 10 cores on the bad Mac to mimic a good Mac's capabilities, the next 10 consecutive builds were successful.
By changing one thing, the number of enabled cores on my Mac, I can eliminate the problem.