11use rustc_hir:: LangItem ;
22use rustc_middle:: ty:: subst:: GenericArg ;
33use rustc_middle:: ty:: AssocKind ;
4- use rustc_session:: config:: EntryFnType ;
4+ use rustc_session:: config:: { sigpipe , EntryFnType } ;
55use rustc_span:: symbol:: Ident ;
66
77use crate :: prelude:: * ;
@@ -15,12 +15,12 @@ pub(crate) fn maybe_create_entry_wrapper(
1515 is_jit : bool ,
1616 is_primary_cgu : bool ,
1717) {
18- let ( main_def_id, is_main_fn) = match tcx. entry_fn ( ( ) ) {
18+ let ( main_def_id, ( is_main_fn, sigpipe ) ) = match tcx. entry_fn ( ( ) ) {
1919 Some ( ( def_id, entry_ty) ) => (
2020 def_id,
2121 match entry_ty {
22- EntryFnType :: Main => true ,
23- EntryFnType :: Start => false ,
22+ EntryFnType :: Main { sigpipe } => ( true , sigpipe ) ,
23+ EntryFnType :: Start => ( false , sigpipe :: DEFAULT ) ,
2424 } ,
2525 ) ,
2626 None => return ,
@@ -35,7 +35,7 @@ pub(crate) fn maybe_create_entry_wrapper(
3535 return ;
3636 }
3737
38- create_entry_fn ( tcx, module, unwind_context, main_def_id, is_jit, is_main_fn) ;
38+ create_entry_fn ( tcx, module, unwind_context, main_def_id, is_jit, is_main_fn, sigpipe ) ;
3939
4040 fn create_entry_fn (
4141 tcx : TyCtxt < ' _ > ,
@@ -44,6 +44,7 @@ pub(crate) fn maybe_create_entry_wrapper(
4444 rust_main_def_id : DefId ,
4545 ignore_lang_start_wrapper : bool ,
4646 is_main_fn : bool ,
47+ sigpipe : u8 ,
4748 ) {
4849 let main_ret_ty = tcx. fn_sig ( rust_main_def_id) . output ( ) ;
4950 // Given that `main()` has no arguments,
@@ -83,6 +84,7 @@ pub(crate) fn maybe_create_entry_wrapper(
8384 bcx. switch_to_block ( block) ;
8485 let arg_argc = bcx. append_block_param ( block, m. target_config ( ) . pointer_type ( ) ) ;
8586 let arg_argv = bcx. append_block_param ( block, m. target_config ( ) . pointer_type ( ) ) ;
87+ let arg_sigpipe = bcx. ins ( ) . iconst ( types:: I8 , sigpipe as i64 ) ;
8688
8789 let main_func_ref = m. declare_func_in_func ( main_func_id, & mut bcx. func ) ;
8890
@@ -143,7 +145,8 @@ pub(crate) fn maybe_create_entry_wrapper(
143145 let main_val = bcx. ins ( ) . func_addr ( m. target_config ( ) . pointer_type ( ) , main_func_ref) ;
144146
145147 let func_ref = m. declare_func_in_func ( start_func_id, & mut bcx. func ) ;
146- let call_inst = bcx. ins ( ) . call ( func_ref, & [ main_val, arg_argc, arg_argv] ) ;
148+ let call_inst =
149+ bcx. ins ( ) . call ( func_ref, & [ main_val, arg_argc, arg_argv, arg_sigpipe] ) ;
147150 bcx. inst_results ( call_inst) [ 0 ]
148151 } else {
149152 // using user-defined start fn
0 commit comments