-
Notifications
You must be signed in to change notification settings - Fork 104
Rewrite static section bounds discovery in Swift. #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite static section bounds discovery in Swift. #1012
Conversation
@swift-ci test |
09723a9
to
3c9eeff
Compare
eae08c4
to
8e967cf
Compare
8e967cf
to
e107fa4
Compare
@swift-ci test |
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.
This reverts commit e107fa4.
e107fa4
to
7a4f5dd
Compare
@swift-ci test |
@swift-ci test |
@swift-ci test Windows |
@swift-ci test |
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful 👍
@swift-ci test |
Honestly, that "Close with comment" button is too easy to click. |
@swift-ci test |
@swift-ci test |
Waiting for a toolchain build to complete before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems unlikely that this would break.
@jckarter Famous last words. |
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 withhasFeature(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.
Resolves rdar://147430270.
Checklist: