rust-lang/rust · critical

unsupported Apple pointer width {pointer_width:?}

Error message

unsupported Apple pointer width {pointer_width:?}

What it means

Thrown by add_data_and_relocation in the Apple (Mach-O) object writer when emitting the placeholder bytes for an exported symbol whose relocation size is determined by target.pointer_width. The match arms only cover 32-bit and 64-bit widths (plus a special arm64e authenticated-pointer case that forces an 8-byte signed value). Any other pointer width hits unimplemented!, signaling that rustc has no Mach-O relocation encoding for that width. In practice every Apple target today is 32- or 64-bit, so this guards against a future or malformed target specification.

Source

Thrown at compiler/rustc_codegen_ssa/src/back/apple.rs:95

/// ```console
/// objdump --macho --reloc foo.o
/// objdump --macho --full-contents foo.o
/// ```
pub(super) fn add_data_and_relocation(
    file: &mut object::write::Object<'_>,
    section: object::write::SectionId,
    symbol: object::write::SymbolId,
    target: &Target,
    kind: SymbolExportKind,
) -> object::write::Result<()> {
    let authenticated_pointer =
        kind == SymbolExportKind::Text && target.llvm_target.starts_with("arm64e");

    let data: &[u8] = match target.pointer_width {
        _ if authenticated_pointer => &[0, 0, 0, 0, 0, 0, 0, 0x80],
        32 => &[0; 4],
        64 => &[0; 8],
        pointer_width => unimplemented!("unsupported Apple pointer width {pointer_width:?}"),
    };

    if target.arch == Arch::X86_64 {
        // Force alignment for the entire section to be 16 on x86_64.
        file.section_mut(section).append_data(&[], 16);
    } else {
        // Elsewhere, the section alignment is the same as the pointer width.
        file.section_mut(section).append_data(&[], target.pointer_width as u64);
    }

    let offset = file.section_mut(section).append_data(data, data.len() as u64);

    let flags = if authenticated_pointer {
        object::write::RelocationFlags::MachO {
            r_type: object::macho::ARM64_RELOC_AUTHENTICATED_POINTER,
            r_pcrel: false,
            r_length: 3,
        }

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Use a stock Apple target triple (aarch64-apple-darwin, x86_64-apple-darwin, aarch64-apple-ios, etc.) instead of a custom spec.
  2. If you must use a custom target spec, ensure its data-layout pointer width is exactly ':32' or ':64'.
  3. If adding a genuinely new Apple architecture to the compiler, extend the match in compiler/rustc_codegen_ssa/src/back/apple.rs:91 with the correct byte width and relocation encoding.

Example fix

// before (custom target spec data-layout with :16 pointer width)
"data-layout": "e-p:16:16-..."
// after
"data-layout": "e-p:64:64-..."
Defensive patterns

Strategy: validation

Validate before calling

fn apple_pointer_width_ok(target: &str) -> bool {
    let is_apple = target.contains("apple") || target.contains("darwin")
        || target.contains("macos") || target.contains("ios")
        || target.contains("tvos") || target.contains("watchos");
    let width = usize::BITS;
    !is_apple || width == 64 || width == 32
}

// caller: assert!(apple_pointer_width_ok(&target_triple));

Type guard

fn is_supported_apple_pointer_width(target: &str, width: u32) -> bool {
    let is_apple = target.contains("apple-darwin")
        || target.contains("apple-ios")
        || target.contains("apple-tvos")
        || target.contains("apple-watchos");
    !is_apple || matches!(width, 32 | 64)
}

Try / catch

// rustc panics here; catch via subprocess exit code, not Result.
let out = std::process::Command::new("rustc")
    .args(["--target", &target_triple, "crate.rs"])
    .output()?;
if !out.status.success()
    && String::from_utf8_lossy(&out.stderr).contains("unsupported Apple pointer width")
{
    return Err(BuildError::UnsupportedApplePointerWidth(target_triple));
}

Prevention

When it happens

Trigger: Reached when rustc builds a Mach-O object for an Apple target whose target.pointer_width is neither 32 nor 64 (e.g. a custom target spec setting data-layout pointer size to 16 or 128). The function is called from the Apple symbol-export/data-emission path during codegen object writing.

Common situations: Using a hand-crafted custom target JSON (-Z build-std / --target custom.json) for an Apple triple with an inconsistent data-layout. Experimental/architectural Apple targets not yet modeled by rustc_target. Forked rustc with a new Arch variant but no matching width arm.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/c992c6c66dd1d636.json. Report an issue: GitHub.