Skip to content

[BUG]: #[device] extern fn leaves an undefined symbol in a cdylib #1800

Open

Description

@physwkim

Description

A cdylib whose kernel calls a #[device] unsafe extern "C" fn cannot be loaded. The cdylib exports the #[no_mangle] host copy of every #[kernel] and #[device] fn, so that copy's call to the device-only symbol stays undefined in the host library. An executable links because the linker drops the unexported host copies.

Error / actual behavior

OSError: .../libdevext_cdylib_repro.so: undefined symbol: scale

nm -D shows U scale, referenced by the exported T cuda_oxide_codegen_v1_cuda_oxide_kernel_246e25db_apply_scale.

Expected behavior

The library loads; scale exists only in the device link.

Minimal reproduction example

// src/lib.rs
use cuda_device::{device, kernel};

#[device]
unsafe extern "C" {
    // Defined only in external LTOIR linked at device link time.
    fn scale(x: f32) -> f32;
}

#[kernel]
pub fn apply_scale(out: *mut f32) {
    unsafe { *out = scale(*out) };
}
# Cargo.toml
[package]
name = "devext_cdylib_repro"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
cuda-device = { path = "<cuda-rust>/cuda-oxide/crates/cuda-device" }

[workspace]
RUSTC_BOOTSTRAP=1 cargo build
python3 -c "import ctypes; ctypes.CDLL('target/debug/libdevext_cdylib_repro.so')"

Operating System

Ubuntu 24.04.5 LTS

GPU and GPU Architecture

NVIDIA RTX 5000 Ada Generation (sm_89); the repro needs no GPU

CUDA driver version

620.70.06

rustc version

rustc 1.99.1 (58cf8f9c3 2026-10-13), cuda-rust main 367bc0f

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions