You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewrite static section bounds discovery in Swift. (#1012)
This PR rewrites the static section bounds discovery code in Swift
(replacing the current C++ implementation.) We are making use of
`@_silgen_name` here to name the section bounds symbols that are defined
by the linker, so we'll want to get the core team's approval before
merging.
### Why do we need to rewrite this code in Swift?
In Embedded Swift, there is only one (statically linked) image in the
process containing Swift code, and if the target is a microcontroller or
similar, it probably doesn't even have a dynamic linker/loader in the
first place for us to query. So we need, on Embedded Swift targets, to
perform static discovery of exactly one test content section. (This is
potentially something we can make configurable via the target's toolset
in a future PR.)
The bounds of the test content section are currently defined in C++
using `__asm__` to reference linker-defined symbols. However, our C++
target can't reliably tell if it is being built for Embedded Swift. That
knowledge is treated by the Swift toolchain as a Swift language feature
and can be checked in Swift with `hasFeature(Embedded)`, but there's no
C++ equivalent. If the implementation is written in Swift, we can know
at compile time whether or not we're dynamically or statically linking
to a test target (and therefore whether we need to do dynamic or static
lookup of images, customized toolset aside.)
Rewriting this logic in Swift reduces our C++ code size (and our direct
dependencies on the C++ STL) which is also a nice bonus.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
0 commit comments