TestFlight watchOS build crashes on Apple Watch Series 3 devices (32-bit) (Bitcode related?)

Hello!

I have a WatchOS Application on TestFlight that is crashing on startup on Apple Watch Series 3 devices (32-bit). It works flawlessly on Simulators (Xcode 11.7) and Apple Watch Series 4. I am using Alamofire 5.2.2 with Swift Package Manager. Latest Xcode (version 11.7). The device is Apple Watch Series 3 devices (32-bit) running latest final watchOS (version 6.2.8).

I am calling a REST service that returns a JSON error file (response) and HTTP status code 401 (Unauthorized) if no gateway access token is given.

As I said this works in simulator and Apple Watch Series 4 device. I suspect of Bitcode, as in the past versions I had an iOS companion app and disabled bitcode generation, but now we only have the watch app and I cannot disable Bitcode generation.

What happened instead?

The crash is somewhat like this:

Code Block
Hardware Model: Watch3,4
Process: Watch App Extension [616]
Version: 132 (1.0)
AppVariant: 1:Watch3,4:6
Beta: YES
Code Type: ARM (Native)
Role: Foreground
Parent Process: launchd [1]
Date/Time: 2020-09-02 15:52:50.8659 -0300
Launch Time: 2020-09-02 15:52:48.0000 -0300
OS Version: Watch OS 6.2.8 (17U63)
Release Type: User
Baseband Version: n/a
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000060
VM Region Info: 0x60 is not in any region. Bytes before following region: 2310048
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
TEXT 00234000-0038c000 [ 1376K] r-x/r-x SM=COW ...App Extension
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [616]
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libswiftCore.dylib 0x6f7f4060 static _SetStorage.allocate+ 864352 (scale:age:seed:) + 16
1 libswiftCore.dylib 0x6f7f007e static _SetStorage.allocate+ 847998 (capacity:) + 126
2 Watch App Extension 0x002fcca4 specialized protocol witness for Collection.endIndex.getter in conformance [A] + 822436 (_$s30Watch_App_Extension12SimulaCambioMp:0)
3 Watch App Extension 0x002ebcfe static ResponseSerializer.defaultEmptyRequestMethods.getter + 752894 (contaFormatada.modify:102)
4 Watch App Extension 0x002801e2 AlamofireLoginService.loginSmartwatch(completion:) + 311778 (AlamofireLoginService.swift:49)
5 Watch App Extension 0x0027b568 specialized InterfaceController.doLogin(:semProgresso:) + 292200 (InterfaceController.swift:0)
6 Watch App Extension 0x00275ec6 InterfaceController.awake(withContext:) + 270022 (InterfaceController.swift:246)
7 Watch App Extension 0x00276888 @objc InterfaceController.awake(withContext:) + 272520 (<compiler-generated>:0
8 WatchKit 0x5f1959c2 _WKInterfaceControllerCreateClass + 444
9 WatchKit 0x5f1ceef4 153-[SPRemoteInterface createViewController:className:properties:contextID:info:gestureDescriptions:clientIdentifier:interfaceControllerCreationCompletion:]_block_invoke_3 + 348
10 WatchKit 0x5f1cebbe 153-[SPRemoteInterface createViewController:className:properties:contextID:info:gestureDescriptions:clientIdentifier:interfaceControllerCreationCompletion:]_block_invoke_2 + 1070
11 WatchKit 0x5f194130 spUtils_dispatchAsyncToMainThread + 22
12 WatchKit 0x5f1ce75c 153-[SPRemoteInterface createViewController:className:properties:contextID:info:gestureDescriptions:clientIdentifier:interfaceControllerCreationCompletion:]_block_invoke + 156
13 WatchKit 0x5f1956c4 -[SPRemoteInterface performAfterApplicationDidFinishLaunching:] + 40
14 WatchKit 0x5f195410 -[SPRemoteInterface createViewController:className:properties:contextID:info:gestureDescriptions:clientIdentifier:interfaceControllerCreationCompletion:] + 282
15 WatchKit 0x5f23564a __178-[SPExtensionConnection interfaceViewController:createCompanionControllerClass:properties:initializationContextID:info:gestureDescriptions:interfaceControllerCreationCompletion:]_block_invoke + 294
16 WatchKit 0x5f192ba2 -[SPExtensionConnection performOnSendQueue:syncIfUnsuspended:] + 464
17 WatchKit 0x5f195298 -[SPExtensionConnection interfaceViewController:createCompanionControllerClass:properties:initializationContextID:info:gestureDescriptions:interfaceControllerCreationCompletion:] + 284
18 WatchKit 0x5f1950f4 -[SPApplicationDelegate viewController:createWKInterfaceControllerClass:properties:contextID:creationCompletion:] + 1588
19 WatchKit 0x5f183740 -[SPInterfaceViewController loadView] + 2004
20 UIKitCore 0x678d7aca -[UIViewController loadViewIfRequired] + 160
21 UIKitCore 0x678d80f0 -[UIViewController view] + 24
...
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000001 r1: 0x00000000 r2: 0x00000001 r3: 0x00000000
r4: 0x00000001 r5: 0x00000001 r6: 0x000000e4 r7: 0x27bcd708
r8: 0x00000000 r9: 0x00000000 r10: 0x00000000 r11: 0x16db3fd0
ip: 0xfff00000 sp: 0x27bcd670 lr: 0x6f7f007f pc: 0x6f7f4060
cpsr: 0x60000030
Binary Images:
0x234000 - 0x3d3fff Watch App Extension armv7k <53780c55b55534578139202ab803cb6a> /var/containers/Bundle/Application/8D10BAB7-2EDF-4C98-8558-915BEBC0F499/Watch App.app/PlugIns/Watch App Extension.appex/Watch App Extension

NOTE
Unfortunately this is a big project for a bank. I do not have yet a demo project because the error only occurs via TestFlight installing on Apple Watch Series 3 (32-bits). Already opened an issue on Alamofire GitHub but they said maybe it is an Apple TestFlight generation (bitcode?) error. < https://github.com/Alamofire/Alamofire/issues/3295 >
Please file Feedback about this. Thanks!
I filed the feedback: FB8612887.

Also, as I commented on the Alamofire issue (https://github.com/Alamofire/Alamofire/issues/3295), I rolled back Alamofire to version 4.9.1 and it is working now with TestFlight version!

I guess with the latest Alamofire 5, the TestFlight (Bitcode?) compilation is doing something wrong for this specific device... As pointer in this crash log:
Code Block
Thread 0 Crashed:
0 libswiftCore.dylib 0x6fb90060 static _SetStorage.allocate+ 864352 (scale:age:seed:) + 16
1 libswiftCore.dylib 0x6fb8c07e static _SetStorage.allocate+ 847998 (capacity:) + 126
2 Watch App Extension 0x00315fb8 specialized Set.init(arrayLiteral:) + 319416 (<compiler-generated>:0)


If you need some other information, please feel free to contact me. Thank you!
Can't delete posts.
Full details about this issue on Alamofire GitHub: https://github.com/Alamofire/Alamofire/issues/3295
I also see this with a different library. Also filed feedback FB8732976. https://github.com/tikhop/ASN1Swift/issues/1

Crash only happens when importing said library with swift package manager, only in app store or testflight builds and only on series 3 watches. Does not happen on a series 3 watch running via xcode or if I include the files manually with my project and not use the swift package manager.
I'm having the same issue in my app when it uses Swift Packages. Also submitted feedback FB8949030.
I'm having the same problem on my project that uses a private swift package. Filled radar FB8949030.
I'm having the same problem. As long as my watchOS app is installed via TestFlight or the App Store, it crashes on startup. And it only reproduces on Apple Watch S3 (armv7k). My watch app target also uses Swift Package Manager to reference dependencies.

However, if the exact same Archive is installed via Xcode's Devices Manager, the app no longer crashes! This seems to indicate that it's not a compiler or build issue, but rather a TestFlight/App Store distribution issue for the app.

The crash log indicates that the crash was due to a segmentation fault:

Code Block log
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000034
VM Region Info: 0x34 is not in any region. Bytes before following region: 2834380
...
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [1746]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 WatchApp Extension 0x004311be _hidden#5646_ + 14 (hidden#5809_:0) <== 🤔 impossible crash!
1 WatchApp Extension 0x0042f62c _hidden#5611_ + 34
2 WatchApp Extension 0x0042e76a _hidden#5596_ + 40
3 WatchApp Extension 0x00327dc8 StoreKey.init(wrappedValue:key:) + 114 (__hidden#969_:19)
4 WatchApp Extension 0x002d4ff2 Store.init() + 116 (Store.swift:24)
...
7 libdispatch.dylib 0x4d8b6100 _dispatch_once_callout + 14 (once.c:52)


So, to summarize, the necessary factors for this problem to be reproduced are:
  1. Apple Watch with armv7k CPU

  2. using Swift Package Manager

  3. distributed via TestFlight/App Store

The problem seems to be happening again. Do you have some new information on this and/or FB8612887?
Workaround: just set "Dead Code Stripping" to No in build settings of the watch app extension target. The app won't crash anymore.

Of course, this will create a larger binary. But anyway, it works.
Sadly, setting DEAD_CODE_STRIPPING to NO does not resolve the issue for me. I'm having the issue with a dynamic library, so perhaps that setting doesn't help in that situation.

I also tried setting PRESERVE_DEAD_CODE_INITS_AND_TERMS to YES. This didn't help either.

UPDATE:
It looks like linking against a dynamic lib from a swift package, the -dead_strip flag is added no matter what.
Has anyone tried this with watchOS 7.4 RC or Xcode 12.5 RC?

I'm facing the same issue, it would seem.

Hi, how did you get the crash logs?

TestFlight watchOS build crashes on Apple Watch Series 3 devices (32-bit) (Bitcode related?)
 
 
Q