Skip to content

Commit

Permalink
Implement imported_main feature
Browse files Browse the repository at this point in the history
Fixes #1164
  • Loading branch information
bjorn3 committed May 11, 2021
1 parent 4663ed7 commit 7c40338
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn create_jit_module<'tcx>(
&mut jit_module,
&mut cx.unwind_context,
true,
true,
);

(jit_module, cx)
Expand Down
9 changes: 7 additions & 2 deletions src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => (
Expand All @@ -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;
}

Expand Down

0 comments on commit 7c40338

Please sign in to comment.