about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-05-11 14:22:05 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2021-05-11 14:22:23 +0200
commit7c40338ba13aa38c8ba4442f92d50155ad9f6ddd (patch)
treedd8dfb8c2d9ac48ecd5a222128cf6f3501bccc50
parent4663ed7bd9ae04dea5beb6d852a37837f00d4a23 (diff)
downloadrust-7c40338ba13aa38c8ba4442f92d50155ad9f6ddd.tar.gz
rust-7c40338ba13aa38c8ba4442f92d50155ad9f6ddd.zip
Implement imported_main feature
Fixes #1164
-rw-r--r--src/driver/aot.rs8
-rw-r--r--src/driver/jit.rs1
-rw-r--r--src/main_shim.rs9
3 files changed, 15 insertions, 3 deletions
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index 9c5cd53d866..99c15a26fe5 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -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;
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 526caeb4f03..fac48401a7e 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -45,6 +45,7 @@ fn create_jit_module<'tcx>(
         &mut jit_module,
         &mut cx.unwind_context,
         true,
+        true,
     );
 
     (jit_module, cx)
diff --git a/src/main_shim.rs b/src/main_shim.rs
index d504024a335..f231e791abd 100644
--- a/src/main_shim.rs
+++ b/src/main_shim.rs
@@ -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;
     }