Skip to content

[ABI] Add predicate to identify sections containing reflection data #41066

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

Conversation

kastiglione
Copy link
Contributor

ABI/ObjectFile.h abstracts reflection section names across platforms (binary file formats). However, some non-root reflection data is stored in general purpose sections, for example on Darwin type metadata can be placed in __DATA_CONST,__const, such as data that has loader fixups (bindings or relocations).

This change introduces a new predicate function to check if a section name could contain reflection data. These are the swift specific reflections sections, as well as general purpose sections that vary by platform. This initial change adds __DATA_CONST,__const for Mach-O files.

This will be used by overrides of MemoryReader::resolvePointer, to know whether an address is from a reflection section or not. If the section doesn't contain reflection data, then resolvePointer should not return a symbol.

@kastiglione kastiglione force-pushed the ABI-Add-predicate-to-identify-sections-containing-reflection-data branch from 23dac14 to 1d5b4be Compare January 28, 2022 23:18
@kastiglione
Copy link
Contributor Author

@swift-ci smoke test

@@ -56,6 +65,12 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
llvm::Optional<llvm::StringRef> getSegmentName() override {
return {"__TEXT"};
}

bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
return sectionName.startswith("__swift5_") ||
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks sketchy: this line compares a section-name-only string and the next line a segment,section string. Does this actually work?

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e., why isn't this __TEXT,_swift5_?

Copy link
Contributor Author

@kastiglione kastiglione Jan 31, 2022

Choose a reason for hiding this comment

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

The caller is implemented to call first with the section name (ie __swift5_fieldmd), and then secondly call with the segment qualified name (ie __DATA,__const).

Here's that implementation: https://github.com/apple/llvm-project/pull/3848/files#diff-1c2c090c5ff772b9b304dbdd4cf45803478f4f33d11d042817fea7358e0cc96b

You'd prefer mach-o binaries call this once, and pass in a segment qualified name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, that makes sense! In light of the dsymutil patch that copies reflection metadata from __TEXT to __DWARF, this implementation is actually preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment to explain how the caller should call this function.

@kastiglione
Copy link
Contributor Author

fwiw mach-o sections have a flags field. Ideally we wouldn't check names, and instead check for a flag. But that's not something that can independently implement.

@kastiglione
Copy link
Contributor Author

@swift-ci smoke test

@kastiglione
Copy link
Contributor Author

@swift-ci smoke test

@kastiglione kastiglione merged commit 56a614a into main Feb 1, 2022
@kastiglione kastiglione deleted the ABI-Add-predicate-to-identify-sections-containing-reflection-data branch February 1, 2022 04:49
kastiglione added a commit that referenced this pull request Feb 4, 2022
…ctions-containing-reflection-data

[ABI] Add predicate to identify sections containing reflection data

(cherry picked from commit 56a614a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants