rust-lang/rust · error · anyhow::Error
llc failed to compile {} into {}
Error message
llc failed to compile {} into {} What it means
Bailed by Session::compile when the llc subprocess returns non-zero while translating the optimized bitcode to native object code. llc had the target CPU/features and the optimized .o as input; failure means it could not emit the requested object file.
Source
Thrown at src/tools/llvm-bitcode-linker/src/linker.rs:156
if let Some(mattr) = &self.feature {
lcc_command.arg(&format!("--mattr={}", mattr));
}
let lcc_output = lcc_command
.arg(&self.opt_path)
.arg("-o").arg(&self.out_path)
.output()
.context("An error occurred when calling llc. Make sure the llvm-tools component is installed.")?;
if !lcc_output.status.success() {
tracing::error!(
"llc returned with Exit status: {}\n stdout: {}\n stderr: {}",
lcc_output.status,
String::from_utf8(lcc_output.stdout).unwrap(),
String::from_utf8(lcc_output.stderr).unwrap(),
);
anyhow::bail!(
"llc failed to compile {} into {}",
self.opt_path.display(),
self.out_path.display()
);
}
Ok(())
}
/// Links, optimizes and compiles to the native format
pub fn lto(&mut self, optimization: crate::Optimization, debug: bool) -> anyhow::Result<()> {
self.link()?;
self.optimize(optimization, debug)?;
self.compile()
}
}
View on GitHub (pinned to 7088e4b63a)
Solutions
- Read the logged llc stderr for the exact diagnostic (unknown CPU, bad feature, unsupported intrinsic).
- Use the llc matching rustc's LLVM (rustup component llvm-tools), not a distro llc.
- Validate the cpu/feature strings against `llc --mcpu=help` / `--mattr=help` for the target triple.
- Re-run optimize() to regenerate opt_path if the input bitcode is suspect.
Example fix
// before
anyhow::bail!("llc failed to compile {} into {}",
self.opt_path.display(), self.out_path.display());
// after: embed llc stderr
let stderr = String::from_utf8_lossy(&lcc_output.stderr);
anyhow::bail!(
"llc failed to compile {} into {}: {}",
self.opt_path.display(), self.out_path.display(),
stderr.trim()
); Defensive patterns
Strategy: validation
Validate before calling
// Validate CPU/feature strings against llc's catalog for the target:
fn cpu_supported(llc: &str, cpu: &str, target: &str) -> bool {
let o = std::process::Command::new(llc)
.arg(format!("--mtriple={target}")).arg("--mcpu=help").output();
matches!(o, Ok(out) if String::from_utf8_lossy(&out.stdout).contains(cpu))
} Type guard
null
Try / catch
match session.lto(opt, debug) {
Ok(()) => Ok(()),
Err(e) if e.to_string().contains("llc failed") => {
eprintln!("llc rejected CPU/feature or bitcode; re-check target triple");
Err(e)
}
Err(e) => Err(e),
} Prevention
- Cross-check --mcpu/--mattr with `llc --mcpu=help` for the target.
- Keep llc on PATH version-matched to rustc's bundled LLVM.
- Cross-compile in a clean env so a system llc is never accidentally picked up.
When it happens
Trigger: Reached after optimize() succeeds, when llc fails. Causes: an llc from a mismatched LLVM version; an --mcpu/--mattr value the target doesn't recognize; the optimized bitcode referencing intrinsics llc can't lower.
Common situations: Cross-compiling with a CPU/feature string (e.g. --mcpu=native on a foreign target) llc rejects; system llc vs bundled LLVM mismatch; corrupted opt_path from a partial optimize step.
Related errors
- llvm-link failed to link files {:?}
- opt failed optimize bitcode: {}
- llvm-readelf failed for binary {binary} with output {stdout}
- Build ID not found for binary {binary}
- unexpected base kind for gap region: {kind:?}
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/f0f94e1eff0f63fb.
Report an issue: GitHub.