rust-lang/rust · error

not implemented

Error message

not implemented

What it means

Thrown by rustc_codegen_gcc (the libgccjit backend) when mapping a Rust linkage kind to a libgccjit FunctionType. The linkage_to_gcc() match handles External, AvailableExternally, WeakAny, Internal, but panics with unimplemented!() for LinkOnceAny, LinkOnceODR, WeakODR, ExternalWeak, and Common. The specific line (base.rs:69) is Linkage::Common => unimplemented!(), meaning a function/static with common/tentative linkage cannot be lowered to GCC. Common linkage corresponds to C-style tentative definitions and COMDAT-like globals.

Source

Thrown at compiler/rustc_codegen_gcc/src/base.rs:69

        Linkage::WeakODR => unimplemented!(),
        Linkage::Internal => GlobalKind::Internal,
        Linkage::ExternalWeak => GlobalKind::Imported, // FIXME(antoyo): should be weak linkage.
        Linkage::Common => unimplemented!(),
    }
}

pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType {
    match linkage {
        Linkage::External => FunctionType::Exported,
        // FIXME(antoyo): set the attribute externally_visible.
        Linkage::AvailableExternally => FunctionType::Extern,
        Linkage::LinkOnceAny => unimplemented!(),
        Linkage::LinkOnceODR => unimplemented!(),
        Linkage::WeakAny => FunctionType::Exported, // FIXME(antoyo): should be similar to linkonce.
        Linkage::WeakODR => unimplemented!(),
        Linkage::Internal => FunctionType::Internal,
        Linkage::ExternalWeak => unimplemented!(),
        Linkage::Common => unimplemented!(),
    }
}

pub fn compile_codegen_unit(
    tcx: TyCtxt<'_>,
    cgu_name: Symbol,
    target_info: LockedTargetInfo,
    lto_supported: bool,
) -> (ModuleCodegen<GccContext>, u64) {
    let prof_timer = tcx.prof.generic_activity("codegen_module");
    let start_time = Instant::now();

    let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
    let (module, _) = tcx.dep_graph.with_task(
        dep_node,
        tcx,
        || module_codegen(tcx, cgu_name, target_info, lto_supported),
        Some(dep_graph::hash_result),

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Switch the codegen backend to LLVM for this crate (remove -Ccodegen-backend=gcc / RUSTC_CODEGEN_BACKEND=gcc).
  2. Remove or replace the #[linkage = "..."] / tentative-definition attribute causing Common linkage.
  3. Disable LTO (-Clto=no) if the Common linkage appears only during LTO symbol merging.
  4. Implement the Common (and related LinkOnce*/WeakODR/ExternalWeak) arms in linkage_to_gcc() by mapping to the closest libgccjit FunctionType / GlobalKind and submit upstream.

Example fix

// before
#[linkage = "external"]
static FOO: u32 = 0; // or a tentative-definition pattern producing Common

// after - plain internal static, no special linkage
static FOO: u32 = 0;
Defensive patterns

Strategy: fallback

Validate before calling

// cg_gcc emits a generic 'not implemented' from base.rs. Pre-flight by
// building a tiny probe crate and checking the codegen works before
// committing to cg_gcc for the whole workspace.
let status = std::process::Command::new("cargo")
    .args(["build", "--lib", "--", "-Zcodegen-backend=gcc"])
    .current_dir("probe/").status()?;
if !status.success() { eprintln!("cg_gcc unsupported feature hit; use LLVM."); }

Try / catch

// Unreachable at runtime — the panic is in rustc_codegen_gcc's base layer
// and aborts compilation. Wrap the *cargo invocation* in CI and fall back:
let s = std::process::Command::new("cargo").args(["build"]).status();
if !s.map(|s| s.success()).unwrap_or(false) {
    std::process::Command::new("cargo").args(["build"]).status()?; // LLVM fallback
}

Prevention

When it happens

Trigger: Compiling a function or static whose Linkage resolves to Common while using the gccjit backend (-Ccodegen-backend=gcc). This arises from items annotated with #[linkage = "..."], certain COMDAT/section attributes, weak symbols from FFI, or compiler-generated common symbols during LTO/codegen-unit partitioning. Several other linkage variants (LinkOnce*, WeakODR, ExternalWeak) in the same function panic identically.

Common situations: Using the gccjit backend (rustc_codegen_gcc / gcc-codegen) with crates that rely on weak or tentative linkage - common in C-FFI bindings, dynamic-plugin systems, or kernel/embedded code with #[linkage]. Also hits with -C lto configurations that merge symbols into COMDAT-like groups the GCC backend never implemented.

Related errors


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