|
1 | 1 | //! Allocator shim
|
2 | 2 | // Adapted from rustc
|
3 | 3 |
|
| 4 | +use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; |
4 | 5 | use rustc_ast::expand::allocator::{
|
5 | 6 | ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
|
6 | 7 | alloc_error_handler_name, default_fn_name, global_fn_name,
|
@@ -97,16 +98,31 @@ fn codegen_inner(
|
97 | 98 | data.define(Box::new([val]));
|
98 | 99 | module.define_data(data_id, &data).unwrap();
|
99 | 100 |
|
100 |
| - let data_id = module |
101 |
| - .declare_data( |
102 |
| - &mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE), |
103 |
| - Linkage::Export, |
104 |
| - false, |
105 |
| - false, |
106 |
| - ) |
107 |
| - .unwrap(); |
108 |
| - let mut data = DataDescription::new(); |
109 |
| - data.set_align(1); |
110 |
| - data.define(Box::new([0])); |
111 |
| - module.define_data(data_id, &data).unwrap(); |
| 101 | + { |
| 102 | + let sig = Signature { |
| 103 | + call_conv: module.target_config().default_call_conv, |
| 104 | + params: vec![], |
| 105 | + returns: vec![], |
| 106 | + }; |
| 107 | + let func_id = module |
| 108 | + .declare_function( |
| 109 | + &mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE), |
| 110 | + Linkage::Export, |
| 111 | + &sig, |
| 112 | + ) |
| 113 | + .unwrap(); |
| 114 | + |
| 115 | + let mut ctx = Context::new(); |
| 116 | + ctx.func.signature = sig; |
| 117 | + let mut func_ctx = FunctionBuilderContext::new(); |
| 118 | + let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx); |
| 119 | + |
| 120 | + let block = bcx.create_block(); |
| 121 | + bcx.switch_to_block(block); |
| 122 | + bcx.ins().return_(&[]); |
| 123 | + bcx.seal_all_blocks(); |
| 124 | + bcx.finalize(); |
| 125 | + |
| 126 | + module.define_function(func_id, &mut ctx).unwrap(); |
| 127 | + } |
112 | 128 | }
|
0 commit comments