From 075983c70ba20f31fc1279dacae6d6fcb8bc9cad Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 12 Nov 2018 09:00:39 +0100 Subject: [PATCH] global allocators: add a few comments --- src/liballoc/alloc.rs | 4 ++++ src/libstd/alloc.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 3bd0c243b39ac..1a8a081e16fad 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -21,6 +21,10 @@ use core::usize; pub use core::alloc::*; extern "Rust" { + // These are the magic symbols to call the global allocator. rustc generates + // them from the `#[global_allocator]` attribute if there is one, or uses the + // default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`) + // otherwise. #[allocator] #[rustc_allocator_nounwind] fn __rust_alloc(size: usize, align: usize) -> *mut u8; diff --git a/src/libstd/alloc.rs b/src/libstd/alloc.rs index 485b2ffe1975e..9c0573964702e 100644 --- a/src/libstd/alloc.rs +++ b/src/libstd/alloc.rs @@ -142,6 +142,7 @@ pub use alloc_crate::alloc::*; #[derive(Debug, Copy, Clone)] pub struct System; +// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`. #[unstable(feature = "allocator_api", issue = "32838")] unsafe impl Alloc for System { #[inline] @@ -226,6 +227,10 @@ pub fn rust_oom(layout: Layout) -> ! { #[unstable(feature = "alloc_internals", issue = "0")] pub mod __default_lib_allocator { use super::{System, Layout, GlobalAlloc}; + // These magic symbol names are used as a fallback for implementing the + // `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs) when there is + // no `#[global_allocator]` attribute. + // for symbol names src/librustc/middle/allocator.rs // for signatures src/librustc_allocator/lib.rs