madsmtm opened PR #13869 from madsmtm:parse-macho-section to bytecodealliance:main:
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 https://github.com/bytecodealliance/wasmtime/pull/13137, I changed my mind since then.
Fixes https://github.com/bytecodealliance/wasmtime/issues/8901.
Replaces https://github.com/rust-lang/rustc_codegen_cranelift/pull/1648.
madsmtm requested alexcrichton for a review on PR #13869.
madsmtm requested wasmtime-compiler-reviewers for a review on PR #13869.
alexcrichton commented on PR #13869:
@bjorn3 would you be able to review this?
madsmtm updated PR #13869.
madsmtm updated PR #13869.
madsmtm updated PR #13869.
bjorn3 commented on PR #13869:
Sure. Will see if I can do that later today.
:memo: madsmtm submitted PR review.
:speech_balloon: madsmtm created PR review comment:
LLVM's parsing is more lenient, they allow whitespace as well. I can implement that too if you want?
:memo: madsmtm submitted PR review.
:speech_balloon: madsmtm created PR review comment:
This requires a stub size (5th part of the custom section name) that should be set with:
https://docs.rs/object/latest/object/read/macho/trait.Section.html#method.symbol_stub_sizeI can implement that too it if you want me to?
github-actions[bot] added the label cranelift:module on PR #13869.
github-actions[bot] added the label cranelift on PR #13869.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
Probably not necessary for now. Can always be implemented later if it turns out people actually use whitespace.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
The only uses I could find are in the rustc test suite: https://github.com/rust-lang/rust/blob/55b6bd8ecbed23599e966a04508a8a13cbfe90b3/tests/ui/linkage-attr/link-section-macho.rs#L44-L58 So fine to defer for now.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
Maybe use the
S_*constants in this test?
:thumbs_up: bjorn3 submitted PR review.
:memo: madsmtm submitted PR review.
:speech_balloon: madsmtm created PR review comment:
Idk., I tend to think it's valuable to not do so? At least for the
foo,bar,literal_pointers,no_toc+no_dead_striptest, what we want to test is that it produces the combined value0x5000_0005, otherwise we'd be doingS_LITERAL_POINTERS | S_ATTR_NO_TOC | S_ATTR_NO_DEAD_STRIP, and that feels like too much code in a test?But that might just be me that's scared of bitwise operations, I'll leave it to your judgement.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
With the test as written it isn't obvious if the mapping from strings to consts is actually correct. I don't have those consts memorized ;)
madsmtm updated PR #13869.
:memo: madsmtm submitted PR review.
:speech_balloon: madsmtm created PR review comment:
Fair. I've changed the test and squashed.
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #13869 Add Mach-O section parsing to the merge queue.
:check: alexcrichton merged PR #13869.
alexcrichton removed PR #13869 Add Mach-O section parsing from the merge queue.
Last updated: Jul 29 2026 at 05:03 UTC