rust-lang/rust · critical
Can't get the layout of `i128`
Error message
Can't get the layout of `i128`
What it means
During `CodegenCx` construction (context.rs:236-241) the backend computes `int128_align` by calling `tcx.layout_of(...i128...).expect("Can't get the layout of \`i128\`")`. If the target's layout for `i128` cannot be computed, the `expect` panics and the entire codegen context fails to initialize. This typically means the target's data layout / target specification does not admit a 128-bit integer type or is malformed, so rustc's layout query returns `Err`.
Source
Thrown at compiler/rustc_codegen_gcc/src/context.rs:239
let longlong_type = context.new_c_type(CType::LongLong);
let ulonglong_type = context.new_c_type(CType::ULongLong);
let sizet_type = context.new_c_type(CType::SizeT);
let usize_type = sizet_type;
let isize_type = usize_type;
let bool_type = context.new_type::<bool>();
let mut functions = FxHashMap::default();
let builtins = ["abort"];
for builtin in builtins.iter() {
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));
}
let mut cx = Self {
int128_align: tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))
.expect("Can't get the layout of `i128`")
.align
.abi,
const_cache: Default::default(),
codegen_unit,
context,
current_func: RefCell::new(None),
normal_function_addresses: Default::default(),
function_address_names: Default::default(),
functions: RefCell::new(functions),
intrinsics: RefCell::new(FxHashMap::default()),
tls_model,
bool_type,
i8_type,
i16_type,
i32_type,
i64_type,View on GitHub (pinned to 22057b88b0)
Solutions
- Verify the target triple is one this backend supports; switch to a mainstream triple (x86_64, aarch64) to confirm the issue is target-specific.
- Inspect/fix the custom target spec's `data-layout` field to ensure it defines a valid 128-bit integer alignment.
- If the target genuinely has no i128, patch context.rs:239 to fall back to a default alignment (e.g. 8 or 16 bytes) instead of `expect`, mirroring how the LLVM backend tolerates such targets.
- Confirm you are not accidentally compiling for the host while a `--target` override points at an unsupported spec.
Example fix
// before (context.rs:237-241)
int128_align: tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))
.expect("Can't get the layout of `i128`")
.align
.abi,
// after (tolerate targets without i128 layout)
int128_align: tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))
.map(|l| l.align.abi)
.unwrap_or_else(|_| tcx.data_layout().aggregate_align.abi), Defensive patterns
Strategy: validation
Validate before calling
// context.rs:239 -> layout_of(i128).expect("Can't get the layout of `i128`")
// at CodegenCx construction. Fires for targets whose spec lacks a valid
// 128-bit integer layout. Probe before constructing the context:
use rustc_middle::ty;
let layout = tcx.layout_of(
ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128),
);
if layout.is_err() {
return Err("target has no valid i128 layout; cannot use gcc backend");
} Prevention
- This fires at CodegenCx construction, not on user input - it means the target spec lacks a valid 128-bit integer layout.
- Use a target spec whose data layout includes i128 (most native targets do); avoid exotic or bare-metal targets missing it.
- If you must target such a platform, fall back to the LLVM backend or patch the spec's data layout.
When it happens
Trigger: Constructing a `CodegenCx` for a target triple whose data layout lacks an i128 representation (or has a malformed spec) — `tcx.layout_of(TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))` returns `Err` and the `expect` at context.rs:239 panics. Also reachable if the target spec is a hand-written custom target missing i128 support.
Common situations: Custom/exotic target specs (e.g. embedded, unusual architectures, MSP430-class targets without 128-bit integers); a corrupted or in-progress target-spec file; pointing rustc_codegen_gcc at a target it was not built to support. The i128 alignment is needed unconditionally at cx init, so any unsupported target aborts immediately.
Related errors
- func
- struct type
- `static_addr_of_mut` did not add the global to `self.global_
- const_alloc_to_gcc_uncached: could not read relocation point
- element type
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/cf69685f3b6e483e.json.
Report an issue: GitHub.