1
1
//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
2
2
//! standalone executable.
3
3
4
+ use std:: io:: { self , Write } ;
4
5
use std:: path:: PathBuf ;
6
+ use std:: process:: { Command , Stdio } ;
5
7
6
8
use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
7
9
use rustc_hir:: ItemId ;
@@ -29,29 +31,34 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
29
31
}
30
32
}
31
33
32
- pub ( crate ) fn compile_global_asm ( tcx : TyCtxt < ' _ > , cgu_name : & str , global_asm : & str ) {
33
- use std:: io:: Write ;
34
- use std:: process:: { Command , Stdio } ;
35
-
34
+ pub ( crate ) fn compile_global_asm (
35
+ tcx : TyCtxt < ' _ > ,
36
+ cgu_name : & str ,
37
+ global_asm : & str ,
38
+ ) -> io:: Result < ( ) > {
36
39
if global_asm. is_empty ( ) {
37
- return ;
40
+ return Ok ( ( ) ) ;
38
41
}
39
42
40
43
if cfg ! ( not( feature = "inline_asm" ) )
41
44
|| tcx. sess . target . is_like_osx
42
45
|| tcx. sess . target . is_like_windows
43
46
{
44
47
if global_asm. contains ( "__rust_probestack" ) {
45
- return ;
48
+ return Ok ( ( ) ) ;
46
49
}
47
50
48
51
// FIXME fix linker error on macOS
49
52
if cfg ! ( not( feature = "inline_asm" ) ) {
50
- tcx. sess . fatal (
53
+ return Err ( io:: Error :: new (
54
+ io:: ErrorKind :: Unsupported ,
51
55
"asm! and global_asm! support is disabled while compiling rustc_codegen_cranelift" ,
52
- ) ;
56
+ ) ) ;
53
57
} else {
54
- tcx. sess . fatal ( "asm! and global_asm! are not yet supported on macOS and Windows" ) ;
58
+ return Err ( io:: Error :: new (
59
+ io:: ErrorKind :: Unsupported ,
60
+ "asm! and global_asm! are not yet supported on macOS and Windows" ,
61
+ ) ) ;
55
62
}
56
63
}
57
64
@@ -78,7 +85,10 @@ pub(crate) fn compile_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &s
78
85
child. stdin . take ( ) . unwrap ( ) . write_all ( global_asm. as_bytes ( ) ) . unwrap ( ) ;
79
86
let status = child. wait ( ) . expect ( "Failed to wait for `as`." ) ;
80
87
if !status. success ( ) {
81
- tcx. sess . fatal ( & format ! ( "Failed to assemble `{}`" , global_asm) ) ;
88
+ return Err ( io:: Error :: new (
89
+ io:: ErrorKind :: Other ,
90
+ format ! ( "Failed to assemble `{}`" , global_asm) ,
91
+ ) ) ;
82
92
}
83
93
84
94
// Link the global asm and main object file together
@@ -93,15 +103,20 @@ pub(crate) fn compile_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &s
93
103
. status ( )
94
104
. unwrap ( ) ;
95
105
if !status. success ( ) {
96
- tcx. sess . fatal ( & format ! (
97
- "Failed to link `{}` and `{}` together" ,
98
- main_object_file. display( ) ,
99
- global_asm_object_file. display( ) ,
106
+ return Err ( io:: Error :: new (
107
+ io:: ErrorKind :: Other ,
108
+ format ! (
109
+ "Failed to link `{}` and `{}` together" ,
110
+ main_object_file. display( ) ,
111
+ global_asm_object_file. display( ) ,
112
+ ) ,
100
113
) ) ;
101
114
}
102
115
103
116
std:: fs:: remove_file ( global_asm_object_file) . unwrap ( ) ;
104
117
std:: fs:: remove_file ( main_object_file) . unwrap ( ) ;
118
+
119
+ Ok ( ( ) )
105
120
}
106
121
107
122
fn add_file_stem_postfix ( mut path : PathBuf , postfix : & str ) -> PathBuf {
0 commit comments