about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2021-10-06 15:52:54 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2022-03-03 12:58:38 +0000
commitaa36237e1604de6a2a6275f5580c9d680d627c2f (patch)
tree671997417164221e78218c622b99b81f2f84de23 /compiler/rustc_codegen_llvm/src
parent1204400ab8da9830f6f77a5e40e7ad3ea459676a (diff)
downloadrust-aa36237e1604de6a2a6275f5580c9d680d627c2f.tar.gz
rust-aa36237e1604de6a2a6275f5580c9d680d627c2f.zip
Add -Z oom={panic,abort} command-line option
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/allocator.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs
index 7680d4fd233..b2c07408800 100644
--- a/compiler/rustc_codegen_llvm/src/allocator.rs
+++ b/compiler/rustc_codegen_llvm/src/allocator.rs
@@ -3,7 +3,7 @@ use libc::c_uint;
 use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
 use rustc_middle::bug;
 use rustc_middle::ty::TyCtxt;
-use rustc_session::config::DebugInfo;
+use rustc_session::config::{DebugInfo, OomStrategy};
 use rustc_span::symbol::sym;
 
 use crate::debuginfo;
@@ -136,6 +136,16 @@ pub(crate) unsafe fn codegen(
     llvm::LLVMBuildRetVoid(llbuilder);
     llvm::LLVMDisposeBuilder(llbuilder);
 
+    // __rust_alloc_error_handler_should_panic
+    let name = OomStrategy::SYMBOL;
+    let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
+    if tcx.sess.target.default_hidden_visibility {
+        llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
+    }
+    let val = tcx.sess.opts.debugging_opts.oom.should_panic();
+    let llval = llvm::LLVMConstInt(i8, val as u64, False);
+    llvm::LLVMSetInitializer(ll_g, llval);
+
     if tcx.sess.opts.debuginfo != DebugInfo::None {
         let dbg_cx = debuginfo::CrateDebugContext::new(llmod);
         debuginfo::metadata::compile_unit_metadata(tcx, module_name, &dbg_cx);