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?