Question

My application builds, runs, simulates etc. etc. fine! Everything works 100% on both the simulators and physical devices. No errors or warnings during building.

Now, when I try to archive my project, I get the following error:

0  clang             0x000000010bdb3472 _ZL15PrintStackTracePv + 34
1  clang             0x000000010bdb38f9 _ZL13SignalHandleri + 553
2  libsystem_c.dylib 0x00007fff8bd8ccfa _sigtramp + 26
3  libsystem_c.dylib 0x0000000000000001 _sigtramp + 18446603338169922337
4  clang             0x000000010bc7fbbf (anonymous namespace)::ObjCARCOpt::runOnFunction(llvm::Function&) + 7407
5  clang             0x000000010b0502b2 llvm::FPPassManager::runOnFunction(llvm::Function&) + 322
6  clang             0x000000010b052baf (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) + 1039
7  clang             0x000000010b050bc1 llvm::MPPassManager::runOnModule(llvm::Module&) + 289
8  clang             0x000000010b0505c5 llvm::PassManagerImpl::run(llvm::Module&) + 277
9  clang             0x000000010b0504ad llvm::PassManager::run(llvm::Module&) + 13
10 clang             0x000000010b02f0e8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 4424
11 clang             0x000000010b02c941 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 513
12 clang             0x000000010aef83f6 clang::ParseAST(clang::Sema&, bool) + 406
13 clang             0x000000010aef6ed7 clang::CodeGenAction::ExecuteAction() + 855
14 clang             0x000000010aec943f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 879
15 clang             0x000000010aec80cb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2683
16 clang             0x000000010aeba8ce cc1_main(char const**, char const**, char const*, void*) + 5086
17 clang             0x000000010ae950d8 main + 648
18 clang             0x000000010ae94e44 start + 52
clang: error: unable to execute command: Segmentation fault: 11
clang: error: clang frontend command failed due to signal 2 (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.
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/yn/jhqtwmzx2l31sytjj7ltz_qc0000gn/T/Image-u5GlrW.mii
clang: note: diagnostic msg: /var/folders/yn/jhqtwmzx2l31sytjj7ltz_qc0000gn/T/Image-u5GlrW.sh
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 254

and I have no idea why. I now the problem comes from Image.mm that I am using from the simple-iphone-image-processing project. And I think it has to do with ARC. Can anyonw shed some more light on this?

Thanks


UPDATE

OK, so I just tried it a bunch of times and it worked. So the problem is intermittent. I'm leaving this question here if anyone else maybe has something to say.

Was it helpful?

Solution

The function that is breaking is ObjCARCOpt::runOnFunction(llvm::Function&). Just for giggles, I posted the runOnFunction() code below. The purpose of this function is to optimize ARC-related object code in the llvm::Function object that is passed in. That's fine, but there seems to be a bug in the compiler related to Objective-C++ handling, which frankly doesn't surprise me.

Bug reports have already been submitted to Apple (here, here, probably other places). You should report it too.

Until then, there are a few things I might suggest.

1) Since the problem is intermittent, just get on with your project. This could work out for you, or maybe not. After all, compilers are supposed to be deterministic...

2) Try to turn off ARC for your Obj-C++ stuff. This is probably the simplest way.

3) Turn off ARC optimizations. Do this by omitting -enable-objc-arc-opts from your build. How to do this using XCode build settings is left as an exercise for the reader. Anyway I think your best bet is 2).

Code from llvm-3.0.src/lib/Transforms/Scalar/ObjCARC.cpp is below. Your best bet is to get out at if (!Run) return false;. Run will be false if ARC is disabled in the module being parsed. Good luck, don't forget to submit that bug report!

bool ObjCARCOpt::runOnFunction(Function &F) {
  if (!EnableARCOpts)
    return false;

  // If nothing in the Module uses ARC, don't do anything.
  if (!Run)
    return false;

  Changed = false;

  PA.setAA(&getAnalysis<AliasAnalysis>());

  // This pass performs several distinct transformations. As a compile-time aid
  // when compiling code that isn't ObjC, skip these if the relevant ObjC
  // library functions aren't declared.

  // Preliminary optimizations. This also computs UsedInThisFunction.
  OptimizeIndividualCalls(F);

  // Optimizations for weak pointers.
  if (UsedInThisFunction & ((1 << IC_LoadWeak) |
                            (1 << IC_LoadWeakRetained) |
                            (1 << IC_StoreWeak) |
                            (1 << IC_InitWeak) |
                            (1 << IC_CopyWeak) |
                            (1 << IC_MoveWeak) |
                            (1 << IC_DestroyWeak)))
    OptimizeWeakCalls(F);

  // Optimizations for retain+release pairs.
  if (UsedInThisFunction & ((1 << IC_Retain) |
                            (1 << IC_RetainRV) |
                            (1 << IC_RetainBlock)))
    if (UsedInThisFunction & (1 << IC_Release))
      // Run OptimizeSequences until it either stops making changes or
      // no retain+release pair nesting is detected.
      while (OptimizeSequences(F)) {}

  // Optimizations if objc_autorelease is used.
  if (UsedInThisFunction &
      ((1 << IC_Autorelease) | (1 << IC_AutoreleaseRV)))
    OptimizeReturns(F);

  return Changed;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top