Steps to resolve "unable to protect … swift-backtrace … disabling backtracing"?

What would be the steps needed to resolve "unable to protect … swift-backtrace … disabling backtracing"?

Setup: Swift Community Apt Repository installation of Swift on a Raspberry Pi 5 with Raspberry Pi OS.

Steps: The command swift --version is sufficient to invoke the "unable to protect" messages:

swift --version
#swift runtime: unable to protect path to swift-backtrace at 0x7fff2ffa7000: 22; disabling backtracing.
#swift runtime: unable to protect environment for swift-backtrace at 0x7fff2ff9f000: 22; disabling backtracing.
#swift runtime: unable to protect path to swift-backtrace at 0x7fff8a907000: 22; disabling backtracing.
#swift runtime: unable to protect environment for swift-backtrace at 0x7fff8a8ff000: 22; disabling backtracing.
#swift runtime: unable to protect path to swift-backtrace at 0x7fffafe97000: 22; disabling backtracing.
#swift runtime: unable to protect environment for swift-backtrace at 0x7fffafe8f000: 22; disabling backtracing.
#Swift version 5.10 (swift-5.10-RELEASE)
#Target: aarch64-unknown-linux-gnu

Alternately, any pointers on where to reach the right expertise would be appreciated. Links are provided below for other places that I've reached out to:

:-) I'm probably the person to talk to about this. It's happening because the code in the runtime tries to work out at compile time what the page size will be, so that it can declare some static buffers that are page aligned (which they need to be so that mprotect() will work on them).

Unfortunately Raspberry Pi OS sets its page size (well, granule size) to 16KB, not the usual 4KB, hence the mprotect() calls fail, and without them it isn't safe to use the runtime's backtracer — enabling it would create a security hole — so we emit a message and turn it off.

Equally unfortunately, this isn't exactly trivial to fix. We could make it work for Raspberry Pi OS perhaps by simply pretending that the page size is 16KB for all ARM64 Linux platforms (that won't hurt too much), but it'll still be broken if someone has their system set for 64KB pages. The right fix here might be a custom linker script for the libswiftCore.so, not sure.

If you're doing a custom build of Swift just for Raspberry Pi OS, of course, you could just update SWIFT_PAGE_SIZE in swift/include/swift/Runtime/Config.h.

1 Like