Skip to content

Commit 7c40338

Browse files
committed
Implement imported_main feature
Fixes #1164
1 parent 4663ed7 commit 7c40338

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/driver/aot.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ fn module_codegen(
134134
}
135135
}
136136
}
137-
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut cx.unwind_context, false);
137+
crate::main_shim::maybe_create_entry_wrapper(
138+
tcx,
139+
&mut module,
140+
&mut cx.unwind_context,
141+
false,
142+
cgu.is_primary(),
143+
);
138144

139145
let debug_context = cx.debug_context;
140146
let unwind_context = cx.unwind_context;

src/driver/jit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn create_jit_module<'tcx>(
4545
&mut jit_module,
4646
&mut cx.unwind_context,
4747
true,
48+
true,
4849
);
4950

5051
(jit_module, cx)

src/main_shim.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) fn maybe_create_entry_wrapper(
1414
module: &mut impl Module,
1515
unwind_context: &mut UnwindContext,
1616
is_jit: bool,
17+
is_primary_cgu: bool,
1718
) {
1819
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
1920
Some((def_id, entry_ty)) => (
@@ -26,8 +27,12 @@ pub(crate) fn maybe_create_entry_wrapper(
2627
None => return,
2728
};
2829

29-
let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx);
30-
if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() {
30+
if main_def_id.is_local() {
31+
let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx);
32+
if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() {
33+
return;
34+
}
35+
} else if !is_primary_cgu {
3136
return;
3237
}
3338

0 commit comments

Comments
 (0)