Swift Runtime Error running on Android SDK 30 arm64-v8a

When running swift code that does any string manipulation on Android SDK 30 with an arm64-v8a device you get a runtime error:

Fatal error: No foreign strings on Linux in this version of Swift: file Swift/StringGraphemeBreaking.swift, line 239

I think it has something to do with the addition of Tagged Pointers in Android SDK 30 because if I disable that feature I do not get the runtime errors anymore. However there is a warning in the Android documentation about the possibility that future hardware may not be able to disable the feature.

This escape hatch will disappear in future versions of Android, because issues of this nature will be incompatible with MTE.

Does anyone here know if there is a workaround for this issue besides downgrading to Android SDK 29 or disabling tagged pointers?

Here is the backtrace

2021-03-08 15:57:48.892 13215-13215/com.test.pathoperationstest A/SwiftRuntime: Fatal error: No foreign strings on Linux in this version of Swift: file Swift/StringGraphemeBreaking.swift, line 239
2021-03-08 15:57:48.899 13215-13215/com.test.pathoperationstest A/libc: Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x6e4afefb9c in tid 13215 (hoperationstest), pid 13215 (hoperationstest)
2021-03-08 15:57:48.940 22036-22036/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-03-08 15:57:48.940 22036-22036/? A/DEBUG: Build fingerprint: 'samsung/c1quew/c1q:11/RP1A.200720.012/N981U1UES1CUA1:user/release-keys'
2021-03-08 15:57:48.940 22036-22036/? A/DEBUG: Revision: '10'
2021-03-08 15:57:48.940 22036-22036/? A/DEBUG: ABI: 'arm64'
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG: Timestamp: 2021-03-08 15:57:48-0700
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG: pid: 13215, tid: 13215, name: hoperationstest  >>> com.test.pathoperationstest <<<
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG: uid: 10006
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG: signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x6e4afefb9c
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG: Abort message: 'Fatal error: No foreign strings on Linux in this version of Swift: file Swift/StringGraphemeBreaking.swift, line 239
    '
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x0  8000006e4b2dbdd0  x1  0000006e4b25a068  x2  0000007ff92a4f48  x3  0000000000000042
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x4  0000000000000010  x5  b400006ece067011  x6  6965726f66206f4e  x7  6e69727473206e67
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x8  0000006e4b25a068  x9  a96d5a641f30b0d1  x10 0000000000000000  x11 e83f000000042107
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x12 0000000000000000  x13 e83f000000042107  x14 0000000000000107  x15 0000ffff00000fff
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x16 0000006e4b382a58  x17 00000070f2a4ab58  x18 00000070f4a3e000  x19 0000006e4b2e06b0
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x20 0000000000000001  x21 0000000000000000  x22 00000000000000ef  x23 0000006e4b2e02f0
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x24 8000006e4b2dbdd0  x25 d000000000000034  x26 000000000000000b  x27 0000000000000002
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     x28 0000006f1e0363b0  x29 0000007ff92a50c0
2021-03-08 15:57:48.942 22036-22036/? A/DEBUG:     lr  0000006e4afefb9c  sp  0000007ff92a5080  pc  0000006e4afefb9c  pst 00000000a0001000
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG: backtrace:
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #00 pc 000000000016eb9c  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!libswiftCore.so (offset 0x98d000) ($ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF+464) (BuildId: 2a65ba22827e6350dae6057a7f155fef1fa06c63)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #01 pc 000000000037fa78  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!libswiftCore.so (offset 0x98d000) (BuildId: 2a65ba22827e6350dae6057a7f155fef1fa06c63)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #02 pc 000000000029ef70  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!libswiftCore.so (offset 0x98d000) ($ss11_StringGutsV22_opaqueCharacterStride10startingAtS2i_tF+120) (BuildId: 2a65ba22827e6350dae6057a7f155fef1fa06c63)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #03 pc 0000000000198d08  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #04 pc 0000000000199aa8  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #05 pc 000000000019cfcc  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000)
2021-03-08 15:57:49.110 22036-22036/? A/DEBUG:       #06 pc 000000000018d360  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #07 pc 00000000001778c4  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000) ($s14ArgumentParser15ParsableCommandPAAE11parseAsRootyAaB_pSaySSGSgKFZ+140)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #08 pc 0000000000177c84  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000) ($s14ArgumentParser15ParsableCommandPAAE4mainyySaySSGSgFZ+48)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #09 pc 00000000001cc0a0  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000) ($s14CriGeoCommands0C0V7executeySSSaySSGSgFZ+180)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #10 pc 00000000001c5dec  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk (offset 0x1b76000) ($s7CriGeoC33executeCommandWithAllocatedResultySpys4Int8VGs5Int32V_SPySPyADGGtF+240)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #11 pc 0000000000000a80  /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!libcrigeo-jni.so (offset 0x4534000) (Java_com_test_testlibrary_TestLib_00024Companion_executeCommandNative+552) (BuildId: b544204172b3b33857d85a7555eedb3f39a3671f)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #12 pc 000000000013ced4  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #13 pc 0000000000133564  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #14 pc 0000000000197e94  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+204) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #15 pc 0000000000309b84  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #16 pc 0000000000304c9c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+884) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #17 pc 0000000000639a2c  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+592) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #18 pc 000000000012d914  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #19 pc 0000000000000358  [anon:dalvik-classes9.dex extracted in memory from /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!classes9.dex] (com.test.testlibrary.TestLib$Companion.executeCommand+16)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #20 pc 0000000000637740  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1440) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #21 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #22 pc 0000000000000fec  [anon:dalvik-classes4.dex extracted in memory from /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!classes4.dex] (com.test.FirstFragment.pathUnion+204)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #23 pc 0000000000639c68  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+1164) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #24 pc 000000000012d914  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #25 pc 0000000000000f04  [anon:dalvik-classes4.dex extracted in memory from /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!classes4.dex] (com.test.FirstFragment.access$pathUnion)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #26 pc 000000000063a4c8  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1120) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #27 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #28 pc 0000000000000e7c  [anon:dalvik-classes4.dex extracted in memory from /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!classes4.dex] (com.test.FirstFragment$onViewCreated$1.onClick+256)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #29 pc 00000000006390d4  /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1840) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #30 pc 000000000012da14  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #31 pc 0000000000366532  /system/framework/framework.jar (offset 0x12ba000) (android.view.View.performClick+74)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #32 pc 0000000000638464  /apex/com.android.art/lib64/libart.so (MterpInvokeSuper+2340) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #33 pc 000000000012d894  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_super+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #34 pc 000000000048dc98  /system/framework/framework.jar (offset 0x12ba000) (android.widget.TextView.performClick)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #35 pc 0000000000638464  /apex/com.android.art/lib64/libart.so (MterpInvokeSuper+2340) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #36 pc 000000000012d894  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_super+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #37 pc 00000000002e86c2  [anon:dalvik-classes7.dex extracted in memory from /data/app/~~_KQDHQ2kaOM3NCHBt1lIHg==/com.test.pathoperationstest-cgpoSko-PwaVQcDLwzrqdw==/base.apk!classes7.dex] (com.google.android.material.button.MaterialButton.performClick+6)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #38 pc 0000000000637740  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1440) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #39 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #40 pc 0000000000366566  /system/framework/framework.jar (offset 0x12ba000) (android.view.View.performClickInternal+6)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #41 pc 0000000000639c68  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+1164) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #42 pc 000000000012d914  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #43 pc 0000000000361580  /system/framework/framework.jar (offset 0x12ba000) (android.view.View.access$3700)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #44 pc 000000000063a4c8  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1120) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #45 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #46 pc 000000000033b754  /system/framework/framework.jar (offset 0x12ba000) (android.view.View$PerformClick.run+16)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #47 pc 00000000006390d4  /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1840) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #48 pc 000000000012da14  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #49 pc 0000000000404574  /system/framework/framework.jar (offset 0x966000) (android.os.Handler.handleCallback+4)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #50 pc 000000000063a4c8  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1120) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #51 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.111 22036-22036/? A/DEBUG:       #52 pc 00000000004043e8  /system/framework/framework.jar (offset 0x966000) (android.os.Handler.dispatchMessage+8)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #53 pc 0000000000637740  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1440) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #54 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #55 pc 0000000000443094  /system/framework/framework.jar (offset 0x966000) (android.os.Looper.loop+480)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #56 pc 00000000002fc678  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.14489065991730532002)+268) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #57 pc 0000000000304340  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #58 pc 0000000000305620  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, true>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1780) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #59 pc 000000000016e3e4  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<true, false>(art::interpreter::SwitchImplContext*)+54148) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #60 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #61 pc 00000000001af620  /system/framework/framework.jar (android.app.ActivityThread.main)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #62 pc 00000000002fc780  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.14489065991730532002)+532) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #63 pc 0000000000625eb4  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+796) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #64 pc 000000000013cff8  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #65 pc 00000000001337e8  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #66 pc 0000000000197eb0  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #67 pc 000000000052e5cc  /apex/com.android.art/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #68 pc 00000000005302c0  /apex/com.android.art/lib64/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+1352) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #69 pc 00000000004b18cc  /apex/com.android.art/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+52) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #70 pc 000000000008a614  /apex/com.android.art/javalib/arm64/boot.oat (art_jni_trampoline+180) (BuildId: 94bcbe9ac8113f19adef5079c0ea888accec9fa6)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #71 pc 0000000000133564  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #72 pc 0000000000197e94  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+204) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #73 pc 0000000000309b84  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #74 pc 0000000000304c9c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+884) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #75 pc 0000000000637504  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+868) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #76 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #77 pc 00000000002322e6  /system/framework/framework.jar (offset 0x1c4c000) (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #78 pc 00000000002fc678  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.14489065991730532002)+268) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #79 pc 0000000000625eb4  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+796) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #80 pc 000000000013cff8  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #81 pc 0000000000afb26c  /system/framework/arm64/boot-framework.oat (com.android.internal.os.ZygoteInit.main+2444) (BuildId: f1045e3032a268897f044d72a7c7afd6ecce4cb9)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #82 pc 00000000001337e8  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #83 pc 0000000000197eb0  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #84 pc 000000000052e5cc  /apex/com.android.art/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #85 pc 000000000052e1c4  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeWithVarArgs<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, std::__va_list)+428) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #86 pc 000000000052f12c  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeWithVarArgs<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list)+92) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #87 pc 00000000004218f4  /apex/com.android.art/lib64/libart.so (art::JNI<true>::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)+656) (BuildId: 682386d31bd69cc9f3186d15033c4278)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #88 pc 000000000009c434  /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+124) (BuildId: 64d701910a0cb6613dbe7ddca70506bf)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #89 pc 00000000000a4574  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+848) (BuildId: 64d701910a0cb6613dbe7ddca70506bf)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #90 pc 000000000000358c  /system/bin/app_process64 (main+1348) (BuildId: cb4a9b8a8482f0772689ddc73871203d)
2021-03-08 15:57:49.112 22036-22036/? A/DEBUG:       #91 pc 000000000004a188  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) (BuildId: 11d13080412d11d9c0f9274b3d01391e)

Thanks for reporting, the same issue cropped up when trying to run SPM on Android 11, looks like you found the root cause. I have a vague recollection of Swift using tagged pointers internally, maybe that collides with Android 11 trying to do the same. I have ordered an Android 11 device and will look into this soon.

2 Likes

I finally spent a couple hours looking into this and can confirm tagged pointers are the issue. I built a debug Swift stdlib and SPM and ran swift-build --version under lldb in the Termux app, both on an Android 11 device that has this problem and one that doesn't (I guess memory tagging isn't rolled out fully on Android 11 yet).

On the tagged pointer device, it fails when interpolating the help strings, when it checks the utf8Count of a string it's appending and looks up if the string isFastUTF8, which is determined by whether the 60th bit is set or not as explained in the docs.

When comparing the same failing code on both devices, the top byte is consistently set on the memory-tagged device and zero'd on the working Android 11 device. As the 60th bit is set, the Swift stdlib goes off the rails and ends up saying it doesn't handle foreign strings. I'm not quite sure why this other help string interpolation is done at all, seems an efficiency issue in swift-argument parser or Swift itself, when all I'm asking for is the SPM version.

Since the Swift stdlib and linux are both trying to use tagged pointers, I'm not sure what the solution could be: move the Swift tag to the second byte?

I wonder would the difficulty with changing the location of the Swift tag to the second byte be maintaining backwards compatibility? Is there documentation anywhere on how Swift stdlib uses the tag that you know of?

would the difficulty with changing the location of the Swift tag to the second byte be maintaining backwards compatibility?

We could just move the tag on linux platforms, where there is no stable ABI for Swift anyway.

Is there documentation anywhere on how Swift stdlib uses the tag that you know of?

I linked to it above: see my last link from my last comment, straight from the source. There is further doc on string layout later in that file.

Obviously there will be one less byte available for small strings if we move the tag byte, unsure how pervasively that will affect the stdlib code.

I've put together a pull that fixes this issue on Android AArch64 by moving Swift's string tag to the second byte, along with other needed moves I found, more detailed technical writeup there. I've tested it on two devices with this problem and one without, with everything working well now. Took me a week of rooting around failing tests with lldb to track these various Swift collisions with Android's memory tagging down.

If @Geordie_J and others running Swift on Android would try it out, more testing would be good. @v.gorlov, try it with your Android cross-compilation toolchain and let us know.

I've pushed the fix into my native Swift toolchain package that runs on Android, which works on these tagged devices for the first time, but recompiling my 5.5 cross-compilation Android SDKs won't be enough, as the Swift compiler itself has to be patched. I'll try to get the fix into the 5.6 branch before the upcoming release, so that this should be fixed by then.

1 Like

Thanks so much for your efforts here @Finagolfin. To test this, would we need to compile the code from an Android device?

No, simply apply this tagging pull to whatever current toolchain you're using to cross-compile to Android, whether from macOS, linux, or Windows, and rebuild your toolchain. You will have to rebuild the Swift compiler too, as it generates some code that currently assumes there is no memory tagging.

Then, rebuild and run whatever test suite or app that is currently failing on memory-tagged Android AArch64 devices with this patched toolchain, and see if it fixes the issues.