Commit Graph

52 Commits

Author SHA1 Message Date
Mike Ash
7edc799b16 [6.2][RemoteMirror] Fix AsyncTask child iteration.
Iterating child tasks depends on knowing the size of AsyncTask, and changing the size of the task broke it. Instead of relying on mirroring the full structure in our out-of-process definitions, add a debug variable to libswift_Concurrency that contains the size of AsyncTask.

While we're there, add some more validation to child task enumeration. Check each child task's metadata pointer to make sure that it actually points to the AsyncTask metadata, and have the inner loop also increment and check ChildTaskLoopCount to stop runaway iteration in that loop.

rdar://148836760

(cherry picked from commit e3057031da)
2025-04-08 15:23:05 -04:00
Evan Wilde
eeee0dfddd CMake: option to disable swift in swift
Adding `SWIFT_ENABLE_SWIFT_IN_SWIFT` option to enable or disable the
parts of Swift that require a Swift compiler to build. This is meant for
bootstrapping compilers on new platforms and is not guaranteed to result
in a compiler that will pass the test suite.

This option is on by default so that folks won't forget.
If the option is off, the resulting compiler does not include the Swift
optimizer sources in SwiftCompilerSources nor does the resulting
compiler have swift macro support.
2025-03-06 13:32:49 -08:00
Robert Widmann
0f94164d3b Replace Hand-Rolled MAX/MIN with std::max/std::min
We're using C++ 14+ at least now across the project so these should not be necessary. It's also kind of wild that the definitions we had across different subsystems had different definitions.
2025-01-22 11:18:35 -07:00
Tim Kientzle
9214ebd360 When ASAN is visible, do not use page-aligned requests 2024-07-24 14:58:16 -07:00
Tim Kientzle
9b7fcba72b Comments 2024-07-23 14:08:02 -07:00
Tim Kientzle
8206c26c59 Remove some debugging code 2024-07-23 09:55:42 -07:00
Tim Kientzle
19cad5fbfb Huge speedup of RemoteMirror testing
**Background:**

Each RemoteMirror test runs two processes: A host process runs the
RemoteMirror library and queries memory data from a target process.  The host
and target communicate by passing strings back and forth with requests to read
particular information in memory.  The target is pure Swift; the host is
C/C++.

**What this change does:**

Without this, the host makes very many small requests to the target.
Each of those requests has to be individually parsed by the target
using String operations from the debug stdlib.  Actually transferring
the raw bytes is relatively quick.
With this, the host requests and caches "pages" of about 4k and
satisfies most requests from previously-fetched data.  This dramatically
reduces the total number of operations.

**Performance notes:**

The following notes only count the time to compile and run the 78 tests in the
validation-tests/Reflection directory using `lit.py`; it does not include time
to rebuild the project before running tests.

**Performance with debug stdlib:**

(That is: `build-script -ra --debug-swift-stdlib`) Before this change, I got
tired of waiting after about 15 minutes and it was about 1/4 done.  Some very
simplistic profiling showed >99% of the time being spent in stdlib String
operations in the target process.  Activity Monitor shows that individual tests
run for about 6 minutes of CPU time each.

With this change, the tests run in about 70s of wall time.  Almost all of the
time seems to spent compiling the tests; the tests themselves run too quickly to
even show up in the Activity Monitor.

**Performance with release stdlib:**

(That is: `build-script -ra`)
The tests run in about 70s of wall time with or without this change.
2024-07-23 09:50:41 -07:00
Alex Lorenz
c8b5344d3e Merge pull request #72014 from compnerd/android
utils: support building android SDKs on Windows
2024-06-07 12:37:00 -07:00
Alastair Houghton
0fa5e65bb2 [Stdlib][Build] Fix the standard library build for fully static Linux.
Mostly this just means adding `Musl` as a module dependency of various
things and making sure that we build things for `swift_static` even
if `SWIFT_BUILD_STATIC_STDLIB` isn't enabled.

There's also a slight difference in the declaration of `memcmp()`;
musl's declaration is more like the one we have on Darwin.

rdar://123508245
2024-05-07 16:56:20 +01:00
Alex Lorenz
7a5a0aad22 [android] misc stdlib build fixes 2024-04-29 15:54:05 -07:00
Ben Troller
bb3c7f5ee8 [RemoteMirror] Allow clients to specify whether Obj-C interop is enabled.
rdar://119570103
2024-01-26 13:11:10 -08:00
Allan Shortlidge
11165f3ef1 NFC: Ignore some -Wcast-qual warnings in swift-reflection-test.c. 2024-01-16 13:27:55 -08:00
Mike Ash
be3015ba66 [Test] Remove five second delay in swift-reflection-test startup.
This was added in ea54c3ba40, presumably inadvertently.
2023-06-08 11:00:26 -04:00
Tim Kientzle
791d780da4 Merge pull request #59488 from tbkka/tbkka-remoteMirrorIndirectEnums
Test support for indirect enums in RemoteMirror
2023-02-15 10:30:08 -08:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00
Tim Kientzle
44f5ee065a This gets through a larger set of tests, but still has a few hacks 2022-06-16 17:43:31 -07:00
Tim Kientzle
afd00a45ab Minor cleanup 2022-06-16 16:40:24 -07:00
Tim Kientzle
c3d378b053 "childForInstance" can drill into a closure context 2022-06-16 13:16:43 -07:00
Tim Kientzle
ea54c3ba40 First sketch of indirect enum support
This is basically an attempt to expand the test harness
to fully dump indirect enums using the existing RemoteMirror
facilities.
2022-06-16 09:54:49 -07:00
Max Desiatov
372ada0e24 test: add handling for Wasm/WASI (#39519)
This change adds support for WASI in stdlib tests. Some tests that expect a crash to happen had to be disabled, since there's currently no way to observe such crash from a WASI host.
2022-01-12 14:24:50 +00:00
Mike Ash
cf3c131e7c [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-18 14:15:25 -05:00
Saleem Abdulrasool
3c9c564eba Revert "[Reflection] Add API for inspecting async task allocation slabs." 2021-11-17 18:47:13 -08:00
Mike Ash
7c7dc5d5b3 [Reflection] Add API for inspecting async task allocation slabs.
We remove the existing `swift_reflection_iterateAsyncTaskAllocations` API that attempts to provide all necessary information about a tasks's allocations starting from the task. Instead, we split it into two pieces: `swift_reflection_asyncTaskSlabPointer` to get the first slab for a task, and `+swift_reflection_asyncTaskSlabAllocations` to get the allocations in a slab, and a pointer to the next slab.

We also add a dummy metadata pointer to the beginning of each slab. This allows tools to identify slab allocations on the heap without needing to locate every single async task object. They can then use `swift_reflection_asyncTaskSlabAllocations` on such allocations to find out about the contents.

rdar://82549631
2021-11-11 16:58:14 -05:00
Michael Gottesman
872d492029 [cmake] Allow for users to build binaries for testing even if we aren't going to run the actual tests.
Previously, we used SWIFT_INCLUDE_TESTS to control if we created build rules for
binaries just used to test as well as running the tests as well. In this commit,
I changed this behavior by adding an option called SWIFT_INCLUDE_TEST_BINARIES.
This will allow for the stage 1 swift build to build and install test binaries
into the just built toolchain for use by the stage 2 swift that builds the
stdlib.
2021-09-01 16:33:04 -07:00
Augusto Noronha
f41d192b48 Implement projectExistentialAndUnwrapClass
Implement a version of projectExistential tailored for LLDB. There are 2
differences when projecting existentials for LLDB:

1 - When it comes to existentials, LLDB stores the address of the error
    pointer, which must be dereferenced.
2 - When the existential wraps a class type, LLDB expects the address
    returned is the class instance itself and not the address of the
    reference.

This patch also adapts the swift reflection test machinery to test
projectExistentialAndUnwrapClass as well. This is done by exposing
the new functionality from swift reflection test.  It is tested in
existentials.swift, and ensures that the typeref information is
exactly the same as what is expected from projectExistential,
except the out address.

(cherry picked from commit 55e971e06750c3ba29722d558cc5400298f6bdaf)
2021-06-16 08:54:50 -03:00
Mike Ash
31f68b1687 [RemoteMirror] Add a call for iterating over the allocations belonging to an AsyncTask.
rdar://72907056
2021-02-11 17:14:38 -05:00
3405691582
7687bc13d2 [tools] Fix invocation of execv.
If execv fails, then there is no valid indication of what failed. This
may manifest itself as an unexpected EOF in `collectBytesFromPipe` when
in fact this is a problem with `execv`. Check the return status and be
noisy if the exec fails.

Now, on other platforms, it may not be a runtime error to call
`execv(..., NULL)`, despite the manual pages and standards requesting
that a valid array be passed. Furthermore, other platforms may require
that argv[0] be populated, and with a valid executable name.

Ensuring that these conditions are fulfilled is more correct, and
permits the Reflection validation tests to successfully run and pass on
OpenBSD.
2021-02-07 10:22:59 -05:00
David Zarzycki
f4be48b157 [NFC] arithmetic on a pointer to void is a GNU extension [-Wpointer-arith] 2021-02-01 07:43:07 -05:00
Kuba (Brecka) Mracek
d7dfa3e942 Bring up tests + validation tests for the 'freestanding' build and the standalone_minimal preset (#34386) 2020-10-26 16:32:36 -07:00
Augusto Noronha
3cb8f9b6fc Add entrypoints to the runtime that exposes metadata necessary for reflection tests on Linux (#32339) 2020-07-24 15:26:15 -07:00
Mishal Shah
6336b14db4 [Apple Silicon] [In-process memory reader] Adjust low-bits computation for arm64 macOS 2020-07-02 18:32:23 -07:00
tbkka
3c8fde7885 Implement MultiPayloadEnum support for projectEnumValue (#30635)
This code rearchitects and simplifies the projectEnumValue support by
introducing a new `TypeInfo` subclass for each kind of enum, including trivial,
no-payload, single-payload, and three different classes for multi-payload enums:

* "UnsupportedEnum" that we don't understand.  This returns "don't know" answers for all requests in cases where the runtime lacks enough information to accurately handle a particular enum.

* MP Enums that only use a separate tag value.  This includes generic enums and other dynamic layouts, as well as enums whose payloads have no spare bits.

* MP Enums that use spare bits, possibly in addition to a separate tag.  This logic can only be used, of course, if we can in fact compute a spare bit mask that agrees with the compiler.

The final challenge is to choose one of the above three handlings for every MPE.  Currently, we do not have an accurate source of information for the spare bit mask, so we never choose the third option above.  We use the second option for dynamic MPE layouts (including generics) and the first for everything else.

TODO: Once we can arrange for the compiler to expose spare bit mask data, we'll be able to use that to drive more MPE cases.
2020-03-31 15:12:44 -07:00
Kuba Mracek
c0ab0c9c0a Fixup swift-reflection-test.c and swift-reflection-dump.cpp 2020-03-07 08:11:52 -08:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
tbkka
0d361bd3ea Teach RemoteMirror how to project enum values (#30161)
Teach RemoteMirror how to project enum values

This adds two new functions to the SwiftRemoteMirror
facility that support inspecting enum values.

Currently, these support non-payload enums and
single-payload enums, including nested enums and
payloads with struct, tuple, and reference payloads.
In particular, it handles nested `Optional` types.

TODO: Multi-payload enums use different strategies for
encoding the cases that aren't yet supported by this
code.

Note: This relies on information from dataLayoutQuery
to correctly decode invalid pointer values that are used
to encode enums.  Existing clients will need to augment
their DLQ functions before using these new APIs.

Resolves rdar://59961527

```
/// Projects the value of an enum.
///
/// Takes the address and typeref for an enum and determines the
/// index of the currently-selected case within the enum.
///
/// Returns true iff the enum case could be successfully determined.
/// In particular, note that this code may fail for valid in-memory data
/// if the compiler is using a strategy we do not yet understand.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_projectEnumValue(SwiftReflectionContextRef ContextRef,
                                      swift_addr_t EnumAddress,
                                      swift_typeref_t EnumTypeRef,
                                      uint64_t *CaseIndex);

/// Finds information about a particular enum case.
///
/// Given an enum typeref and index of a case, returns:
/// * Typeref of the associated payload or zero if there is no payload
/// * Name of the case if known.
///
/// The Name points to a freshly-allocated C string on the heap.  You
/// are responsible for freeing the string (via `free()`) when you are finished.
SWIFT_REMOTE_MIRROR_LINKAGE
int swift_reflection_getEnumCaseTypeRef(SwiftReflectionContextRef ContextRef,
                                        swift_typeref_t EnumTypeRef,
                                        unsigned CaseIndex,
                                        char **CaseName,
                                        swift_typeref_t *PayloadTypeRef);
```


Co-authored-by: Mike Ash <mikeash@apple.com>
2020-03-06 13:17:40 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Michael Ilseman
bfd0de4928 Revert "Revert "Revert "swift-lang: shuffle the source directory structure (N…" 2020-02-20 15:39:51 -08:00
Saleem Abdulrasool
200b96df81 Revert "Revert "swift-lang: shuffle the source directory structure (NFC)""
This reverts commit beb8ecd8cc.  Add a
workaround for the dependency issue.

It is unclear why `sourcekitd` is getting added improperly as a
dependency on `lib/sourcekitd.framework/sourcekitd`.  This workaround
adjusts the dependency such that we end up with a dependency on
`lib/sourcekitd.framework/Versions/A/sourcekitd` as an order-only
dependency.  This should fix the compile issue.  I am unable to
reproduce this issue with the `add_library` usage for adding a Swift
library.  This allows us to cleave the host and target libraries, and so
the workaround is sufficient to make progress and the problem will be
resolved with the migration towards CMake for handling the dependencies.
2020-02-19 16:09:37 -08:00
Ben Langmuir
beb8ecd8cc Revert "swift-lang: shuffle the source directory structure (NFC)"
This reverts commit edbe22b63c.
2020-02-19 13:33:08 -08:00
Ben Langmuir
089d347104 Revert "[swift-lang] Fix dependency on sourcekitd module"
This reverts commit 0ab98fc0e4.
2020-02-19 13:32:54 -08:00
Ben Langmuir
0ab98fc0e4 [swift-lang] Fix dependency on sourcekitd module
The link dependency is not sufficient, because this code depends on the
sourcekitd header and module map, which are produced during the build
process.  This started failing after edbe22b63c, where the dependency
on `sourcekitd-test` was removed. That dependency was itself wrong,
but it happened to be a good enough approximation that we never saw
issues.
2020-02-19 08:45:38 -08:00
Saleem Abdulrasool
edbe22b63c swift-lang: shuffle the source directory structure (NFC)
This moves the swift-lang library out of the tools/SourceKit directory
and into the stdlib directory.  As it stands, the library required that
the standard library and the SDK overlay was being built.  This is
implicitly done when building the stdlib subdirectory.  Furthermore, it
had an odd tie between the flags for Swift and SourceKit which now have
the logic separated.  This clearly delineates the host and target
components in the repository.
2020-02-16 19:12:47 -08:00
David Zarzycki
12ccc5df2c [Testing] Review feedback 2019-08-27 10:56:23 +01:00
David Zarzycki
db0fea4cb4 [Testing] Fix some build warnings 2019-08-26 08:16:06 +01:00
Saleem Abdulrasool
7b1f732b1d swift-reflection-test: silence tautological warning
PE/COFF does not permit weak linking semantics.  This means that the
expression `&symbol == NULL` is tautologically false.  In order to
support this semantic, the symbol needs to be dynamically looked up at
runtime.  Since the ObjC runtime is not in use on Windows currently,
just ignore this for the time being.  Silences a warning from clang
about the tautological comparison.
2019-06-02 11:36:49 -07:00
Mike Ash
8b0ab1cc49 [RemoteMirror] Mark swift_reflection_classIsSwiftMask as a weak import.
Also have swift-reflection-test check if the symbol exists. This allows swift-reflection-test to work with older Remote Mirror dylibs that don't have it.

rdar://problem/50030805
2019-04-23 11:37:37 -04:00
Saleem Abdulrasool
4b9e9d3164 build: excise the concept of fat libraries
This was used for the swift-reflection-test tool.  Instead of using fat
binaries, use the target binary itself.  This simplifies the build logic
as well as paves the road to sub-builds for each target rather than a
monolithic build as we have today.

Originally, the swift-reflection-test was a host tool that linked
against the target libraries since it was testing the target layout.
Now that the tool has been split into a host and target component
(5ea5bb06a3) and we have target and host
libraries that we can link against appropriately, we do not need to link
against the FAT binary.  Since there was exactly one use of this
functionality, switching that from fat linking to regular linking allows
us to remove this functionality entirely.  Switch to regular linking and
remove the option.
2019-03-12 22:30:20 -07:00
Saleem Abdulrasool
2c5fe7dbd8 build: try to fix swift-reflection-test harder
Ensure that the symbol is marked for DLL import rather than just as a local.
2019-03-08 21:33:59 -08:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
Mike Ash
dd170399e4 [Reflection] Add some (disabled by default) debug logging in swift-reflection-test.c. 2019-02-27 14:37:33 -05:00