10

When I try to build my app with LLVM 2.0 in XCode 4.0.1 and any level or optimization that is not none (anything but -O0), the app crashes after i launch it on the device (simulator is ok). I can't seem to debug the crash as it does not happen when i build in xcode and attach via GDB/LLDB. Also, the crash only happens when i build the app on the command line with xcodebuild; building via the XCode IDE doesn't crash even with the exact same project settings. I can't see any useful information in the crash logs, as the crash happens outside my code:

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00b53400
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   ???                             0x00b53400 0 + 11875328

It won't symbolicate correctly since it doesn't know which library the crash happened in.

The device console shows some NSLog statements that our app makes at startup, then the first screen's UI is loaded and drawn, and after that the crash happens. Building with no optimizations, or building with GCC 4.2 with any optimization level works fine.

What could be happening here, and how can i debug it? What could the XCode IDE be doing differently when it builds and deploys the app vs. the xcodebuild command line interface?

Kevlar
  • 8,804
  • 9
  • 55
  • 81

2 Answers2

9

We've had the same issue with our app. It only affected armv6 code in Release/Distribution builds and thus only the iPhone 3G and the iPod Touch 2G. But contrary to your description, it was reproducible with XCode (we don't use xcodebuild).

Obviously the generated code corrupts the stack pointer. As a consequence, you can't really debug it and the crash logs are worthless. With the debugger, it could stop at viewWillAppear:animated of the first view that should be displayed. But quickly after that, the app always crashed.

Switching to an older compiler solved the problem.

I've filed a bug with Apple. Please file one too as it is said to increase the priority of the bug.

There are more people reporting the same problem:

Codo
  • 75,595
  • 17
  • 168
  • 206
  • That's weird, since my co-workers and i have seen it happen on the iPad and my iPhone 3gs as well. – Kevlar Mar 30 '11 at 19:58
  • 1
    thanks for the clarification. I'm having the same problem. I can reproduce as well, and can confirm. I am running XCode 4.0 (oops time to upgrade!) and iOS 3.1 on an iPhone 3G device. My build settings are LLVM 2.0 with optimization set "Fastest, smallest". App crashes with ANY optimization other than "None", so far with every setting I've tried, as @Kevlar suggests. – makdad Apr 04 '11 at 04:56
  • 1
    Same problem with XCode 4.1, even with other compilers (gcc or gcc-llvm), for any optimisation level higher than -O0. – Eino Gourdin Apr 22 '11 at 09:54
  • 1
    You probably mean XCode 4.0.1. For a few days now, XCode 4.0.2 is available. And the README says: "Fixed a bug in LLVM compiler 2.0 that could cause apps to crash on iOS devices". Maybe that's going to fix it. I'll give a try later. – Codo Apr 22 '11 at 10:11
  • I finally got hold of an iPhone 3G and retested it with XCode 4.0.2. The good new is: the problem is gone. – Codo Aug 24 '11 at 10:58
  • Interestingly, I'm encountering a similar issue in Xcode 4.2, where some layout issues with UITableViewCell only occur on armv6 hardware, for which the binaries are compiled using *any* level of LLVM compiler optimization: http://stackoverflow.com/questions/7739563/app-store-code-runs-different-from-xcode-device-code-on-iphone-3g – Craig Otis Oct 12 '11 at 13:16
1

Upgrade to Xcode 4.0.2.

It fixed this issue (crash on launch for ARMv6 but not ARMv7 with optimization turned on) for us.

Ben Lachman
  • 3,083
  • 1
  • 28
  • 44
  • 1
    For a little more color. It seems LLVM 1.6-2.0 with Xcode 3.2.x-4.0.1 can produce code that has this crash in it. In addition, the level of optimization seems to have no effect whatsoever, anything more than -O0 will make it happen. – Ben Lachman Apr 24 '11 at 05:05
  • 3
    The other workaround is to conditionally build -O0 for ARMv6 while leaving ARMv7 building with -Os or whatever you use. To do this in Xcode 4.x click on the plus beside "Optimization Level" in your target's build settings and then special case ARMv6. Make sure you clean and recompile after this since Xcode doesn't seem to pick up the change automatically. – Ben Lachman Apr 24 '11 at 05:07
  • +BenLachman that's a fantastic tip about conditional optimization on a per-architecture basis, I had no idea you could do that. In future, I may build all my ARMv6 code with -O0 - there are only a small percentage of customers left with iPhone 3G devices and the losses in performance are outweighed by the gains in stability IMHO – Carlos P Nov 01 '11 at 09:47