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

  1. Read the logged llc stderr for the exact diagnostic (unknown CPU, bad feature, unsupported intrinsic).
  2. Use the llc matching rustc's LLVM (rustup component llvm-tools), not a distro llc.
  3. Validate the cpu/feature strings against `llc --mcpu=help` / `--mattr=help` for the target triple.
  4. 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

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


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/f0f94e1eff0f63fb. Report an issue: GitHub.