diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2021-10-06 15:52:54 +0100 | 
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2022-03-03 12:58:38 +0000 | 
| commit | aa36237e1604de6a2a6275f5580c9d680d627c2f (patch) | |
| tree | 671997417164221e78218c622b99b81f2f84de23 /library/std/src/alloc.rs | |
| parent | 1204400ab8da9830f6f77a5e40e7ad3ea459676a (diff) | |
| download | rust-aa36237e1604de6a2a6275f5580c9d680d627c2f.tar.gz rust-aa36237e1604de6a2a6275f5580c9d680d627c2f.zip | |
Add -Z oom={panic,abort} command-line option
Diffstat (limited to 'library/std/src/alloc.rs')
| -rw-r--r-- | library/std/src/alloc.rs | 16 | 
1 files changed, 15 insertions, 1 deletions
| diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 8ee55234cea..86899d05b8a 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -315,7 +315,21 @@ pub fn take_alloc_error_hook() -> fn(Layout) { } fn default_alloc_error_hook(layout: Layout) { - rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); + #[cfg(not(bootstrap))] + extern "Rust" { + // This symbol is emitted by rustc next to __rust_alloc_error_handler. + // Its value depends on the -Zoom={panic,abort} compiler option. + static __rust_alloc_error_handler_should_panic: u8; + } + #[cfg(bootstrap)] + let __rust_alloc_error_handler_should_panic = 0; + + #[allow(unused_unsafe)] + if unsafe { __rust_alloc_error_handler_should_panic != 0 } { + panic!("memory allocation of {} bytes failed\n", layout.size()); + } else { + rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); + } } #[cfg(not(test))] | 
