Skip to content

Add swift5_tests to MetadataSections. #71509

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

Merged

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Feb 9, 2024

This PR adds a swift5_tests property to MetadataSections and populates it in the static constructors used on Linux and Windows. This section will be used by swift-testing to store test metadata for discovery at runtime (see swiftlang/swift-testing#210.)

This change is necessary because on Linux and Windows, section boundaries are not discoverable at runtime and so must be noted on a per-image basis at compile time. (This is also why MetadataSections and the static constructors are present in the first place.)

There are no compiler changes needed here. The compiler does not need special knowledge of the tests section emitted by swift-testing. The compiler does not itself need to emit anything into this section.

This change does not affect platforms that use the Mach-O binary format (i.e. Darwin) because on those platforms, there is API to find sections and segments at runtime.

This PR adds a `swift5_tests` property to `MetadataSections` and populates it in the static constructors used on Linux and Windows. This section will be used by swift-testing to store test metadata for discovery at runtime (see swiftlang/swift-testing#210.)

This change is necessary because on Linux and Windows, section boundaries are not discoverable at runtime and so must be noted on a per-image basis at compile time. (This is also why `MetadataSections` and the static constructors are present in the first place.)

There are no compiler changes needed here. The compiler does not need special knowledge of the tests section emitted by swift-testing. The compiler does not itself need to emit anything into this section.

This change does not affect platforms that use the Mach-O binary format (i.e. Darwin) because on those platforms, there is API to find sections and segments at runtime.
@grynspan grynspan requested a review from kubamracek February 9, 2024 16:35
@grynspan
Copy link
Contributor Author

grynspan commented Feb 9, 2024

@swift-ci please smoke test

@grynspan grynspan marked this pull request as ready for review February 18, 2024 13:43
@grynspan grynspan requested review from mikeash, al45tair and a team as code owners February 18, 2024 13:43
@grynspan grynspan added Linux Platform: Linux Windows Platform: Windows runtime The Swift Runtime XCTest Flag: Involves XCTest labels Feb 18, 2024
@grynspan grynspan self-assigned this Feb 18, 2024
@grynspan
Copy link
Contributor Author

That "ready for review" button is too easy to hit in the mobile app.

@grynspan grynspan marked this pull request as draft February 18, 2024 13:48
@grynspan grynspan requested a review from compnerd February 18, 2024 13:51
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition of this is fine. Where is the content emitted? The Windows case is particularly interesting as that requires specific section naming (the content itself must be emitted into the B group so that the boundaries are properly ordered).

@grynspan
Copy link
Contributor Author

Addition of this is fine. Where is the content emitted? The Windows case is particularly interesting as that requires specific section naming (the content itself must be emitted into the B group so that the boundaries are properly ordered).

I believe it's going in the "C" section along with all the other emitted Swift section symbols. Mind helping me make sense of the macros in the SwiftRT-COFF source?

@grynspan
Copy link
Contributor Author

Worth noting the plan for the ABI for this section is to emit data only, no executable code, so I think it should be fine to do the same as what other sections do?

@grynspan
Copy link
Contributor Author

Re-reading the Windows section documentation here: I think we're fine?

@compnerd
Copy link
Member

Addition of this is fine. Where is the content emitted? The Windows case is particularly interesting as that requires specific section naming (the content itself must be emitted into the B group so that the boundaries are properly ordered).

I believe it's going in the "C" section along with all the other emitted Swift section symbols. Mind helping me make sense of the macros in the SwiftRT-COFF source?

The section should be fine (sw5test). However, the linker table generation relies on grouping to get the start and end symbols ordered properly. The start symbol is emitted into sw5test$A and the end symbol into swtest$C. The content of the (unsorted) table is emitted into group B - sw5test$B. This allows the linker to sort the groups properly as they are sorted lexicographically. Since the emission is not in the compiler, I just wanted to cross-check that the table contents were emitted into the proper group.

@grynspan grynspan marked this pull request as ready for review February 19, 2024 17:18
@grynspan
Copy link
Contributor Author

As of right now, the content of the section is not emitted by any component. swift-testing will (hopefully/eventually) start emitting data in a future PR.

So I think all is well.

@grynspan grynspan merged commit d35dcc8 into main Feb 19, 2024
@grynspan grynspan deleted the jgrynspan/add-swift-tests-section-to-metadatasections branch February 19, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Platform: Linux runtime The Swift Runtime swift 6.0 Windows Platform: Windows XCTest Flag: Involves XCTest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants