{"id":"c992c6c66dd1d636","repo":"rust-lang/rust","slug":"unsupported-apple-pointer-width-pointer-width","errorCode":null,"errorMessage":"unsupported Apple pointer width {pointer_width:?}","messagePattern":"unsupported Apple pointer width (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_ssa/src/back/apple.rs","lineNumber":95,"sourceCode":"/// ```console\n/// objdump --macho --reloc foo.o\n/// objdump --macho --full-contents foo.o\n/// ```\npub(super) fn add_data_and_relocation(\n    file: &mut object::write::Object<'_>,\n    section: object::write::SectionId,\n    symbol: object::write::SymbolId,\n    target: &Target,\n    kind: SymbolExportKind,\n) -> object::write::Result<()> {\n    let authenticated_pointer =\n        kind == SymbolExportKind::Text && target.llvm_target.starts_with(\"arm64e\");\n\n    let data: &[u8] = match target.pointer_width {\n        _ if authenticated_pointer => &[0, 0, 0, 0, 0, 0, 0, 0x80],\n        32 => &[0; 4],\n        64 => &[0; 8],\n        pointer_width => unimplemented!(\"unsupported Apple pointer width {pointer_width:?}\"),\n    };\n\n    if target.arch == Arch::X86_64 {\n        // Force alignment for the entire section to be 16 on x86_64.\n        file.section_mut(section).append_data(&[], 16);\n    } else {\n        // Elsewhere, the section alignment is the same as the pointer width.\n        file.section_mut(section).append_data(&[], target.pointer_width as u64);\n    }\n\n    let offset = file.section_mut(section).append_data(data, data.len() as u64);\n\n    let flags = if authenticated_pointer {\n        object::write::RelocationFlags::MachO {\n            r_type: object::macho::ARM64_RELOC_AUTHENTICATED_POINTER,\n            r_pcrel: false,\n            r_length: 3,\n        }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_ssa/src/back/apple.rs#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a stock Apple target triple (aarch64-apple-darwin, x86_64-apple-darwin, aarch64-apple-ios, etc.) instead of a custom spec.","If you must use a custom target spec, ensure its data-layout pointer width is exactly ':32' or ':64'.","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."],"exampleFix":"// before (custom target spec data-layout with :16 pointer width)\n\"data-layout\": \"e-p:16:16-...\"\n// after\n\"data-layout\": \"e-p:64:64-...\"","handlingStrategy":"validation","validationCode":"fn apple_pointer_width_ok(target: &str) -> bool {\n    let is_apple = target.contains(\"apple\") || target.contains(\"darwin\")\n        || target.contains(\"macos\") || target.contains(\"ios\")\n        || target.contains(\"tvos\") || target.contains(\"watchos\");\n    let width = usize::BITS;\n    !is_apple || width == 64 || width == 32\n}\n\n// caller: assert!(apple_pointer_width_ok(&target_triple));","typeGuard":"fn is_supported_apple_pointer_width(target: &str, width: u32) -> bool {\n    let is_apple = target.contains(\"apple-darwin\")\n        || target.contains(\"apple-ios\")\n        || target.contains(\"apple-tvos\")\n        || target.contains(\"apple-watchos\");\n    !is_apple || matches!(width, 32 | 64)\n}","tryCatchPattern":"// rustc panics here; catch via subprocess exit code, not Result.\nlet out = std::process::Command::new(\"rustc\")\n    .args([\"--target\", &target_triple, \"crate.rs\"])\n    .output()?;\nif !out.status.success()\n    && String::from_utf8_lossy(&out.stderr).contains(\"unsupported Apple pointer width\")\n{\n    return Err(BuildError::UnsupportedApplePointerWidth(target_triple));\n}","preventionTips":["Pin to 64-bit (or 32-bit) Apple targets; never assume 16/128-bit Apple variants exist.","Confirm the target triple with `rustc --print target-list | grep apple` before building.","When cross-compiling, validate that the LLVM target's pointer width matches the data layout you expect."],"tags":["apple","mach-o","codegen","target-spec","relocation"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}