Skip to content

Add Mach-O section parsing#13869

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
madsmtm:parse-macho-section
Jul 14, 2026
Merged

Add Mach-O section parsing#13869
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
madsmtm:parse-macho-section

Conversation

@madsmtm

@madsmtm madsmtm commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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.

Discussed a bit in #13137, I changed my mind since then.
Fixes #8901.
Replaces rust-lang/rustc_codegen_cranelift#1648.

@madsmtm madsmtm requested a review from a team as a code owner July 13, 2026 14:03
@madsmtm madsmtm requested review from alexcrichton and removed request for a team July 13, 2026 14:03
@alexcrichton

Copy link
Copy Markdown
Member

@bjorn3 would you be able to review this?

@madsmtm madsmtm force-pushed the parse-macho-section branch 3 times, most recently from 9853ed2 to ab3b658 Compare July 13, 2026 14:15
@bjorn3

bjorn3 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Sure. Will see if I can do that later today.

Comment thread cranelift/object/src/backend.rs
Comment thread cranelift/object/src/backend.rs
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:module labels Jul 13, 2026
Comment thread cranelift/object/src/backend.rs Outdated
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.
@madsmtm madsmtm force-pushed the parse-macho-section branch from ab3b658 to 7c4fa05 Compare July 14, 2026 10:49
@alexcrichton alexcrichton added this pull request to the merge queue Jul 14, 2026
Merged via the queue into bytecodealliance:main with commit 1de8045 Jul 14, 2026
53 checks passed
@madsmtm madsmtm deleted the parse-macho-section branch July 15, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:module cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cranelift-module: Support marking data object as read-only C string

3 participants