gccrs#4557: Add lang item exchange_malloc
Link: Rust-GCC/gccrs#4557
#![allow(unused)]
fn main() {
#[lang = "exchange_malloc"]
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
match Global.alloc(layout) {
Ok(ptr) => ptr.as_mut_ptr(),
Err(_) => handle_alloc_error(layout),
}
}
}
Objective
This PR introduces the exchange_malloc lang item to the compiler.
Changes Made
We just need to produce it as a symbol. Then, when we look for it, we need to be able to find it.
Why is this needed for alloc?
This lang item is a strict prerequisite for the owned_box lang item and box expressions.
Test Case
#![allow(unused)]
fn main() {
#[lang = "exchange_malloc"]
unsafe fn _allocate(_size: usize, _align: usize) -> *mut u8 {
0 as *mut u8
}
}