Add Mach-O section parsing#13869
Merged
Merged
Conversation
Member
|
@bjorn3 would you be able to review this? |
9853ed2 to
ab3b658
Compare
Contributor
|
Sure. Will see if I can do that later today. |
madsmtm
commented
Jul 13, 2026
madsmtm
commented
Jul 13, 2026
bjorn3
reviewed
Jul 14, 2026
bjorn3
approved these changes
Jul 14, 2026
Mach-O sections have a type and a number of attributes, and are grouped in segments. There is a canonical textual representation that allows specifying this with the assembly .section directive (mostly defined by LLVM's source). Cranelift supported this with `DataDescription::custom_segment_section` by letting the user implement the parsing themselves, but this complicates the API (and will require breaking changes if we want to support specifying e.g. the stub size). Instead, `DataDescription::custom_section` is now just a `String`, and `cranelift-object` implements the parsing of the section name into its components. This is the same "layering" that LLVM has chosen, and it seems to work well there. This makes it easy for `rustc_cranelift_backend` to implement Rust's `#[link_section = ...]` to support things such as the `ctor` crate.
ab3b658 to
7c4fa05
Compare
alexcrichton
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mach-O sections have a type and a number of attributes, and are grouped in segments. There is a canonical textual representation that allows specifying this with the assembly .section directive (mostly defined by LLVM's source).
Cranelift supported this with
DataDescription::custom_segment_sectionby letting the user implement the parsing themselves, but this complicates the API (and will require breaking changes if we want to support specifying e.g. the stub size).Instead,
DataDescription::custom_sectionis now just aString, andcranelift-objectimplements the parsing of the section name into its components. This is the same "layering" that LLVM has chosen, and it seems to work well there.This makes it easy for
rustc_cranelift_backendto implement Rust's#[link_section = ...]to support things such as thectorcrate.Discussed a bit in #13137, I changed my mind since then.
Fixes #8901.
Replaces rust-lang/rustc_codegen_cranelift#1648.