1
1
use rustc_hir:: LangItem ;
2
2
use rustc_middle:: ty:: subst:: GenericArg ;
3
3
use rustc_middle:: ty:: AssocKind ;
4
- use rustc_session:: config:: EntryFnType ;
4
+ use rustc_session:: config:: { sigpipe , EntryFnType } ;
5
5
use rustc_span:: symbol:: Ident ;
6
6
7
7
use crate :: prelude:: * ;
@@ -15,12 +15,12 @@ pub(crate) fn maybe_create_entry_wrapper(
15
15
is_jit : bool ,
16
16
is_primary_cgu : bool ,
17
17
) {
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 ( ( ) ) {
19
19
Some ( ( def_id, entry_ty) ) => (
20
20
def_id,
21
21
match entry_ty {
22
- EntryFnType :: Main => true ,
23
- EntryFnType :: Start => false ,
22
+ EntryFnType :: Main { sigpipe } => ( true , sigpipe ) ,
23
+ EntryFnType :: Start => ( false , sigpipe :: DEFAULT ) ,
24
24
} ,
25
25
) ,
26
26
None => return ,
@@ -35,7 +35,7 @@ pub(crate) fn maybe_create_entry_wrapper(
35
35
return ;
36
36
}
37
37
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 ) ;
39
39
40
40
fn create_entry_fn (
41
41
tcx : TyCtxt < ' _ > ,
@@ -44,6 +44,7 @@ pub(crate) fn maybe_create_entry_wrapper(
44
44
rust_main_def_id : DefId ,
45
45
ignore_lang_start_wrapper : bool ,
46
46
is_main_fn : bool ,
47
+ sigpipe : u8 ,
47
48
) {
48
49
let main_ret_ty = tcx. fn_sig ( rust_main_def_id) . output ( ) ;
49
50
// Given that `main()` has no arguments,
@@ -83,6 +84,7 @@ pub(crate) fn maybe_create_entry_wrapper(
83
84
bcx. switch_to_block ( block) ;
84
85
let arg_argc = bcx. append_block_param ( block, m. target_config ( ) . pointer_type ( ) ) ;
85
86
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 ) ;
86
88
87
89
let main_func_ref = m. declare_func_in_func ( main_func_id, & mut bcx. func ) ;
88
90
@@ -143,7 +145,8 @@ pub(crate) fn maybe_create_entry_wrapper(
143
145
let main_val = bcx. ins ( ) . func_addr ( m. target_config ( ) . pointer_type ( ) , main_func_ref) ;
144
146
145
147
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] ) ;
147
150
bcx. inst_results ( call_inst) [ 0 ]
148
151
} else {
149
152
// using user-defined start fn
0 commit comments