72 Commits

Author SHA1 Message Date
Saleem Abdulrasool
cbe4715b9a Merge pull request #87430 from hjyamauchi/armasm
Fix an ARMASM build error
2026-02-23 17:54:31 -08:00
Hiroshi Yamauchi
2354c7ceb7 Fix an ARMASM build error
PUBLIC is a MASM directive and causes a build error in a certain version of MSVC

```
Microsoft (R) ARM Macro Assembler Version 14.44.35217.0 for 64 bits
Copyright (C) Microsoft Corporation.  All rights reserved.

D:\r\_work\swift-build\swift-build\SourceCache\swift\stdlib\public\RuntimeModule\get-cpu-context-aarch64.asm(21) : error A2003: improper line syntax: PUBLIC
```
EXPORT is an ARMASM equivalent, which is already there.
2026-02-23 13:00:39 -08:00
Allan Shortlidge
d4547ec74c stdlib: Fix compiler warnings in Concurrency, Cxx, and RuntimeModule
- Remove spurious `unsafe` on non-unsafe calls in TaskCancellation.swift
  and UnsafeCxxIterators.swift
- Change `var fd` to `let fd` in ImageSource.swift since it is never mutated
2026-02-23 09:35:18 -08:00
Alastair Houghton
0c32b10ee6 [Backtracing] baseAddress is Optional, so we need a ! here.
I don't understand how this passed PR testing (or built) previously,
but it did both, then started failing.

rdar://170887396
2026-02-23 10:24:45 +00:00
Carl Peto
70dfbf87b5 [Runtime] Move source code doc comments to DocC (#87311)
rdar://126273038

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-02-20 12:15:42 -08:00
Alastair Houghton
245b5e0766 [Backtracing] Add the ability for a SymbolLocator to find images.
This is better than the `alternativePaths` mechanism because it means that
a client of the `Runtime` module can do its own thing, which might even
mean fetching things from a remote server or decompressing files or any
other thing we might find useful.

rdar://170642627
2026-02-18 16:59:52 +00:00
Alastair Houghton
19b823c9db [Backtracing][PDB] Fix 32-bit Intel build. (#87304) 2026-02-18 07:14:00 -08:00
Alastair Houghton
042861d752 [Backtracing][PDB] Fix a couple of tests.
We can't test the alternate image support for ELF, because that's been
removed in favour of `SymbolLocator`/`SymbolSource`.

Also we must pass `/opt:icf` in the symbolicated backtrace test when
using PDB, otherwise we corrupt the metadata.

Finally fix a mistake in `Utils.swift` where we were crashing if the
environment variable in question wasn't set.

rdar://168454023
2026-02-17 18:51:17 +00:00
Alastair Houghton
e7f603fd25 [Backtracing][PDB] For ELF, always return the image file.
ELF images typically do contain symbols, unlike PE-COFF images.

rdar://168454023
2026-02-17 12:24:51 +00:00
Alastair Houghton
2d6d395f75 [Backtracing] Fix Linux build.
The fix for the previous Linux build problem introduced a new one.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton
af322cf942 [Backtracing][PDB] Remove ELF-specific lookupSymbol().
We don't need the ELF-specific function any more, so get rid of it.

Also fix a typo.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton
d380cde01a [Backtracing][PDB] Remove debugging things.
I'd told the RuntimeModule to build with debug information while
working on debugging it.  We don't want that in the build.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton
b89b5e13bd [Backtracing][PDB] Fix-ups after rebasing.
A few tweaks required after rebasing on top of Carl's work on
cross-platform symbolication.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton
487e173a26 [Backtracing][PDB] Scan the main symbol stream as well.
Without scanning the main symbol stream, we get weird names for the
Swift functions in the backtrace, because the compiler generates C++-style
names for them.  We actually want the mangled names, if possible, which
only seem to be in the symbol stream, so scan that as well and use it
to find mangled names.

rdar://168454023
2026-02-17 10:50:56 +00:00
Alastair Houghton
acdaeef626 [Backtracing][PDB] Add PDB code and SymbolLocator.
Added the PDB reading code and also a `SymbolLocator` type that
allows us to locate symbols for a given image.

rdar://168454023
2026-02-17 10:50:55 +00:00
Carl Peto
42ea2a5f7f [Backtracing] Allow symbolication across platforms (#86750)
Instead of the symbolication method being decided by what platform the symbolication code is running on, use a parameter passed to the symbolication function, defaulted to the current platform for backward compatibility.

Useful for the upcoming offline symbolicator.

rdar://168769519

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

---------

Co-authored-by: Carl Peto <carlpeto@Carls-MacBook-Pro.local>
2026-02-13 13:38:50 +00:00
Jesse Zamora
e73c16a330 Support reading DWARFv2 format in DwarfReader
- It is essentially the same as DWARFv3 minus a few missing fields.
2026-02-06 18:13:40 -05:00
Alastair Houghton
3e7647de2c [Backtracing] Fix silly mistake.
I really did mean `ret`.

rdar://101623384
2026-02-06 08:53:16 +00:00
Alastair Houghton
ceaba82d6d [Backtracing] Updates after review.
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
2026-02-06 08:53:16 +00:00
Alastair Houghton
ae71bd8d65 [Backtracing] Fix tests up for Windows.
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
2026-02-06 08:53:16 +00:00
Alastair Houghton
d9b0031f09 [Backtracing] Build and test fixes.
Tweak things to build on Linux and macOS again.

Also fix a few things in the tests.

rdar://101623384
2026-02-06 08:53:15 +00:00
Alastair Houghton
58a6470ac3 [Backtracing] Fix build failures for places Runtime doesn't build.
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
2026-02-06 08:53:15 +00:00
Alastair Houghton
f6af22c402 [Backtracing] Don't pull in windows.h unnecessarily.
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
2026-02-06 08:53:15 +00:00
Alastair Houghton
38c4848b12 [Backtracing] Remember to emit end instruction.
We were omitting the `end` instruction, the upshot of which was
that the compact backtrace was always being decoded as truncated.

rdar://101623384
2026-02-06 08:53:15 +00:00
Alastair Houghton
add83b4d22 [Backtracing] Don't build backtracing code when it's disabled.
Don't even bother building the backtracing code if the backtracing
code is disabled.

rdar://101623384
2026-02-06 08:53:12 +00:00
Alastair Houghton
54f9cee919 [Backtracing] Fix typos, tidy up.
Fix a couple of typos and remove some `print()` statements that
were added for debugging.

rdar://101623384
2026-02-03 18:23:30 +00:00
Alastair Houghton
a677131c96 [Backtracing] Tweak a few things after rebasing.
Fix a couple of issues with the rebase.

Also, add code to handle the debug exceptions (which we don't want
to crash the process).

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
6d930d39ec [Backtracing] Make tests work, plus various fixes.
Made the tests run, then fixed various issues with them.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
e0845e1483 [Backtracing] Made on-crash backtraces work for 64-bit.
On-crash backtracing is basically there for 64-bit Windows.  It
won't work on 32-bit because of a Swift compiler issue, and there
is a little more work to do yet, but it is now working!

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
38f91e2dbd [Backtracing] Fix Linux and macOS builds.
There was a case-sensitivity problem, and a missing source file.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
bf9dd3ac55 [Backtracing] Make line numbers work.
Also fix things so that we use the right path separator, depending
on image type, and add support for `DW_AT_specification` attributes
on `DW_TAG_subprogram` entries.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
3cdac64200 [Backtracer] Fix some bugs that prevented DWARF reading.
This is now fetching symbols successfully, though not line numbers
yet.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
7f57385be4 [Backtracing][Windows] Add PE file parsing and DWARF-in-PE support.
This should allow us to get symbolicated backtraces for Swift code
that is built with DWARF debug information.

rdar://181623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
d13988bd5f [Backtracing][Windows] Initial Windows support.
This doesn't have a working symbolicator yet, but it does build and
it can obtain a basic backtrace.

It also doesn't include a working `swift-backtrace` program yet.

rdar://101623384
2026-02-03 18:23:29 +00:00
Alastair Houghton
07eaaf2ed7 [Backtracing] For DWARF 3, skip maximum_operations_per_instruction
DWARF 3 doesn't have the `maximum_operations_per_instruction` field
in the line number header.  As a result, we were mis-reading the
subsequent fields in the DWARF line table header.

rdar://168996222
2026-01-27 14:37:04 +00:00
Alastair Houghton
9b74e82d16 Merge pull request #86535 from AZero13/zlib
Total output needs to have the last outbuffer pos added to it
2026-01-16 13:25:57 +00:00
Konrad `ktoso` Malawski
40dabefdb4 Reapply: Runtime: expose demangle() in Runtime module (#84788) (#86510) 2026-01-14 21:44:28 +09:00
AZero13
38d0284c00 Total output needs to have the last outbuffer pos added to it 2026-01-13 13:09:36 -05:00
Alastair Houghton
e0486a47bd [Backtracing] Add some more availability annotations.
We needed a few more annotations, it turns out.  Also, we need to disable
availability checking when building swift-backtrace.

rdar://164850733
2026-01-09 15:48:37 +00:00
Alastair Houghton
6a6ff87602 [Backtracing] Move availability definition, fix tests.
Move the availability definition to the `.def` file, and then
turn off availability checking in the tests.

rdar://164850733
2026-01-09 11:58:36 +00:00
Alastair Houghton
22a7c8fa0a [Backtracing] More availability annotations required.
Apparently we need some more availability annotations.

rdar://164850733
2026-01-09 11:58:36 +00:00
Alastair Houghton
64fa447210 [Backtracing] Add missing availability annotations.
This is slightly complicated by us currently not supporting this code
on iOS/tvOS/watchOS/visionOS.  We should fix that, at which point we
can use the `SwiftStdlib`/`StdlibDeploymentTarget` macros instead.

rdar://164850733
2026-01-09 11:58:35 +00:00
AZero13
c83e58c6f4 Fix typos in Register
37-38 are reserved, not 36
2025-12-31 16:26:03 -05:00
Carl Peto
1c3684f217 make sure crashed is explicitly set if absent, and that symbolication options can be passed in 2025-12-17 12:59:44 +00:00
Carl Peto
740f2d4c81 pr feedback and unit test fixes 2025-12-12 16:32:02 +00:00
Carl Peto
8f8d4585c1 pr feedback
Changed the way swift-backtrace works for JSON, so that it captures
into a CrashLog, then writes to JSON from the CrashLog. Separating out
the two sets of logic so that writing the CrashLog to JSON becomes
simpler and more modular.
2025-12-08 11:29:33 +00:00
Carl Peto
237c99f135 move JSON formatter into Runtime module 2025-12-08 11:29:33 +00:00
Carl Peto
c42dcfcbce refactor JSON.swift from swift-backtrace to be useable by swift-symbolicate 2025-12-08 11:29:32 +00:00
Alastair Houghton
210eae4f7d Merge pull request #82720 from al45tair/eng/PR-154837649
[Backtracing][Linux] Ignore `SHT_NULL` sections.
2025-07-08 15:38:15 +01:00
Alastair Houghton
fbd87591d0 [Backtracing][Linux] Ignore SHT_NULL sections.
The ELF specification says that if a section's type is set to `SHT_NULL`,
_none_ of the other fields are valid, so we shouldn't even be trying to
read the section name.

(We won't crash, because of how all of this code works, but we might
read an incorrect name.)

rdar://154837649
2025-07-02 14:35:16 +01:00