Skip to content

Commit

Permalink
Mark imports of #[rustc_std_internal_symbol] items with this attribute
Browse files Browse the repository at this point in the history
This ensures that they will be correctly mangled in a future commit.
  • Loading branch information
bjorn3 committed Nov 3, 2024
1 parent 7471e1c commit 386c90c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ mod tests;

extern "Rust" {
// These are the magic symbols to call the global allocator. rustc generates
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
// them to call the global allocator if there is a `#[global_allocator]` attribute
// (the code expanding that attribute macro generates those functions), or to call
// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
// otherwise.
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
// like `malloc`, `realloc`, and `free`, respectively.
#[rustc_allocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
#[rustc_deallocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
#[rustc_reallocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
#[rustc_allocator_zeroed]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;

#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
static __rust_no_alloc_shim_is_unstable: u8;
}

Expand Down Expand Up @@ -359,6 +362,7 @@ extern "Rust" {
// This is the magic symbol to call the global alloc error handler. rustc generates
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
// default implementations below (`__rdl_oom`) otherwise.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

Expand Down Expand Up @@ -429,6 +433,7 @@ pub mod __alloc_error_handler {
extern "Rust" {
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
// Its value depends on the -Zoom={panic,abort} compiler option.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
static __rust_alloc_error_handler_should_panic: u8;
}

Expand Down
2 changes: 2 additions & 0 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ cfg_if::cfg_if! {
extern "C" {
/// Handler in std called when a panic object is dropped outside of
/// `catch_unwind`.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_drop_panic() -> !;

/// Handler in std called when a foreign exception is caught.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_foreign_exception() -> !;
}

Expand Down
1 change: 1 addition & 0 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ fn default_alloc_error_hook(layout: Layout) {
extern "Rust" {
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
// Its value depends on the -Zoom={panic,abort} compiler option.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
static __rust_alloc_error_handler_should_panic: u8;
}

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ use crate::{fmt, intrinsics, process, thread};
// hook up these functions, but it is not this day!
#[allow(improper_ctypes)]
extern "C" {
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
}

extern "Rust" {
/// `PanicPayload` lazily performs allocation only when needed (this avoids
/// allocations when using the "abort" panic runtime).
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32;
}

Expand Down

0 comments on commit 386c90c

Please sign in to comment.