Skip to content

[Backtracing] Add initial support for Windows.#84906

Merged
al45tair merged 29 commits intoswiftlang:mainfrom
al45tair:eng/PR-101623384
Feb 6, 2026
Merged

[Backtracing] Add initial support for Windows.#84906
al45tair merged 29 commits intoswiftlang:mainfrom
al45tair:eng/PR-101623384

Conversation

@al45tair
Copy link
Copy Markdown
Contributor

@al45tair al45tair commented Oct 15, 2025

This PR includes support for capturing backtraces and symbolicating using DWARF debug information. It doesn't include support for PDB (yet).

rdar://101623384

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please smoke test

@al45tair al45tair force-pushed the eng/PR-101623384 branch 2 times, most recently from 4ea287c to d954e8a Compare October 15, 2025 12:25
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please smoke test

@al45tair
Copy link
Copy Markdown
Contributor Author

Status: this isn't working for 32-bit Windows, because of a problem with the Swift compiler itself.

Also, I need to work on the build system a bit because right now you need to manually copy the backtracer into the correct place. Not sure why, because I'm fairly certain there's CMake code already that's supposed to do that.

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair al45tair force-pushed the eng/PR-101623384 branch 2 times, most recently from d4a345a to 499c6ea Compare January 13, 2026 12:24
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair al45tair force-pushed the eng/PR-101623384 branch 2 times, most recently from 6512a83 to bb20822 Compare January 14, 2026 11:17
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test macOS platform

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

2 similar comments
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test Linux platform

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test macOS platform

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

1 similar comment
@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

@swift-ci Please test Linux platform

@al45tair al45tair marked this pull request as ready for review January 20, 2026 12:07
@al45tair al45tair requested a review from compnerd as a code owner January 20, 2026 12:07
@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 4, 2026

@swift-ci Please test

@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 4, 2026

I've just checked that this works on ARM64 Windows, since we don't have PR testing coverage there. My small crash test program generated a backtrace :-)

One thing I did spot is that if you install x86-64 Swift on ARM64 Windows, programs seem to crash on exit somewhere in mimalloc. We might need to look into that, but that's nothing to do with this PR.

Copy link
Copy Markdown
Contributor

@edymtt edymtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me on the build system side (especially the new one) -- not sure if it makes sense to break the rename of SwiftRuntime to SwiftRuntimeCore in the Core build system in a separate PR.

find_package(SwiftOverlay REQUIRED)
find_package(SwiftCxxOverlay REQUIRED)

if(APPLE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Darwin find module should be already skipping the search if we are not building for Darwin, so this if should not be strictly necessary -- did you hit issues when building at desk?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did, yes, We might want to investigate that, if we're not supposed to need the APPLE condition.

target_compile_definitions(swiftRuntimeCore
PRIVATE
-DSWIFT_RUNTIME
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntimeCore
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this is now redundant -- in case, we can remove it at a later time to reduce risks in landing this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered that also, but didn't feel brave enough to delete it :-)

@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 4, 2026

@swift-ci Please test Linux platform

@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 5, 2026

@swift-ci Please test macOS platform

@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 5, 2026

In addition to manually testing crash catching on ARM64 Windows, I've also tested that the Runtime API is able to capture a backtrace with Backtrace.capture(). That is also working.

@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 5, 2026

@swift-ci Please test macOS platform

@al45tair al45tair force-pushed the eng/PR-101623384 branch 2 times, most recently from 6a8a47c to 2ebe6ed Compare February 6, 2026 08:49
Don't even bother building the backtracing code if the backtracing
code is disabled.

rdar://101623384
We were omitting the `end` instruction, the upshot of which was
that the compact backtrace was always being decoded as truncated.

rdar://101623384
Also, fix two files that managed to use Windows API without
importing `WinSDK` as a result of the leakage caused by including
`windows.h` from `codeview.h`.

rdar://101623384
We should only add the assembly files if we're actually going
to build the `Runtime` module.  This was tripping up iOS/tvOS/
watchOS builds.

rdar://101623384
Tweak things to build on Linux and macOS again.

Also fix a few things in the tests.

rdar://101623384
We can't use `|| true` on Windows, so use `not` instead.

Also, on Windows, program names get downcased because `lit` uses
`os.path.normcase()`, so if we have program names in the output,
make sure the programs are already lower-case.

Fix up the stack overflow test to match the expected output.

Plus fix the macOS build to always build for macOS 26.0 or above.

rdar://101623384
`not` works on Windows, but not on Linux or Darwin.

rdar://101623384
Test for `}` rather than `},`, since we may or may not have extra
frames after the ones we expect, depending.

rdar://101623384
Tweaked the comment in `Runtime/Config.h`.

Fixed a couple of incorrect ARM64 instruction mnemonics.  This still needs
testing on ARM64 Windows.

Fixed an out-of-date comment in `swift-backtrace`.

Use a macro in `Backtrace.cpp` to guarantee we don't overrun the buffer,
and in the process simplify the code slightly.

rdar://101623384
This change in the driver isn't necessary after all.

rdar://101623384
I really did mean `ret`.

rdar://101623384
We needed to add the `Runtime` module to the new build system, but
when I tried doing that, various things broke.

Firstly, we ended up with two targets with the name `swiftRuntime`,
but only in the static build (because in that build, everything
gets pulled in together, so CMake sees both of them).  Rename the
one that's part of `swiftCore` to `swiftRuntimeCore`.

Second, we need some extra paths for the `Cxx` module and its
submodules, and since those are part of the `INTERFACE`, we need
to make sure we `PUBLIC` link them into the `Cxx` module so that
they get passed through when building `swiftRuntime`.

rdar://101623384
@al45tair
Copy link
Copy Markdown
Contributor Author

al45tair commented Feb 6, 2026

@swift-ci Please smoke test

@al45tair al45tair merged commit e38c065 into swiftlang:main Feb 6, 2026
3 checks passed
finagolfin added a commit that referenced this pull request Feb 17, 2026
…in CI again (#87275)

This was fixed in #86694, but the subsequent massive #84906 appears to
have [inadvertently disabled adding the needed Android API
level](https://github.com/swiftlang/swift/pull/84906/changes#diff-c861caa2fcc08744108e542ca836b07e342f537566e8c5f7a21a0e9125331ed9R2774),
as it was started late last year, long before the fix was added.
blevine1 pushed a commit to blevine1/swift that referenced this pull request Feb 24, 2026
…in CI again (swiftlang#87275)

This was fixed in swiftlang#86694, but the subsequent massive swiftlang#84906 appears to
have [inadvertently disabled adding the needed Android API
level](https://github.com/swiftlang/swift/pull/84906/changes#diff-c861caa2fcc08744108e542ca836b07e342f537566e8c5f7a21a0e9125331ed9R2774),
as it was started late last year, long before the fix was added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants