Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crash , Xcode11.4, iOS 10.3.3 10.3.4, iPhone 5c /5 iPad4 (armv7s)

Our app crash on os 10.3.3 10.3.4, iPhone 5c /5 iPad4 (armv7s 32) compiled by Xcode 11.4, swift optimization on. We find the PC register point to a hole address without virtual address and no stack information. If we close swift optimization, it works.

So do anyone find the problem and any solution?

It's certain that it's related to Xcode 11.4 swift optimization.

I find the same question here. https://www.reddit.com/r/iOSProgramming/comments/frcpsc/xcode_114_builds_crashes_on_ios_10/

Incident Identifier: 2224949E-E5E3-479C-9B08-4FD1473144B3
CrashReporter Key:   052c9a28855da965790a6dcc0885097a66ee4eff
Hardware Model:      iPad3,4
Process:             AAAAA [34872]
Path:                /private/var/containers/Bundle/Application/xxxxxx....
Identifier:          com.xxx.xxxxx
Version:             xxxx
Code Type:           ARM (Native)
Role:                Non UI
Parent Process:      launchd [1]
Coalition:           com.xxx.xxxxx [1932]


Date/Time:           2020-03-30 22:42:49.2564 +xxx
Launch Time:         2020-03-30 22:42:47.0000 +xxx
OS Version:          iPhone OS 10.3.3 (14G60)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x015fa500
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   ???                             0x015fa500 0 + 23045376
like image 572
Victor Choy Avatar asked Apr 07 '20 07:04

Victor Choy


2 Answers

After lots of analysis such as log and instruction debug, I am surely it's a bug xcode 11.4 swift compiler optimization. Detailedly, the optimization cause a stack pointer (fp) messy at the point opening a new function stack frame. I show it in the following.

Here is a helper function type metadata accessor for myapp.MainViewController at <compiler-generated> generated by compiler in our mainviewcontroller.

enter image description here

<+0>, <+4> is wrong. It should be

0x6cd85c <+0>:   push.w {r4, r5, r6, r7, lr}
0x6cd860 <+4>:   add  r7, sp, #0xc

r7 is fp. so the error instruction <+0> don`t save r7, and <+4> sub ins makes r7 lower than sp a lot that causes all whole stack messy. So It's wrong clearly.

This is what happens when the ins execute.

Before: enter image description here

After: enter image description here

The whole stack loses becuase of fp error.

And we can also verify that in xcode 11.3. enter image description here <+0> <+2> is the same as our expectation above.

So we have to downgrade to xcode 11.3 as well and use runtime refection to adapt new iOS SDK feature that should be call in xcode 11.4.

like image 85
Victor Choy Avatar answered Dec 22 '22 19:12

Victor Choy


We have also encountered multiple crashed on old 32-Bit devices with iOS 9 or 10. Recompiling with Xcode 11.3.1 fixed those random crashes in my case...

There is also a open Bug for this topic at https://bugs.swift.org/browse/SR-12511

like image 45
niggeulimann Avatar answered Dec 22 '22 17:12

niggeulimann