rust-lang / rust-lang/rust

unresolved symbol `rdl_oom` when compiling `cdylib` crate with `no_global_oom_handling` on `pc-windows-msvc` target

Open
#138,758 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

-Zfixed-x18 A-allocators A-linkage C-bug O-windows-msvc requires-nightly T-compiler T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Full repro crate available here: https://github.com/wmmc88/minimal-repros/tree/no_global_oom_handling

I tried this code:

lib.rs

#![no_std]

extern crate alloc;

use core::alloc::{GlobalAlloc, Layout};

use alloc::{
    alloc::{alloc, dealloc},
    vec::Vec,
};

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

#[global_allocator]
static ALLOCATOR: Allocator = Allocator;

pub struct Allocator;
unsafe impl GlobalAlloc for Allocator {
    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
        unsafe { alloc(layout) }
    }

    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
        unsafe { dealloc(ptr, layout) };
    }
}

pub fn foo() {
    let _v = Vec::<u32>::new();
}

Cargo.toml

[package]
name = "no_global_oom_handling-test"
version = "0.1.0"
edition = "2024"

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

[dependencies]


[profile.dev]
panic = "abort"
# lto = "thin" # Requires at least thin lto or else error: error LNK2019: unresolved external symbol __rdl_oom referenced in function __rust_alloc_error_handler␍

[profile.release]
panic = "abort"
# lto = "thin" # Requires at least thin lto or else error: error LNK2019: unresolved external symbol __rdl_oom referenced in function __rust_alloc_error_handler␍

.cargo/config.toml

[build]
rustflags = [
  "--cfg",
  "no_global_oom_handling",
]

[unstable]
build-std = ["core", "alloc"]

I expected to see this happen: successful compilation

Instead, this happened:
On pc-windows-msvc target, this causes the following linker error:

error LNK2019: unresolved external symbol _RNvCs95KLPZDDxvS_7___rustc9___rdl_oom referenced in function _RNvCs95KLPZDDxvS_7___rustc26___rust_alloc_error_handler

Some important observations:

  • enabling lto = "thin" causes the linker error to disappear
  • this linker error does not happen when the crate is not a cdylib
  • both x86_64-pc-windows-msvc and aarch64-pc-windows-msvc cause this error
  • there is no error when compiling with x86_64-unknown-linux-gnu target
Meta

rustc --version --verbose:

rustc 1.87.0-nightly (1aeb99d24 2025-03-19)
binary: rustc
commit-hash: 1aeb99d248e1b0069110cb03c6f1dcc7b36fd7f3
commit-date: 2025-03-19
host: aarch64-pc-windows-msvc
release: 1.87.0-nightly
LLVM version: 20.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the linked minimal-repros crate, starting with lib.rs, Cargo.toml, and .cargo/config.toml. Reproduce the cdylib build on the x86_64-pc-windows-msvc or aarch64-pc-windows-msvc target with no_global_oom_handling, then compare builds with thin LTO, a non-cdylib crate, and the Linux target. Done means the affected Windows cdylib configuration links without the unresolved rdl_oom symbol.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.