Skip to content

Commit 6afa440

Browse files
authored
Rollup merge of rust-lang#147526 - bjorn3:alloc_shim_weak_shape, r=petrochenkov,RalfJung
Move computation of allocator shim contents to cg_ssa In the future this should make it easier to use weak symbols for the allocator shim on platforms that properly support weak symbols. And it would allow reusing the allocator shim code for handling default implementations of the upcoming externally implementable items feature on platforms that don't properly support weak symbols. In addition to make this possible, the alloc error handler is now handled in a way such that it is possible to avoid using the allocator shim when liballoc is compiled without `no_global_oom_handling` if you use `#[alloc_error_handler]`. Previously this was only possible if you avoided liballoc entirely or compiled it with `no_global_oom_handling`. You still need to avoid libstd and to define the symbol that indicates that avoiding the allocator shim is unstable.
2 parents 3620856 + 4d10ff3 commit 6afa440

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
361361
unsafe extern "Rust" {
362362
// This is the magic symbol to call the global alloc error handler. rustc generates
363363
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
364-
// default implementations below (`__rdl_oom`) otherwise.
364+
// default implementations below (`__rdl_alloc_error_handler`) otherwise.
365365
#[rustc_std_internal_symbol]
366366
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
367367
}
@@ -425,7 +425,7 @@ pub mod __alloc_error_handler {
425425
// called via generated `__rust_alloc_error_handler` if there is no
426426
// `#[alloc_error_handler]`.
427427
#[rustc_std_internal_symbol]
428-
pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! {
428+
pub unsafe fn __rdl_alloc_error_handler(size: usize, _align: usize) -> ! {
429429
unsafe extern "Rust" {
430430
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
431431
// Its value depends on the -Zoom={panic,abort} compiler option.

std/src/alloc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,10 @@ fn default_alloc_error_hook(layout: Layout) {
358358
// This is the default path taken on OOM, and the only path taken on stable with std.
359359
// Crucially, it does *not* call any user-defined code, and therefore users do not have to
360360
// worry about allocation failure causing reentrancy issues. That makes it different from
361-
// the default `__rdl_oom` defined in alloc (i.e., the default alloc error handler that is
362-
// called when there is no `#[alloc_error_handler]`), which triggers a regular panic and
363-
// thus can invoke a user-defined panic hook, executing arbitrary user-defined code.
361+
// the default `__rdl_alloc_error_handler` defined in alloc (i.e., the default alloc error
362+
// handler that is called when there is no `#[alloc_error_handler]`), which triggers a
363+
// regular panic and thus can invoke a user-defined panic hook, executing arbitrary
364+
// user-defined code.
364365
rtprintpanic!("memory allocation of {} bytes failed\n", layout.size());
365366
}
366367
}

0 commit comments

Comments
 (0)