@@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
1515use rustc_data_structures:: profiling:: { get_resident_set_size, print_time_passes_entry} ;
1616use rustc_data_structures:: sync:: { par_iter, ParallelIterator } ;
1717use rustc_hir as hir;
18- use rustc_hir:: def_id:: { LocalDefId , LOCAL_CRATE } ;
18+ use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
1919use rustc_hir:: lang_items:: LangItem ;
2020use rustc_index:: vec:: Idx ;
2121use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
@@ -348,12 +348,29 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
348348 cx : & ' a Bx :: CodegenCx ,
349349) -> Option < Bx :: Function > {
350350 let main_def_id = cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) . map ( |( def_id, _) | def_id) ?;
351- let instance = Instance :: mono ( cx. tcx ( ) , main_def_id. to_def_id ( ) ) ;
351+ let main_is_local = main_def_id. is_local ( ) ;
352+ let instance = Instance :: mono ( cx. tcx ( ) , main_def_id) ;
352353
353- if !cx . codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance ) ) {
354+ if main_is_local {
354355 // We want to create the wrapper in the same codegen unit as Rust's main
355356 // function.
356- return None ;
357+ if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
358+ return None ;
359+ }
360+ } else {
361+ // FIXME: Add support for non-local main fn codegen
362+ let span = cx. tcx ( ) . main_def . unwrap ( ) . span ;
363+ let n = 28937 ;
364+ cx. sess ( )
365+ . struct_span_err ( span, "entry symbol `main` from foreign crate is not yet supported." )
366+ . note ( & format ! (
367+ "see issue #{} <https://github.com/rust-lang/rust/issues/{}> \
368+ for more information",
369+ n, n,
370+ ) )
371+ . emit ( ) ;
372+ cx. sess ( ) . abort_if_errors ( ) ;
373+ bug ! ( ) ;
357374 }
358375
359376 let main_llfn = cx. get_fn_addr ( instance) ;
@@ -366,7 +383,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
366383 fn create_entry_fn < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
367384 cx : & ' a Bx :: CodegenCx ,
368385 rust_main : Bx :: Value ,
369- rust_main_def_id : LocalDefId ,
386+ rust_main_def_id : DefId ,
370387 use_start_lang_item : bool ,
371388 ) -> Bx :: Function {
372389 // The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
0 commit comments