Xcode 12 archive failed: ipatool failed with an exception: #<CmdSpec::NonZeroExitException

I've been struggling with this error for 2 weeks & I tried almost all solutions available online. When trying to export adhoc ipa, I get the below error:
Code Block
{
code = 1061;
description = "ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $ /Applications/Xcode_new.app/Contents/Developer/usr/bin/python3 /Applications/Xcode_new.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -L /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-out/arm64/Payload/HelloWorld.app/Frameworks/XYZ.framework -L /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-out/arm64/Payload/HelloWorld.app/Frameworks --sdk /Applications/Xcode_new.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk -o /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-out/arm64/Payload/HelloWorld.app/HelloWorld --generate-dsym /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-out/arm64/Payload/HelloWorld.app/HelloWorld.dSYM --strip-swift-symbols /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld\nStatus: pid 12181 exit 1\nStdout:\n SDK path: /Applications/Xcode_new.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk\n SDK version: 14.0\n PATH: ['/Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin', '/Applications/Xcode_new.app/Contents/Developer/usr/bin']\n Using: /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo\n MachoInfo: cd /\n ['/Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo', '-info', '/var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld']\n -= Output =-\n Non-fat file: /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld is architecture: arm64\n Exited with 0\n \n Command took 0 seconds\n Using: /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump\n GetUUID: cd /\n ['/Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump', '-u', '/var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld']\n -= Output =-\n UUID: E5D8E7AF-7D34-32E1-9337-A84BC4389DFC (arm64) /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld\n Exited with 0\n \n Command took 0 seconds\n Using: /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/segedit\n ExtractXAR: cd /\n ['/Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/segedit', '/var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/ipatool20201005-8057-ws4wo9/thinned-in/arm64/Payload/HelloWorld.app/HelloWorld', '-extract', 'LLVM', 'bundle', '/var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/HelloWorld8zix1rk8/HelloWorld.arm64.xar']\n -= Output =-\n Exited with 0\n \n Command took 0 seconds\n Bitcode bundle version: 1.0\n Setting platform to: iOS\n Using: /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld\n Linker option verification failed for bundle /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/HelloWorld8zix1rk8/HelloWorld.arm64.xar (unrecognized arguments: -sectalign DATA llvm_prf_cnts -sectalign DATA llvm_prf_data)\n\nStderr:\n\n>\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:373:in `run'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:2808:in `block in CompileOrStripBitcodeInBundle'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:2747:in `each'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:2747:in `CompileOrStripBitcodeInBundle'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:3016:in `block in ProcessIPA'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:2978:in `each'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:2978:in `ProcessIPA'\n /Applications/Xcode_new.app/Contents/Developer/usr/bin/ipatool:3928:in `<main>'";
info = {
};
level = ERROR;
type = exception;
}
);
extractedWatchIPAInputPath = "/var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/XcodeDistPipeline.~~~UmHmV8/Root";
}


The interesting part here is the last Output
Code Block
-= Output =-\n Exited with 0\n \n Command took 0 seconds\n Bitcode bundle version: 1.0\n Setting platform to: iOS\n Using: /Applications/Xcode_new.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld\n Linker option verification failed for bundle /var/folders/n7/bmb8rpvx1r7g762vv1bm66lm0000gn/T/Stocard8zix1rk8/Stocard.arm64.xar (unrecognized arguments: -sectalign DATA llvm_prf_cnts -sectalign DATA llvm_prf_data)


On seeing llvm_prf_cnts & llvm_prf_data, I checked this apple guide and disabled code coverage and also GCC_INSTRUMENT_PROGRAM_FLOW_ARCS

We have Bitcode enabled and the same setup works in Xcode 11.

Can someone please shed some light on why this might be happening? Any leads would be much appreciated. Thanks.

This is a known bug: The linker does not encode -sectalign correctly with bitcode.

The work around (as you surmised) is to disable code coverage. Apparently, you have not actually disabled code coverage to this target.
Thank you for the reply. I double checked the code coverage settings and its disabled.

I disabled them for all the targets but the issue still persists. Is there something that I might be missing?
I had the exact same problem and thank you Sreejith for posting your question - you saved my bacon. I finally found the "Gather coverage for..." setting in the Test section of the target Scheme. Be sure to review all of the schemes for all of your targets. As a sanity check, there was this: codeCoverageEnabled = "YES"> in a TestAction element in Project.xcodeproj/xcshareddata/xcschemes/Project.xcscheme. Fixing the "Gather coverage" setting removed that line. IHTH.

Accepted Answer
Finally found the issue 🎉

CLANG_ENABLE_CODE_COVERAGE was set to NO but the CFLAG -fprofile-instr-generate was still set. Removing the -fprofile-instr-generate worked :)
have exactly same issue with Xcode 12.1.
It's failing on 3rd party framework I use.
I had to set bitcode off & coverage off to make that work (for App project & Pods project).

Hope this issue will gonna be fixed int next Xcode.
Question for Apple Staff:
Is there anything 3rd party library can do to make that work without my need to set bitcode off?

This is a known bug: The linker does not encode -sectalign correctly with bitcode.  


Any idea when this will be fixed and available?
Set below options from Build Settings
  1. Apple Clang - Code Generation --> "ENABLE CODE COVERAGE SUPPORT" need to set "NO" and

  2. Build Option --> "ENABLE BITCODE" need to set "NO"

This works great!
Xcode 12 archive failed: ipatool failed with an exception: #&lt;CmdSpec::NonZeroExitException
 
 
Q