File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ pub(crate) mod stack_size;
1212
1313pub fn binary_analysis < ' tcx > ( cx : & AnalysisCtxt < ' tcx > , path : & Path ) {
1414 let file = File :: open ( path) . unwrap ( ) ;
15+ let meta = file. metadata ( ) . unwrap ( ) ;
16+ if !meta. is_file ( ) {
17+ // We cannot handle special devices (this can be e.g. /dev/null).
18+ return ;
19+ }
20+
1521 let mmap = unsafe { rustc_data_structures:: memmap:: Mmap :: map ( file) } . unwrap ( ) ;
1622 let object = ObjectFile :: parse ( & * mmap) . unwrap ( ) ;
1723
Original file line number Diff line number Diff line change @@ -159,9 +159,20 @@ impl driver::CallbacksExt for MyCallbacks {
159159 }
160160
161161 fn after_codegen < ' tcx > ( & mut self , cx : & ' tcx AnalysisCtxt < ' tcx > ) {
162+ // If compilation fails, do not attempt to perform binary analysis, as
163+ // binary might not have been generated.
164+ if cx. dcx ( ) . has_errors ( ) . is_some ( ) {
165+ return ;
166+ }
167+
162168 let outputs = cx. output_filenames ( ( ) ) ;
163169 if outputs. outputs . contains_key ( & OutputType :: Object ) {
164- binary_analysis:: binary_analysis ( cx, outputs. path ( OutputType :: Object ) . as_path ( ) ) ;
170+ let file = outputs. path ( OutputType :: Object ) ;
171+ // We cannot retrieve object back from stdout.
172+ if file. is_stdout ( ) {
173+ return ;
174+ }
175+ binary_analysis:: binary_analysis ( cx, file. as_path ( ) ) ;
165176 }
166177 }
167178}
You can’t perform that action at this time.
0 commit comments