Implement imported_main feature

Fixes #1164
This commit is contained in:
bjorn3 2021-05-11 14:22:05 +02:00
parent 4663ed7bd9
commit 7c40338ba1
3 changed files with 15 additions and 3 deletions

View File

@ -134,7 +134,13 @@ fn module_codegen(
}
}
}
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut cx.unwind_context, false);
crate::main_shim::maybe_create_entry_wrapper(
tcx,
&mut module,
&mut cx.unwind_context,
false,
cgu.is_primary(),
);
let debug_context = cx.debug_context;
let unwind_context = cx.unwind_context;

View File

@ -45,6 +45,7 @@ fn create_jit_module<'tcx>(
&mut jit_module,
&mut cx.unwind_context,
true,
true,
);
(jit_module, cx)

View File

@ -14,6 +14,7 @@ pub(crate) fn maybe_create_entry_wrapper(
module: &mut impl Module,
unwind_context: &mut UnwindContext,
is_jit: bool,
is_primary_cgu: bool,
) {
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
Some((def_id, entry_ty)) => (
@ -26,8 +27,12 @@ pub(crate) fn maybe_create_entry_wrapper(
None => return,
};
let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx);
if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() {
if main_def_id.is_local() {
let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx);
if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() {
return;
}
} else if !is_primary_cgu {
return;
}