Commit Graph

3149 Commits

Author SHA1 Message Date
Jonathan Grynspan
b2bbf00bd7 Remove unused infrastructure added for runtime attributes (#62971) 2023-01-12 04:16:45 -08:00
Erik Eckstein
0e78660bdd linux: link the stdlib against the clang rt libs
This fixes missing floating point conversion symbols.
It also makes the workarounds in Float16Support.cpp obsolete.

rdar://102641225
2023-01-11 13:51:02 +01:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00
Alastair Houghton
f0200bc0d8 Conditionalise the warnings on an environment variable.
We'll only generate warnings if SWIFT_DEBUG_FAILED_TYPE_LOOKUP is
enabled.

rdar://103950409
2023-01-06 14:42:27 +00:00
Alastair Houghton
d9db40d356 Make the swift_getTypeByMangled... functions emit error messages.
When type lookups fail, these functions should at least generate a warning.

rdar://103950409
2023-01-06 13:04:38 +00:00
Alastair Houghton
e73de539b8 Move _swift_win32_withDbgHelpLibrary into the new header.
It makes sense to move this function into the new Win32 header.

rdar://103397975
2022-12-21 11:44:37 +00:00
Alastair Houghton
fb1211e3fa Rename the functions as they're exported as C APIs.
`SWIFT_RUNTIME_STDLIB_INTERNAL` does `extern "C"`, so we can't put these
in a namespace and have to use a C-style prefix instead.

Also slightly rearrange the code in `CommandLine.cpp`.

rdar://103397975
2022-12-21 11:44:37 +00:00
Alastair Houghton
ca771c4d1d Change to returning nullptr rather than triggering a fatal error.
Instead of triggering a fatal error on failure, return `nullptr` and
let the caller decide what to do about it.  The CommandLine code should
trigger a fatal error, of course.

rdar://103397975
2022-12-21 11:44:37 +00: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
8af9b14428 Only touch the MetadataSections::swift5_runtime_attributes field in newer structures 2022-12-20 09:45:01 -08:00
Jonathan Grynspan
11033c6aa4 Fill out dynamic loading of the runtime attributes section 2022-12-20 09:45:01 -08:00
Pavel Yaskevich
a5af302173 [stdlib] RuntimeMetadata: Register newly added "runtime attributes" section 2022-12-20 09:45:01 -08:00
Arnold Schwaighofer
1e82ef8df7 Fix dynamic replacement of weakly linked symbols
If the replaced symbol goes away in the original library, the
replacement key in the replacement descriptor will be null. Handle this
by ignoring the replacement entry rather than crashing.

rdar://103307821
2022-12-15 13:19:34 -08:00
Jonathan Grynspan
70d4b4678e Add swift:: in a couple of places that don't have using namespace swift (affects sourcekit-lsp) (#62583) 2022-12-14 16:34:44 -05:00
Jonathan Grynspan
c889270a38 Remove lookupSymbol() and have all callers use SymbolInfo::lookup() instead (#62552) 2022-12-14 08:33:32 -05:00
Jonathan Grynspan
26fc627ad0 Fix a use-after-free bug on Win32 when calling lookupSymbol() (#62484) 2022-12-13 09:04:34 -05:00
Mike Ash
108f7805e5 [Runtime] Fatal error if self escapes from deinit.
When deallocating a class instance, we check the retain count of the instance and error if it's greater than 1.

Self is allowed to be temporarily passed to other code from deinit, but there's no way to extend the lifetime of the object. Retaining it no longer extensd the lifetime. If self escapes from deinit, the result is a dangling pointer and eventual crash.

Instead of crashing randomly due to a dangling pointer, crash deliberately when destroying an object that has escaped.

rdar://93848484
2022-12-07 12:42:41 -05:00
Jonathan Grynspan
e057172b6f Make _swift_willThrow atomic (#62349)
* Make _swift_willThrow atomic
2022-12-03 10:41:56 -05:00
Jonathan Grynspan
c30f62f202 Merge pull request #62294 from grynspan/jgrynspan/dbghelp-pass-handle
Refactor `_swift_withWin32DbgHelpLibrary()` to avoid using `GetCurrentProcess()` per Microsoft documentation
2022-11-30 22:18:28 -05:00
Jonathan Grynspan
024f018b22 Missed a bool -> HANDLE conversion 2022-11-30 16:33:07 -05:00
Jonathan Grynspan
687f754c8f Rename the runtime function to 'namespace' it in 'win32' 2022-11-30 15:32:24 -05:00
Mike Ash
fefe33fd7d [Runtime] Add missing bridgeObjectRR_xN entrypoints.
We're supposed to expose bridgeObjectRetain/Release_xN variants, but they were missing. This fixes the custom_rr_abi.swift test. Also remove the redundant extern "C" on the entrypoint definitions, which fixes some warnings.

rdar://102793667 rdar://102783074
2022-11-30 10:50:14 -05:00
Jonathan Grynspan
e199f0b077 Refactor _swift_withWin32DbgHelpLibrary to avoid using GetCurrentProcess() per Microsoft documentation 2022-11-29 16:02:53 -05:00
Mike Ash
f3feea5a12 Merge pull request #62103 from mikeash/custom-rr-abi
[Runtime] Add register-specific entrypoints for retain/release calls on ARM64.
2022-11-28 16:52:36 -05:00
Kuba (Brecka) Mracek
42ca1c4e73 Avoid using strndup in TupleImpl::childMetadata (#62121) 2022-11-16 11:20:28 -08:00
Mike Ash
b677b5676a [Runtime] Add register-specific entrypoints for retain/release calls on ARM64.
This will allow emitted code to condense a sequence like:

    mov x0, x21
    bl swift_retain

To:

    bl swift_retain_x21

Saving code size.

rdar://98884198
2022-11-15 09:53:49 -05:00
Erik Eckstein
77fd3a7004 runtime: fix a wrong fall-through caused by an assert(false)
Replace the `assert(false)` with `swift_unreachable`.
This is more robust in release builds where the `assert(false)` is a no-op and would result in a wrong fall-though to the next switch case.
Fixes a warning in release builds.
2022-11-14 20:40:56 +01:00
Mike Ash
42899535d8 [Runtime] Fix swift_bridgeObjectRetain on ARM64 Linux.
The tail call of swift_retain isn't correct there. Revert back to a non-tail call for all !SWIFT_OBJC_INTEROP for now.

rdar://102152616
2022-11-10 12:19:07 -05:00
Mike Ash
b9391c03e5 Merge pull request #61794 from mikeash/retain-stack-frames
[Runtime] Eliminate stack frames in swift_retain and swift_bridgeObjectRetain on ARM64.
2022-11-08 15:32:55 -05:00
Mike Ash
724a9a7da4 [Runtime] Eliminate stack frames in swift_retain and swift_bridgeObjectRetain on ARM64.
Rearrange the slow paths a bit to make them tail calls, which allows the compiler to emit these functions without frames.

Clang is happy to emit frameless functions on ARM64 if no stack space is needed on all execution paths. However, when there's a fast path which doesn't need stack space, and a slow path which does, clang emits code that pushes a stack frame and then decides which path to take. This is fine, but it means we're paying more than we'd like to on the fast path.

We can work around that by manually outlining the slow path, and ensuring that it's invoked with a tail call. Then the original function doesn't need a stack frame on any path and clang omits the stack frame.

We tweak RefCounts::increment to return the object it's being called on, which allows `swift_retain` to tail-call it. We manually outline the objc_retain call in swift_bridgeObjectRetain, which allows the swift_retain path to be frameless.

rdar://101764509
2022-11-07 15:38:14 -05:00
Alastair Houghton
26ded3f6b1 Also remove SWIFT_REFLECTION_METADATA_ELF_NOTE_MAGIC_STRING.
We aren't using this constant any more either.

rdar://101749382
2022-11-04 16:04:20 +00:00
Alastair Houghton
5e6c8b18ba Remove erroneous ELF note.
On ELF platforms we currently output an ELF note but with totally invalid
contents.  I tried experimenting to see whether it was possible to do it
properly and tie the result into ReflectionContext, but it turns out to be a
hard problem because of issues to do with cross-segment symbol references and
relocations.

The upshot is that I think for now it's best just to remove it.

We might revisit this in future at some point; it would be good to be able to
reliably find the Swift metadata just from the ELF Phdrs.

rdar://101749382
2022-11-04 02:51:20 -07:00
Alsey Coleman Miller
62b7be4e9c [stdlib] Add RISCV64 support 2022-11-01 23:59:42 -07:00
Mike Ash
96e965a359 [Concurrency] Use dispatch cooperative queues when available.
These queues are better suited to the concurrency runtime.
2022-09-29 15:46:35 -04:00
swift-ci
51d937cf2a Merge pull request #61276 from mikeash/fix-concurrent-type-by-name-again
[Runtime] Fix concurrent lookups of types by name (again).
2022-09-28 10:22:53 -07:00
Anthony Latsis
c731089068 Gardening: Migrate stdlib sources to GH issues 2022-09-26 06:30:49 +03:00
Mike Ash
e15783ecd4 [Runtime] Fix concurrent lookups of types by name (again).
Fix a potential false positive if we check a class for a protocol conformance and its superclasses aren't yet instantiated.

This was partially fixed before, but we were incorrectly saying that all superclasses had been instantiated if they had been instatiated by the LAST check in conformsToProtocol. That left us open for a possible false positive in an earlier check to go unnoticed.

This change fixes it by checking for uninstantiated superclasses after each iteration over superclasses, not just the last one.

This change also makes the concurrentTypeByName test much more robust. The original test caught this bug only rarely, but the new one catches it it reliably. We now look up 1000 types per test run. Testing locally, we typically hit the race after less than 100 types.

rdar://82364236
2022-09-23 16:45:30 -04:00
Julian Lettner
0c53630afd Cleanup outdated comment
In the general case, the compiler should add ptrauth instructions even
for simple pointer equality checks.  We therefore need to manually avoid
these checks; making this workaround permanent.
2022-09-21 16:02:08 -07:00
swift-ci
d93c022125 Merge pull request #61076 from mikeash/unsafe-continuation-validation
[Concurrency] Add an environment variable to validate unchecked continuation usage.
2022-09-16 18:27:22 -07:00
Mike Ash
afc5116ef0 [Concurrency] Add an environment variable to validate unchecked continuation usage.
When enabled, we track all active unchecked continuations in a global set, and fatal error if one is called twice.

rdar://97390481
2022-09-16 13:50:59 -04:00
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +01:00
Ben Pious
57d82317c1 Add CustomDebugDescription conformance to AnyKeyPath (#60133)
* initial

* it works

demangling mostly works

fix dots

printing works

add tests

add conformance to AnyKeyPath

implement SPI

subscripts fully work

comments

use cross platform image inspection

remove unnecessary comment

fix

fix issues

add conditional conformance

add types

try to fix the api-digester test

cr feedback: move impls behind flag, remove addChain(), switch statement, fallthrough instead of if-elses, move import

cr feedback: refactor switch statement

fix #ifdef

reindent, cr feedback: removes manual memory management

fix missing whitespace

fix typo

fix indentation issues

switch to regexes

checks should test in on all platforms

print types in subscripts

add test for empty subscript

Update test/api-digester/stability-stdlib-abi-without-asserts.test

Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>

add commas

fix failing test

fix stdlib annotation

cr feedback: remove global, refactor ifdef

cr feedback: switch back to manual memory management

switch to 5.8 macro

add new weakly linked functions to the allowlist

fix one more failing test

more cr feedback

more cr feedback

* fix invisible unicode
2022-09-13 09:23:32 -07:00
Anton Korobeynikov
c89e270b7d Implement value witness table for @differentiable functions (#60875)
@differentiable function is actually a triple (function, jvp, vjp). Previously normal thick function value witness table was used. As a result, for example,  only function was copied, but none of differential components.

This was the cause of uninitialized memory accesses and subsequent segfaults.

Should fix now unavailable TF-1122
2022-09-01 03:09:39 -07:00
Mike Ash
91b86912e6 [Runtime] Fix rare crash when fixing up dynamic subclasses.
Swift vtables can contain NULL entries. This happens when the compiler is able to prove that a method is never called.

When ptrauth is enabled, those NULL entries are still signed. However, there's an inconsistency in the runtime. Most places where we copy a vtable with swift_ptrauth_copy_code_or_data, we accept an unsigned NULL value. But when fixing up a dynamic ObjC subclass with swift_objc_classCopyFixupHandler, we don't.

Since the compiler seems to always sign these NULL values, this still works, except in the case where a signed NULL value coincidentally has a ptrauth signature of all zeroes. When that happens, the code to accept an unsigned NULL value sees this NULL with an all-zero signature as an unsigned NULL, and copies it verbatim. Then we really do have an unsigned NULL in the destination.

If that class is then dynamically subclassed, we'll call swift_objc_classCopyFixupHandler which does not accept unsigned NULL values, and fail ptrauth.

Adjust swift_objc_classCopyFixupHandler to accept unsigned NULL like the rest. These entries should never be called, and any attempt to call them will crash regardless, so it makes little difference.

rdar://92800322
2022-07-25 22:38:55 -04:00
zoecarver
13b0a5bc37 [nfc] Clang format changes. 2022-07-21 17:34:36 -04:00
zoecarver
c9f54e1417 [nfc] Rename CxxCustom -> Custom and fix comments based on review feedback. 2022-07-21 10:25:57 -04:00
John McCall
caa57f5f0d Fix extended existential symbolic demangling on arm64e.
Fixes rdar://96367576 and rdar://96367737.
2022-07-05 18:18:11 -04:00
Kuba (Brecka) Mracek
f13a5213c8 Explicitly #include <cctype> to avoid relying on isdigit being available through unrelated headers (#59745) 2022-07-05 17:30:12 +02:00
swift-ci
f8c608a3fd Merge pull request #59366 from eltociear/patch-35
Fix typo in SwiftDtoa.cpp
2022-07-03 15:02:10 -07:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00