Commit Graph

217 Commits

Author SHA1 Message Date
Nate Chandler
2af30b2f04 [NFC] CoroutineAccessors: Remove old runtime files
The functions are open-coded now.
2025-03-27 19:23:09 -07:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Alastair Houghton
26d0e49764 [Backtracing] Updates following review.
Added some explanatory text to the Compact Backtrace Format
documentation, and also to the `CMakeLists.txt` for the runtime.

Tweaked the conversions for `Backtrace.Address` to truncate, which
should result in reasonable behaviour for negative fixed-width
integers.

Use a constant for the ASCII values for `/` and `\` in the Compact
Image Format encoder/decoder.

Make the TSD key for `ElfImageCache` non-optional, and call
`fatalError()` if we don't get one.

rdar://124913332
2025-01-27 17:22:39 +00:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00
Alastair Houghton
a2c33ad22c [Runtime] Fix generation of .lnk files for static linking.
Use the new `SWIFT_SDK_<sdk>_STATIC_LINKING_SUPPORTED` and
`_STATIC_ONLY` flags instead of hardcoding support for Linux
and WASI.

Also, use the `_LIB_SUBDIR` variable rather than lowercasing
the SDK.

rdar://123504757
2024-05-07 16:45:16 +01:00
Alastair Houghton
143a473aa4 [Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
The previous approach was effectively to catch the exception and then
run a trap instruction.  That has the unfortunate feature that we end
up with a crash at the catch site, not at the throw site, which leaves
us with very little information about which exception was thrown or
where from.

(Strictly we do have the exception pointer and could obtain exception
information, but it still won't tell us what threw it.)

Instead of that, set a personality function for Swift functions that
call potentially throwing code, and have that personality function
trap the exception during phase 1 (i.e. *before* the original stack
has been unwound).

rdar://120952971
2024-02-06 16:19:17 +00:00
Mike Ash
4341102c92 [Tools] Add a library to build specialized generic metadata out of process.
This library uses GenericMetadataBuilder with a ReaderWriter that can read data and resolve pointers from MachO files, and emit a JSON representation of a dylib containing the built metadata.

We use LLVM's binary file readers to parse the MachO files and resolve fixups so we can follow pointers. This code is somewhat MachO specific, but could be generalized to other formats that LLVM supports.

rdar://116592577
2024-01-24 20:45:50 -05:00
Mike Ash
29c350e813 [Runtime] Create an external generic metadata builder.
Create a version of the metadata specialization code which is abstracted so that it can work in different contexts, such as building specialized metadata from dylibs on disk rather than from inside a running process.

The GenericMetadataBuilder class is templatized on a ReaderWriter. The ReaderWriter abstracts out everything that's different between in-process and external construction of this data. Instead of reading and writing pointers directly, the builder calls the ReaderWriter to resolve and write pointers. The ReaderWriter also handles symbol lookups and looking up other Swift types by name.

This is accompanied by a simple implementation of the ReaderWriter which works in-process. The abstracted calls to resolve and write pointers are implemented using standard pointer dereferencing.

A new SWIFT_DEBUG_VALIDATE_EXTERNAL_GENERIC_METADATA_BUILDER environment variable uses the in-process ReaderWriter to validate the builder by running it in parallel with the existing metadata builder code in the runtime. When enabled, the GenericMetadataBuilder is used to build a second copy of metadata built by the runtime, and the two are compared to ensure that they match. When this environment variable is not set, the new builder code is inactive.

The builder is incomplete, and this initial version only works on structs. Any unsupported type produces an error, and skips the validation.

rdar://116592420
2024-01-11 09:15:02 -05:00
Alastair Houghton
9d462a7b69 [Backtracing] Add an indication that we're working on a backtrace.
When we crash, emit a message straight away that says we're working
on a backtrace.  If starting the backtracer fails, report that also.

Finally, add a duration to the messages output by the backtracer, so
that we can see how long it took.

rdar://118055527
2023-11-09 18:12:18 +00:00
Alastair Houghton
003b4556b3 [Backtracing] Fix a Windows build issue.
When backtracing is disabled, don't try to refer to
`_swift_backtraceSettings`.

rdar://117470489
2023-11-08 16:06:16 +00:00
Alastair Houghton
c9efa69ef1 [Linux] Make the backtracing symbol reference conditional.
On the LSan builds, we disable the backtracer, which results in a
link error because we completely remove the code from libswiftCore.

rdar://116105222
2023-09-27 09:56:22 +01:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Yuta Saito
7aa6cbbe2d Merge pull request #66851 from kateinoigakukun/katei/patch-series/driver-wasm-toolchain
Re-land `static-executable-args.lnk` changes
2023-06-29 12:38:51 +09:00
Alastair Houghton
4f4d0147ca Merge pull request #66721 from al45tair/eng/PR-110665213
[Threading][TSan] Fix TSan errors from lazy init on Linux.
2023-06-22 20:03:00 +01:00
Yuta Saito
a613ab2521 Revert "Revert "Merge pull request #66793 from kateinoigakukun/pr-a75d757a3dcce5b990423cf1ab73ba4cd2f95b10""
This reverts commit 7aa4a8de06.
2023-06-22 08:31:32 +00:00
Yuta Saito
ad9409b517 [static-stdlib] NFC: Generalize the static-executable-args.lnk file generation
This patch makes the build system to copy the lnk files for each
stdlib targets if needed instead of only for the Linux target.

This is the take 2 of the patch. The first one was reverted in
7aa4a8de06
2023-06-22 08:30:37 +00:00
Max Desiatov
bcc102d621 Revert "Merge pull request #66759 from kateinoigakukun/pr-a33fc5da8cdbc494e3935399dd7b74eba2288267"
This reverts commit 0795dede1c, reversing
changes made to 0845bc1373.
2023-06-21 17:55:05 +01:00
Max Desiatov
7aa4a8de06 Revert "Merge pull request #66793 from kateinoigakukun/pr-a75d757a3dcce5b990423cf1ab73ba4cd2f95b10"
This reverts commit c9d20c4024, reversing
changes made to ca0061dab7.
2023-06-21 17:54:43 +01:00
Yuta Saito
2555dc7e35 [static-stdlib] Add static executable support for WASI target
This patch adds static-executble-args.lnk file for WASI target
2023-06-21 03:29:20 +00:00
swift-ci
0795dede1c Merge pull request #66759 from kateinoigakukun/pr-a33fc5da8cdbc494e3935399dd7b74eba2288267
[static-stdlib] NFC: Generalize the static-executable-args.lnk file generation
2023-06-20 20:22:44 -07:00
Yuta Saito
29b27374d9 [static-stdlib] NFC: Generalize the static-executable-args.lnk file generation
This patch makes the build system to copy the lnk files for each
stdlib targets if needed instead of only for the Linux target.

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
2023-06-21 01:07:32 +00:00
Yuta Saito
ae0a061663 Merge pull request #66543 from kateinoigakukun/pr-b1e7535cbac5af8c5e06068a747c1b925d571265
[wasm] Add metadata registration for WebAssembly
2023-06-20 19:52:07 +09:00
Alastair Houghton
bad716f2cd [Threading][TSan] Rearrange things again.
We need ThreadSanitizer.cpp in libswiftCore for the runtime case, but
we also need it in libswiftThreading for non-runtime cases.

rdar://1106655213
2023-06-19 17:00:39 +01:00
Alastair Houghton
8ed8a28478 [Threading][TSan] Move ThreadSanitizer.cpp into the main runtime.
On Darwin, `RTLD_NEXT` doesn't do what we need it to here, with the
result that if `libswiftCore`'s TSan initializer gets found first,
then `libswift_Concurrency` won't have its initializer called at all,
in spite of us using `RTLD_NEXT` to find the next definition.

Fix this by centralising the initializer in `libswiftCore` instead.

rdar://110665213
2023-06-19 15:33:36 +01:00
Yuta Saito
f527f72640 Merge pull request #66423 from kateinoigakukun/pr-0c7c2f57b05a694965ab652f57cbfead006a33d7
[static-stdlib] Move static-executable-args.lnk under stdlib/public/Resources/linux
2023-06-19 19:30:53 +09:00
Yuta Saito
8d84a64556 [wasm] Add metadata registration for WebAssembly
This patch adds the metadata registration for the wasm targets, and also
adds build support for it.
2023-06-19 06:13:20 +00:00
Mike Ash
110f428780 [Runtime] Add tracing for section scans.
Section scans (for metadata, protocols, etc.) can be costly. This change adds tracing calls to those scans so we can more easily see how much time is spent in these scans and where they're initiated.

This adds an os_signpost implementation controlled by SWIFT_STDLIB_TRACING, and a default empty implementation for when that's disabled.

rdar://110266743
2023-06-14 12:07:44 -04:00
Yuta Saito
2410da4259 [static-stdlib] Move static-executable-args.lnk under stdlib/public/Resources/linux
This is a preparatory change for adding a static executable support for WASI
2023-06-08 11:46:18 +00:00
Alastair Houghton
2dcaa6f14f [Backtracing][Linux] Add Linux crash handler to the runtime.
This also adds a function to demangle a symbol, and a way for the
backtracing code to report warning messages to the same place as
the main runtime.

I'd like to rename the _swift_isThunkFunction() SPI also, but we
can't do that until we've made the changes to the _Backtracing
library, so we'll do that there instead.

rdar://110261430
2023-06-05 15:39:50 +01:00
Alastair Houghton
0261a29fee [Backtracing] Support specifying a hard-coded path for swift-backtrace.
Add a way to disable dynamic lookup of the backtracer path, for situations
where a hard-coded path makes more sense.

rdar://107360391
2023-03-29 15:08:48 +01:00
Alastair Houghton
1258d45152 [Backtracing] Build work.
Additional shimming required for some builds, as well as a few other build
related tweaks.

rdar://106234311
2023-03-04 15:46:30 +00:00
Alastair Houghton
8a29657f4c [Runtime] [Darwin] Add code to trigger the external backtracer.
When a Swift program crashes, we should catch the crash and execute the
external backtracer.

rdar://105391747
2023-03-04 07:56:02 +00:00
Alastair Houghton
f02f62f1e3 [Backtracing] Add support for looking up paths for auxiliary executables.
We need to be able to locate `swift-backtrace` relative to the current
location of the runtime library.

This needs to work:

* In a Swift build directory.
* On Darwin, where we're installed in /usr/lib/swift and /usr/libexec/swift.
* On Linux, where we're in /usr/lib/swift/linux and /usr/libexec/swift/linux.
* On Windows, where we may be in a flat directory layout (because of limitations
  of Windows DLL lookups).

rdar://103071801
2023-03-01 13:43:15 +00:00
Dario Rexin
96d988a431 [Runtime] Move bytecode layout handling into runtime (#63901)
rdar://105904548
2023-02-25 10:18:45 -08:00
Jonathan Grynspan
b2bbf00bd7 Remove unused infrastructure added for runtime attributes (#62971) 2023-01-12 04:16:45 -08:00
Alastair Houghton
a31b1c54fa Centralise code to map between UTF-8 and UTF-16 on Windows.
In various places we need to call the Windows API, and because Swift uses UTF-8
for its string representation, we can’t call the ANSI API functions (because the
code page used for the ANSI functions varies depending on the system locale
setting). Instead, we need to use the wide character APIs.

This means that we need to convert UTF-8 to wide character and vice-versa in
various places in the runtime.

rdar://103397975
2022-12-21 11:44:35 +00:00
Jonathan Grynspan
11033c6aa4 Fill out dynamic loading of the runtime attributes section 2022-12-20 09:45:01 -08:00
Jonathan Grynspan
26fc627ad0 Fix a use-after-free bug on Win32 when calling lookupSymbol() (#62484) 2022-12-13 09:04:34 -05:00
Alastair Houghton
fae8d20978 Merge pull request #59425 from thevinster/lto
[cmake] Prevent test failures by disabling LTO for swift runtime
2022-06-16 09:21:51 +01:00
Vincent Lee
a81bb11f35 [cmake] Prevent test failures by disabling LTO for swift runtime 2022-06-15 18:57:39 -07:00
Alastair Houghton
ab9e628b72 [Threading][Runtime] Separate threading error function to fix link on Linux.
On Linux it seems that the linker objects, probably because of link order,
to the definition of `swift::threading::fatal()` being in both static
libraries.  Fix by moving `swift::threading::fatal()` to its own file
in the main runtime as well as the Concurrency runtime.

Fixes #59444.
2022-06-15 08:22:53 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
63a09007a1 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-05-24 14:57:39 +01:00
Alastair Houghton
dadcb04ae2 [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-05-24 14:57:38 +01:00
Alastair Houghton
b3b080e12d Merge pull request #42109 from al45tair/eng/PR-91095592
[Demangling] Fix duplicate _gCRAnnotations symbol problems.
2022-04-01 16:37:05 +01:00
Alastair Houghton
3f49b8be32 [Demangling] Fix duplicate _gCRAnnotations symbol problems.
Moved the _gCRAnnotations declarations to their own object module,
which will help to avoid duplicate symbol problems (at least with .a
files).

Also tweaked things to make it so that the demangler and runtime
versions of the message setting code will interoperate (and so that
they'll interoperate better with other implementations that might
creep in from somewhere, like the one in LLVMSupport).

rdar://91095592
2022-03-31 13:04:09 +01:00
Evan Wilde
1977a6859e Fix statically linked concurrency on Linux
Generating a statically-linked executable either with
`-static-executable` or `-static-stdlib` that contains concurrency needs
to link the concurrency libraries or the missing symbols will cause link
failures.

This patch adds dispatch and blocks runtime to the list of statically
linked libraries. In the case of the static stdlib, it only adds them if
the concurrency mechanisms use dispatch, otherwise it doesn't.

For the static executable, it always adds them since that doesn't appear
to be very configurable.
2022-03-28 16:21:17 -07:00
Pavel Yaskevich
3f4c06eb1b [Distributed] Runtime: Add skeleton support for accessible function sections 2021-12-17 10:52:56 -08:00