11//! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a
22//! standalone executable.
33
4+ use std:: io:: { self , Write } ;
45use std:: path:: PathBuf ;
6+ use std:: process:: { Command , Stdio } ;
57
68use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
79use rustc_hir:: ItemId ;
@@ -29,29 +31,34 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
2931 }
3032}
3133
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 < ( ) > {
3639 if global_asm. is_empty ( ) {
37- return ;
40+ return Ok ( ( ) ) ;
3841 }
3942
4043 if cfg ! ( not( feature = "inline_asm" ) )
4144 || tcx. sess . target . is_like_osx
4245 || tcx. sess . target . is_like_windows
4346 {
4447 if global_asm. contains ( "__rust_probestack" ) {
45- return ;
48+ return Ok ( ( ) ) ;
4649 }
4750
4851 // FIXME fix linker error on macOS
4952 if cfg ! ( not( feature = "inline_asm" ) ) {
50- tcx. sess . fatal (
53+ return Err ( io:: Error :: new (
54+ io:: ErrorKind :: Unsupported ,
5155 "asm! and global_asm! support is disabled while compiling rustc_codegen_cranelift" ,
52- ) ;
56+ ) ) ;
5357 } 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+ ) ) ;
5562 }
5663 }
5764
@@ -78,7 +85,10 @@ pub(crate) fn compile_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &s
7885 child. stdin . take ( ) . unwrap ( ) . write_all ( global_asm. as_bytes ( ) ) . unwrap ( ) ;
7986 let status = child. wait ( ) . expect ( "Failed to wait for `as`." ) ;
8087 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+ ) ) ;
8292 }
8393
8494 // 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
93103 . status ( )
94104 . unwrap ( ) ;
95105 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+ ) ,
100113 ) ) ;
101114 }
102115
103116 std:: fs:: remove_file ( global_asm_object_file) . unwrap ( ) ;
104117 std:: fs:: remove_file ( main_object_file) . unwrap ( ) ;
118+
119+ Ok ( ( ) )
105120}
106121
107122fn add_file_stem_postfix ( mut path : PathBuf , postfix : & str ) -> PathBuf {
0 commit comments