Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtracing module does not build for Linux armv7 #79477

Open
xtremekforever opened this issue Feb 19, 2025 · 3 comments
Open

Backtracing module does not build for Linux armv7 #79477

xtremekforever opened this issue Feb 19, 2025 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@xtremekforever
Copy link
Contributor

Description

When I try to compile Swift for linux-armv7 with -DSWIFT_ENABLE_BACKTRACING=ON, it fails to build:

/src/swift-armv7/downloads/swift/stdlib/public/runtime/CrashHandlerLinux.cpp:256:34: error: no member named 'gprs' in 'mcontext_t'
  256 |   pc = (void *)(ctx->uc_mcontext.gprs[15]);
      |                 ~~~~~~~~~~~~~~~~ ^
1 error generated.

If I apply the fix that is used for Android for __linux__ as well, it compiles fine. However, the backtracing module was moved into the runtime module, so if I enable -DSWIFT_ENABLE_RUNTIME_MODULE=ON, I get more errors:

/src/swift-armv7/downloads/swift/stdlib/public/RuntimeModule/Context.swift:886:15: error: cannot find 'to' in scope
 884 |           $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
 885 |             for n in 0..<16 {
 886 |               to[n] = from[n]
     |               `- error: cannot find 'to' in scope
 887 |             }
 888 |           }

/src/swift-armv7/downloads/swift/stdlib/public/RuntimeModule/Context.swift:886:23: error: cannot find 'from' in scope
 884 |           $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
 885 |             for n in 0..<16 {
 886 |               to[n] = from[n]
     |                       `- error: cannot find 'from' in scope
 887 |             }
 888 |           }

/src/swift-armv7/downloads/swift/stdlib/public/RuntimeModule/Context.swift:882:59: error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
 880 |   init(with mctx: mcontext_t) {
 881 |     withUnsafeMutablePointer(to: &gprs._r) {
 882 |       $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
     |                                                           `- error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
 883 |         withUnsafePointer(to: &mctx.arm_r0) {
 884 |           $0.withMemoryRebound(to: UInt32.self, capacity: 16) {

/src/swift-armv7/downloads/swift/stdlib/public/RuntimeModule/Context.swift:883:31: error: cannot pass immutable value as inout argument: 'mctx' is a 'let' constant
 881 |     withUnsafeMutablePointer(to: &gprs._r) {
 882 |       $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
 883 |         withUnsafePointer(to: &mctx.arm_r0) {
     |                               `- error: cannot pass immutable value as inout argument: 'mctx' is a 'let' constant
 884 |           $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
 885 |             for n in 0..<16 {

/src/swift-armv7/downloads/swift/stdlib/public/RuntimeModule/Context.swift:884:63: error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
 882 |       $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
 883 |         withUnsafePointer(to: &mctx.arm_r0) {
 884 |           $0.withMemoryRebound(to: UInt32.self, capacity: 16) {
     |                                                               `- error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
 885 |             for n in 0..<16 {
 886 |               to[n] = from[n]

I would like to have an opportunity to fix this up and hopefully find a solution for linux-armv7 that does not affect Darwin armv7 targets, like the Apple Watch (I think).

@al45tair

Reproduction

This is the output given by the swiftlang/swift cmake invocation:

-- Threading package override enabled
--   Global: c11
-- 
-- Linux SDK:
--   Object File Format: ELF
--   Swift Standard Library Path: linux
--   Threading Package: c11
--   Static linking supported: TRUE
--   Static link only: FALSE
--   Architectures: armv7
--   armv7 triple: armv7-unknown-linux-gnueabihf
--   Module triple: armv7-unknown-linux-gnueabihf
--   armv7 Path: /src/swift-armv7/sysroot-debian-bookworm
-- 
-- Not building host Swift tools
-- 
-- Building Swift standard library and overlays for SDKs: LINUX
--   Build type:       Release
--   Assertions:       OFF
-- 
-- Building Swift runtime with:
--   Leak Detection Checker Entrypoints: OFF
-- 
-- Differentiable Programming Support: ON
-- Concurrency Support:                ON
-- Distributed Support:                ON
-- String Processing Support:          ON
-- Backtracing Support:                ON
-- Unicode Support:                    ON
-- Observation Support:                ON
-- Synchronization Support:            ON
-- Volatile Support:                   OFF
-- Pointer Bounds Support:             
-- Runtime Support:                    ON
-- 

Expected behavior

The backtracing module should compile for linux-armv7.

Environment

Swift version 6.2-dev (LLVM a1d5a03ff545308, Swift d0e4f84)
Target: aarch64-unknown-linux-gnu
Build config: +assertions

Additional information

Almost everything else compiles just fine for linux-armv7 with virtually no patching required. All that is missing is the backtracing functionality that does not compile, but may be relatively simple to patch.

@xtremekforever xtremekforever added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 19, 2025
@al45tair
Copy link
Contributor

al45tair commented Feb 24, 2025

that does not affect Darwin armv7 targets, like the Apple Watch (I think).

The Runtime module is presently disabled for iOS, watchOS et al, as was the _Backtracing module before it. I'd like to enable it, but I might not have time this year — part of doing that entails checking that e.g. armv7 and arm64-32 are supported properly.

Put another way, if the armv7 support isn't working right now, that's not a great surprise, since we aren't actually using that code. It should mostly be there, but it doesn't surprise me that there are some issues as nobody has used it up to now.

@xtremekforever
Copy link
Contributor Author

that does not affect Darwin armv7 targets, like the Apple Watch (I think).

The Runtime module is presently disabled for iOS, watchOS et al, as was the _Backtracing module before it. I'd like to enable it, but I might not have time this year — part of doing that entails checking that e.g. armv7 and arm64-32 are supported properly.

Put another way, if the armv7 support isn't working right now, that's not a great surprise, since we aren't actually using that code. It should mostly be there, but it doesn't surprise me that there are some issues as nobody has used it up to now.

Okay, that makes sense then why it doesn't compile for armv7. Since it's even disabled for iOS and watchOS platforms I guess it's not a big deal then.

However, I'd like to have a shot at getting backtracing to at least compile for Linux-armv7, and ultimately being able to have some backtracing support on armv7 with swift-backtrace. If I do this, @al45tair would you be able to review the code to make sure it doesn't break anything and is acceptable?

@al45tair
Copy link
Contributor

If I do this, @al45tair would you be able to review the code to make sure it doesn't break anything and is acceptable?

Yes, I'd be happy to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants