In the debugger console, if you run image list does it show the libswift_Concurrency.dylib as being loaded?
Doug
tera
23
Nope, 264 items on the list but not that one. Tell me what to do while I am still in debugger.
btw, this is what it tries to de-mangle:
0x1008835d4 <+28>: adr x0, #0xa78c ; demangling cache variable for type metadata for Swift.Optional<Swift.TaskPriority>
That explains the crash, because the runtime is looking for a symbol in libswift_Concurrency.dylib, but that shared library hasn't been loaded. That means either it isn't there in the .app, or it's somehow invalid. If you look at the .app directory on disk, does it have libswift_Concurrency.dylib in its Frameworks directory? If so, is it ~1MB or is it ~11MB?
Doug
1 Like
tera
25
Yes, it is (in the app that is in the build folder on mac). It is 1MB. I also see it mentioned in CodeResources.
From the build log:
Copying /Applications/Xcode-13.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib to /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
/Applications/Xcode-13.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip /Applications/Xcode-13.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib -r -o /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
Probing signature of /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
/usr/bin/codesign -r- --display /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
/Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib: code object is not signed at all
Codesigning /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
/usr/bin/codesign --force --sign 2BBB636743121E376194A84FCD31546991DBFAB9 --verbose /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
hmm.. "code object is not signed at all" ?
Can the issue be because the library is not signed?
(Note in this particular instance to help with debugging in Xcode I am building debug version.)
According to Xcode signing settings the signing is automatic for both debug and release, and it doesn't raise any flags.
hmm.. let me do this test again. I'll try release now.
1 Like
tera
26
@Douglas_Gregor, I was puzzled by that "not signed at all" message. when I run it manually in terminal that's what I am getting:
/usr/bin/codesign -r- --display /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
Executable=/Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib
designated => identifier "com.apple.dt.runtime.swiftConcurrency" and anchor apple generic and certificate leaf[subject.CN] = "Apple Development: ***reducted***" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */
no, probably red herring, as that's just the check. and it's getting signed the next line. something else.
jmuthialu
(Jay Muthialu)
27
Just curious, how is it working for @Douglas_Gregor but for myself, @tera and others are experiencing/reproduce crash?
zavsby
(Sergey)
29
I have only one Xcode installed (13.2.1) and only one command line tools installed (13.2.1 too).
Xcode was installed via XIP (not from store) btw.
jmuthialu
(Jay Muthialu)
31
Mine was installed from Appstore, if that helps.
tera
32
Anything suspicious here?
otool -L /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/CrashTest2
/Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/CrashTest2:
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1856.105.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
/System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 5205.0.101)
/usr/lib/swift/libswiftCore.dylib (compatibility version 1.0.0, current version 1300.0.46)
/usr/lib/swift/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 14.0.0, weak)
/usr/lib/swift/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 3.0.0, weak)
/usr/lib/swift/libswiftCoreImage.dylib (compatibility version 1.0.0, current version 2.0.0, weak)
/usr/lib/swift/libswiftDarwin.dylib (compatibility version 1.0.0, current version 0.0.0, weak)
/usr/lib/swift/libswiftDataDetection.dylib (compatibility version 1.0.0, current version 697.1.0, weak)
/usr/lib/swift/libswiftDispatch.dylib (compatibility version 1.0.0, current version 11.0.0)
/usr/lib/swift/libswiftFileProvider.dylib (compatibility version 1.0.0, current version 378.62.1, weak)
/usr/lib/swift/libswiftFoundation.dylib (compatibility version 1.0.0, current version 70.101.0)
/usr/lib/swift/libswiftMetal.dylib (compatibility version 1.0.0, current version 258.14.0, weak)
/usr/lib/swift/libswiftObjectiveC.dylib (compatibility version 1.0.0, current version 2.0.0, weak)
/usr/lib/swift/libswiftQuartzCore.dylib (compatibility version 1.0.0, current version 3.0.0, weak)
/usr/lib/swift/libswiftUIKit.dylib (compatibility version 1.0.0, current version 5100.0.0)
@rpath/libswift_Concurrency.dylib (compatibility version 1.0.0, current version 1300.0.46, weak)
Keith
(Keith Smiley)
33
I think this looks fine as long as /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib exists and otool -l /Users/tera/Library/Developer/Xcode/DerivedData/CrashTest2-dxpfkkbbfiopxcavapqahqofquyf/Build/Products/Release-iphoneos/CrashTest2.app/CrashTest2 | grep -A2 RPATH shows something like this:
cmd LC_RPATH
cmdsize 32
path /usr/lib/swift (offset 12)
--
cmd LC_RPATH
cmdsize 40
path @executable_path/Frameworks (offset 12)
I am a bit surprised that the library is loaded weakly, I did some hacking on LD to make this not weak, and when reproducing this crash, instead of the reports we have above, I got:
Termination Description: DYLD, dependent dylib '@rpath/libswift_Concurrency.dylib' not found for '/private/var/containers/Bundle/Application/AF6C2EFE-2B61-48EF-9EF4-53B7C29B103D/crashtest.app/crashtest'. chained fixups, seg_count does not match number of segments
Which might lead us to something.
Keith
(Keith Smiley)
35
I was able to make this crash with the debugger attached in Xcode on an iOS 13 device by unchecking all the scheme options that lead to custom libraries being injected when launching the binary with DYLD_INSERT_LIBRARIES. Here is a project with that scheme shared GitHub - keith/backdeploy-concurrency-crash: https://forums.swift.org/t/async-await-crash-on-ios14-with-xcode-13-2-1/54541/33
My assumption based on my previous comment is DYLD changes behavior somehow based on those libraries being loaded as well. I would appreciate if someone could verify that running this project on their device also causes the crash even when attached in Xcode (you'll have to update provisioning info). I am testing on an iOS 13.6 device. In the crashed state image list does not show the concurrency library as loaded, but I assume since it's linked weakly that is accepted and leads to this crash later.
1 Like
Keith
(Keith Smiley)
36
So I noticed in this case that the dylib bundled with the app contains multiple architectures:
DerivedData/CrashTest2/Build/Products/Debug-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib: Mach-O universal binary with 2 architectures: [arm64:Mach-O 64-bit dynamically linked shared library arm64] [arm64e:Mach-O 64-bit dynamically linked shared library arm64e]
DerivedData/CrashTest2/Build/Products/Debug-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib (for architecture arm64): Mach-O 64-bit dynamically linked shared library arm64
DerivedData/CrashTest2/Build/Products/Debug-iphoneos/CrashTest2.app/Frameworks/libswift_Concurrency.dylib (for architecture arm64e): Mach-O 64-bit dynamically linked shared library arm64e
If I explicitly remove the arm64e slice from this with:
lipo -remove arm64e /path/to/dylib -output foo
mv foo /path/to/dylib
And re-run without Xcode overwriting this, it works successfully on my 13.6 device. I guess I'm not sure if this would be the same behavior on 14.x given the minimum OS version of that slice specific says 14.0, but I don't have a device on that OS version to test.
2 Likes
tera
37
What are those options?
I can confirm both your findings: launching your project in Xcode crashes it into debugger and stripping the architecture fixes the bug, so the app can now be opened on iPhone. Tested on iOS 14.5. Well done!
1 Like
jmuthialu
(Jay Muthialu)
38
@Keith - I took your project and ran lipo to remove arm64e and ran the build in my device running iOS14.8 and can confirm that it did not crash by running with Xcode and also by running from homescreen (without Xcode). Awesome!!
Keith
(Keith Smiley)
39
By default at least the main thread checker, and the the other options in the Options tab of the scheme editor. I didn't do them one by one to see which translate to injecting some libraries, but it did seem to require they all be disabled.
Please note that I'm not recommending any of these solutions, I'm just hoping this debugging is helpful for the folks who know more about all the moving pieces here.
2 Likes
Keith
(Keith Smiley)
40
Thank you both for testing it!
2 Likes