Skip to content

default_alloc_error_handler requires the linker to omit __rg_oom from liballoc #95113

Closed
@bjorn3

Description

__rg_oom calls the rust_oom symbol (aka the "oom" weak lang item). This symbol is not defined when using default_alloc_error_handler.

// if there is an `#[alloc_error_handler]`
#[rustc_std_internal_symbol]
pub unsafe extern "C-unwind" fn __rg_oom(size: usize, align: usize) -> ! {
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
extern "Rust" {
#[lang = "oom"]
fn oom_impl(layout: Layout) -> !;
}
unsafe { oom_impl(layout) }
}

This causes https://github.com/rust-lang/rust/blob/31535841701e0bf7ef33998024376f2cedd8b3e3/src/test/ui/allocator/no_std-alloc-error-handler-default.rs to fail with cg_clif as it uses -Zfunction-sections=no by default. I suspect it would also cause it to fail for windows as windows has this default too.

Applying the approach of #86844 to the alloc error handler too should trivially fix this. This PR is still pending decision if it should be done or not.

Metadata

Assignees

No one assigned

    Labels

    A-craneliftThings relevant to the [future] cranelift backendC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions