faysou opened PR #14985 from faysou:cranelift-object-macho-shared-custom-sections to bytecodealliance:main:
Problem
ObjectModule::define_datacallsadd_sectionfor every data object that has a custom section. A Mach-O object holds at most 255 sections, soObjectProduct::emitfails withToo many sections: 0x12donce a module defines more data objects than that.This happens in practice with rustc_codegen_cranelift on aarch64 macOS: every
inventory::submit!static goes into__DATA,__mod_init_func, and buildingnautilus-modelhits the limit.Change
On Mach-O, reuse an existing section when segment, name,
SectionKind, and Mach-O flags all match, as LLVM does when it merges sections with the same name. ELF and COFF output is unchanged.Testing
- New
macho_data_objects_share_custom_sectionincranelift/object/tests/basic.rs: defines 300 objects in__DATA,__mod_init_func,mod_init_funcsplus one in a second custom section, then checks there is exactly one section of each with the expected size and section type. It fails without the fix (Too many sections: 0x12d) and passes with it.cargo test -p cranelift-object,cargo fmt --check, andcargo clippy -p cranelift-object --all-targetspass.
faysou removed the review request for wasmtime-compiler-reviewers from PR #14985.
faysou requested fitzgen for a review on PR #14985.
faysou requested wasmtime-compiler-reviewers for a review on PR #14985.
github-actions[bot] added the label cranelift on PR #14985.
github-actions[bot] added the label cranelift:module on PR #14985.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
if self.object.format() == BinaryFormat::MachO && let Some(§ion) = self.macho_custom_sections.get(&(segment.clone(), section.clone(), kind, macho_flags.0))
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
LLVM emits an error when a section is defined twice with different flags.
:speech_balloon: bjorn3 deleted PR review comment.
faysou updated PR #14985.
:memo: faysou submitted PR review.
:speech_balloon: faysou created PR review comment:
Thanks, switched to a let-chain. The insert below now checks the format directly too, since there's no optional key anymore.
:memo: bjorn3 submitted PR review.
:speech_balloon: bjorn3 created PR review comment:
Can you inline this to avoid the clones outside Mach-O?
faysou updated PR #14985.
:memo: faysou submitted PR review.
:speech_balloon: faysou created PR review comment:
Done. The lookup key is now built inside the let-chain, and the insert key is built only for Mach-O before add_section takes ownership of the names.
Last updated: Oct 31 2026 at 23:03 UTC