Skip to content
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

[WIP] Enable support for the @_section experimental attribute. #210

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Feb 9, 2024

This PR enables support for @_used and @_section to allow embedding test data directly into its own section in a binary. This means we don't have to look up synthesized test types at runtime.

Limitations:

  1. Test clients must enable support for the experimental "SymbolLinkageMarkers" feature.
  2. The @_section attribute currently doesn't support application to constants of function type, thinking they are non-constant.
  3. We will need to make a change to the Swift runtime on Linux/Windows to add the new section to MetadataSections (or alternatively, the experimental feature needs to provide a different way to discover sections at runtime.) See Add swift5_tests to MetadataSections. swift#71509.

⚠️ Do not merge: this is a proof-of-concept and work-in-progress.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@grynspan
Copy link
Contributor Author

grynspan commented Feb 9, 2024

@swift-ci please test

grynspan added a commit to apple/swift that referenced this pull request 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 apple/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 force-pushed the jgrynspan/adopt-section-attribute branch from c4f2d40 to b586d1b Compare February 9, 2024 19:49
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan self-assigned this Feb 15, 2024
@grynspan grynspan added enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs labels Feb 15, 2024
@grynspan
Copy link
Contributor Author

@compnerd says the Windows section needs the suffix "$B".

Sources/TestingInternals/Discovery.cpp Outdated Show resolved Hide resolved
Sources/TestingInternals/Discovery.cpp Outdated Show resolved Hide resolved
Sources/TestingInternals/Discovery.cpp Show resolved Hide resolved
Sources/TestingInternals/Discovery.cpp Show resolved Hide resolved
@grynspan grynspan force-pushed the jgrynspan/adopt-section-attribute branch from b586d1b to 5498dfa Compare February 20, 2024 20:19
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor Author

Linux failure is expected right now; the new swift5_tests section needs a newer toolchain.

@grynspan
Copy link
Contributor Author

Looks like Windows has a compile-time complaint about the constness of C function pointers.

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan force-pushed the jgrynspan/adopt-section-attribute branch from 5498dfa to 98807fe Compare February 27, 2024 19:37
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan force-pushed the jgrynspan/adopt-section-attribute branch from 98807fe to 554a343 Compare March 7, 2024 16:32
This PR enables support for `@_used` and `@_section` to allow embedding test data directly into its own section in a binary. This means we don't have to look up synthesized test types at runtime.

Limitations:

1. Test clients must enable support for the experimental `"SymbolLinkageMarkers"` feature.
1. The `@_section` attribute currently doesn't support application to constants of function type, thinking they are non-constant.
1. We will need to make a change to the Swift runtime on Linux/Windows to add the new section to `MetadataSections` (or alternatively, the experimental feature needs to provide a different way to discover sections at runtime.)
1. We will need to make a change to the Swift compiler on Linux/Windows to ensure that the aforementioned section is always emitted since section discovery on those platforms is based on static linkage of the section boundary symbols (so if they're not present, a linker error will occur.)

:warning: Do not merge: this is a proof-of-concept and work-in-progress.
@grynspan grynspan force-pushed the jgrynspan/adopt-section-attribute branch from 554a343 to 5cd3809 Compare March 7, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants