|
1 | 1 | use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
|
2 | 2 | use rustc_hir::LangItem;
|
| 3 | +use rustc_middle::ty::subst::GenericArg; |
| 4 | +use rustc_middle::ty::AssocKind; |
3 | 5 | use rustc_session::config::EntryFnType;
|
| 6 | +use rustc_span::symbol::Ident; |
4 | 7 |
|
5 | 8 | use crate::prelude::*;
|
6 | 9 |
|
@@ -79,8 +82,38 @@ pub(crate) fn maybe_create_entry_wrapper(
|
79 | 82 | let result = if is_main_fn && ignore_lang_start_wrapper {
|
80 | 83 | // regular main fn, but ignoring #[lang = "start"] as we are running in the jit
|
81 | 84 | // FIXME set program arguments somehow
|
82 |
| - bcx.ins().call(main_func_ref, &[]); |
83 |
| - bcx.ins().iconst(m.target_config().pointer_type(), 0) |
| 85 | + let call_inst = bcx.ins().call(main_func_ref, &[]); |
| 86 | + let call_results = bcx.func.dfg.inst_results(call_inst).to_owned(); |
| 87 | + |
| 88 | + let termination_trait = tcx.require_lang_item(LangItem::Termination, None); |
| 89 | + let report = tcx |
| 90 | + .associated_items(termination_trait) |
| 91 | + .find_by_name_and_kind( |
| 92 | + tcx, |
| 93 | + Ident::from_str("report"), |
| 94 | + AssocKind::Fn, |
| 95 | + termination_trait, |
| 96 | + ) |
| 97 | + .unwrap(); |
| 98 | + let report = Instance::resolve( |
| 99 | + tcx, |
| 100 | + ParamEnv::reveal_all(), |
| 101 | + report.def_id, |
| 102 | + tcx.mk_substs([GenericArg::from(main_ret_ty)].iter()), |
| 103 | + ) |
| 104 | + .unwrap() |
| 105 | + .unwrap(); |
| 106 | + |
| 107 | + let report_name = tcx.symbol_name(report).name; |
| 108 | + let report_sig = get_function_sig(tcx, m.isa().triple(), report); |
| 109 | + let report_func_id = |
| 110 | + m.declare_function(report_name, Linkage::Import, &report_sig).unwrap(); |
| 111 | + let report_func_ref = m.declare_func_in_func(report_func_id, &mut bcx.func); |
| 112 | + |
| 113 | + // FIXME do proper abi handling instead of expecting the pass mode to be identical |
| 114 | + // for returns and arguments. |
| 115 | + let report_call_inst = bcx.ins().call(report_func_ref, &call_results); |
| 116 | + bcx.func.dfg.inst_results(report_call_inst)[0] |
84 | 117 | } else if is_main_fn {
|
85 | 118 | let start_def_id = tcx.require_lang_item(LangItem::Start, None);
|
86 | 119 | let start_instance = Instance::resolve(
|
|
0 commit comments