Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjC ARC contraction (clang crash)

I always hesitate to add a brand new question to the killer forums here, but I haven't seen anything close to this bug.

Seems clang has crashed on my while compiling one of my .m files. If anyone has seen or knows of any solution for the below I'd be immensely obliged.

This error occurs when I build for armv6 in a release configuration using XCode 4.4.1

But does not occur when I build for armv6 in a debug configuration, or release for armv7, armv7s or i386.

The specific error is "ObjC ARC contraction":

    1. <eof> parser at end of file
    2. Code generation
    3. Running pass 'Function Pass Manager' on module '/Users/Me/Documents/ThisProject/iOS/..../ClassFoo.m'.
    4. Running pass 'ObjC ARC contraction' on function '@"\01-[ClassFoo evalJS:]"'
    clang: error: unable to execute command: Segmentation fault: 11
    clang: error: clang frontend command failed due to signal (use -v to see invocation)
    clang: note: diagnostic msg: Please submit a bug report to http://developer.apple.com/bugreporter/ and include command line arguments and all diagnostic information.

In the ../Intermediaries/Project.build/armv6/ folder I see:

    ClassFoo.dia

and I should see (like all of its surrounding files)

    ClassFoo.d
    ClassFoo.dia
    ClassFoo.o

Here are the top 4 of the clang stack, in case someone recognizes something in it:

    0  clang             0x00000001010536f2 main + 17107682
    1  clang             0x0000000101053b79 main + 17108841
    2  libsystem_c.dylib 0x00007fff93c428ea _sigtramp + 26
    3  libsystem_c.dylib 0x00007fff93c7a54e tiny_malloc_from_free_list + 1078

edit: I also noticed when trying again recently that I'm getting complaints about the -fno-objc-arc flag -- perhaps the compiler sym-links are pointing at the wrong binaries?

Thanks in advance,

Miles

like image 282
Miles Alden Avatar asked Nov 16 '12 03:11

Miles Alden


1 Answers

Thanks for all your interest, and I'm sorry to have to answer this question myself but no other solution I've tried has resulted in anything successful. I've done my best to document my adventure here as a how-to-guide to hopefully help a few others.

The short version:

  1. Xcode 4.5+ does not support building to armv6 (iphone 3g).
  2. With fresh installs of 4.5 & 4.4.1 I experienced various versions of the original error.
  3. The reason is two-fold:

    • xcspec files Xcode uses do not include entries for this architecture.
    • 4 needed libclang_rt*.a files have had their armv6 slices stripped.
  4. There is a solution! (see long version below)

The long version:

Amongst the many many frustrating attempts I made to sort this issue out, such as searching SO forums, searching apple dev forums, googling, endlessly fiddling with project settings, copying earlier SDKs into the Xcode.app packages, posting this question, filing a bug report with Apple, etc. ad infinitum <-- means, "and so in into infinity" each seemed to have either nothing pertinent to reveal or only a tiny tidbit of information.

The recipe for this solution finally took one frustrated and determined developer and the culmination of everything in one very long night.

So where's the how-to?

( Right here, bro )

There are about 12 steps, so don't forget the final ones below the images!

Disclaimer: This is my own solution and it works great for me, but if you're not sure about what's going on or what you're doing please be very careful and realize that I will assume no responsibility for any damages you may incurr by trying to follow these steps. That said, here you go!

  1. If you don't already have a copy, download Xcode 4.4.1 from http://connect.apple.com
  2. Extract /PATH_TO_YOUR_Xcode_4.4.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
  3. Copy it to /PATH_TO_YOUR_Xcode_4.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
  4. Now you'll edit 4 Xcode .xcspec files in your Xcode 4.5:

    • Navigate here: /PATH_TO_YOUR_Xcode_4.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications
    • Select these files:

      • iPhoneXcode4Options.xcspec
      • iPhoneOSArchitectures.xcspec
      • iPhoneCompilerOptions.xcspec
      • iPhoneClangOptions.xcspec
    • Right-click and select "Open with Xcode"

  5. Repeat for Xcode 4.4.1, and stick the two windows side-by-side (just makes this easier).
  6. You're going to add armv6 to several entries as below: iPhoneClangOptions.xcspec

  7. Here again: iPhoneCompilerOptions.xcspec

  8. And here: iPhoneXcode4Options.xcspec

  9. Here you cut & paste an entry from Xcode 4.4.1 to Xcode 4.5: iPhoneOSArchitectures.xcspec

  10. Alright you completed that tediousness, yay! Save the edited files and close them all. Next you have to create new libclang_rt*.a files to handle compiling these arches. This step is more easily done in Terminal. Enter these commands:

Make sure the backups copy and there isn't some error in paths or typing!

 cd /PATH_TO_YOUR_Xcode_4.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/4.2/lib/darwin

 sudo mkdir armv6_extractions

 lipo -extract armv6 -output armv6_extractions/libclang_rt.ios.armv6.a libclang_rt.ios.a
 lipo -extract armv6 -output armv6_extractions/libclang_rt.profile_ios.armv6.a libclang_rt.profile_ios.a
 lipo -extract armv6 -output armv6_extractions/libclang_rt.cc_kext.armv6.a libclang_rt.cc_kext.a

 sudo cp -R armv6_extractions  /PATH_TO_YOUR_Xcode_4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/4.2/lib/darwin

 cd /PATH_TO_YOUR_Xcode_4.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/4.2/lib/darwin

 sudo mkdir originals
 sudo cp libclang_rt.ios.a originals/
 sudo cp libclang_rt.cc_kext_ios5.a originals/
 sudo cp libclang_rt.profile_ios.a originals/

 lipo -create -output libclang_rt.ios.a armv6_extractions/libclang_rt.ios.armv6.a originals/libclang_rt.ios.a
 lipo -create -output libclang_rt.cc_kext_ios5.a armv6_extractions/libclang_rt.cc_kext.armv6.a originals/libclang_rt.cc_kext_ios5.a
 lipo -create -output libclang_rt.profile_ios.a armv6_extractions/libclang_rt.cc_kext.armv6.a originals/libclang_rt.profile_ios.a
  1. Restart Xcode 4.5

    ^...I wrote "11" here...why's it showing as "1"?

  2. Open your project and edit your settings accordingly. I recommend that you create a separate configuration just for building to armv6, and lipo everything together when you're done.

    • Add armv6 to Valid Architectures
    • Add armv6 to Architectures
    • For your specific armv6 configuration, set Base SDK to iOS 5.x (whatever is now listed in the drop-down menu)
    • Set your deployment target as needed ( I have built as low as iOS4.1 so far, and I believe the iOS5.x sdk you installed in the beginning can deploy as low as 4.x )

Okay, I think that's all.

If anyone sees any edits that need to be made PLEASE do so, and I welcome any feedback that anyone has to give here.

If something goes wrong, fingers crossed you can always reinstall your Xcode and try again (or not).

Best of luck.

like image 146
Miles Alden Avatar answered Sep 24 '22 15:09

Miles Alden