Skip to content

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

@wmmc88

Description

@wmmc88

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zfixed-x18Unstable option: -Zfixed-x18A-allocatorsArea: Custom and system allocatorsA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-windows-msvcToolchain: MSVC, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions