@@ -9,12 +9,12 @@ use std::{io, iter, slice};
99use object:: read:: archive:: ArchiveFile ;
1010use object:: { Object , ObjectSection } ;
1111use rustc_codegen_ssa:: back:: lto:: { SerializedModule , ThinModule , ThinShared } ;
12- use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
12+ use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput , SharedEmitter } ;
1313use rustc_codegen_ssa:: traits:: * ;
1414use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
1515use rustc_data_structures:: fx:: FxHashMap ;
1616use rustc_data_structures:: memmap:: Mmap ;
17- use rustc_errors:: DiagCtxtHandle ;
17+ use rustc_errors:: { DiagCtxt , DiagCtxtHandle } ;
1818use rustc_hir:: attrs:: SanitizerSet ;
1919use rustc_middle:: bug;
2020use rustc_middle:: dep_graph:: WorkProduct ;
@@ -150,36 +150,36 @@ fn get_bitcode_slice_from_object_data<'a>(
150150/// for further optimization.
151151pub ( crate ) fn run_fat (
152152 cgcx : & CodegenContext < LlvmCodegenBackend > ,
153+ shared_emitter : & SharedEmitter ,
153154 exported_symbols_for_lto : & [ String ] ,
154155 each_linked_rlib_for_lto : & [ PathBuf ] ,
155156 modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
156157) -> ModuleCodegen < ModuleLlvm > {
157- let dcx = cgcx . create_dcx ( ) ;
158+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter . clone ( ) ) ) ;
158159 let dcx = dcx. handle ( ) ;
159160 let ( symbols_below_threshold, upstream_modules) =
160161 prepare_lto ( cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx) ;
161162 let symbols_below_threshold =
162163 symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
163- fat_lto ( cgcx, dcx, modules, upstream_modules, & symbols_below_threshold)
164+ fat_lto ( cgcx, dcx, shared_emitter , modules, upstream_modules, & symbols_below_threshold)
164165}
165166
166167/// Performs thin LTO by performing necessary global analysis and returning two
167168/// lists, one of the modules that need optimization and another for modules that
168169/// can simply be copied over from the incr. comp. cache.
169170pub ( crate ) fn run_thin (
170171 cgcx : & CodegenContext < LlvmCodegenBackend > ,
172+ dcx : DiagCtxtHandle < ' _ > ,
171173 exported_symbols_for_lto : & [ String ] ,
172174 each_linked_rlib_for_lto : & [ PathBuf ] ,
173175 modules : Vec < ( String , ThinBuffer ) > ,
174176 cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
175177) -> ( Vec < ThinModule < LlvmCodegenBackend > > , Vec < WorkProduct > ) {
176- let dcx = cgcx. create_dcx ( ) ;
177- let dcx = dcx. handle ( ) ;
178178 let ( symbols_below_threshold, upstream_modules) =
179179 prepare_lto ( cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx) ;
180180 let symbols_below_threshold =
181181 symbols_below_threshold. iter ( ) . map ( |c| c. as_ptr ( ) ) . collect :: < Vec < _ > > ( ) ;
182- if cgcx. opts . cg . linker_plugin_lto . enabled ( ) {
182+ if cgcx. use_linker_plugin_lto {
183183 unreachable ! (
184184 "We should never reach this case if the LTO step \
185185 is deferred to the linker"
@@ -197,6 +197,7 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBu
197197fn fat_lto (
198198 cgcx : & CodegenContext < LlvmCodegenBackend > ,
199199 dcx : DiagCtxtHandle < ' _ > ,
200+ shared_emitter : & SharedEmitter ,
200201 modules : Vec < FatLtoInput < LlvmCodegenBackend > > ,
201202 mut serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
202203 symbols_below_threshold : & [ * const libc:: c_char ] ,
@@ -265,8 +266,13 @@ fn fat_lto(
265266 // The linking steps below may produce errors and diagnostics within LLVM
266267 // which we'd like to handle and print, so set up our diagnostic handlers
267268 // (which get unregistered when they go out of scope below).
268- let _handler =
269- DiagnosticHandlers :: new ( cgcx, dcx, llcx, & module, CodegenDiagnosticsStage :: LTO ) ;
269+ let _handler = DiagnosticHandlers :: new (
270+ cgcx,
271+ shared_emitter,
272+ llcx,
273+ & module,
274+ CodegenDiagnosticsStage :: LTO ,
275+ ) ;
270276
271277 // For all other modules we codegened we'll need to link them into our own
272278 // bitcode. All modules were codegened in their own LLVM context, however,
@@ -720,10 +726,11 @@ impl Drop for ThinBuffer {
720726}
721727
722728pub ( crate ) fn optimize_thin_module (
723- thin_module : ThinModule < LlvmCodegenBackend > ,
724729 cgcx : & CodegenContext < LlvmCodegenBackend > ,
730+ shared_emitter : & SharedEmitter ,
731+ thin_module : ThinModule < LlvmCodegenBackend > ,
725732) -> ModuleCodegen < ModuleLlvm > {
726- let dcx = cgcx . create_dcx ( ) ;
733+ let dcx = DiagCtxt :: new ( Box :: new ( shared_emitter . clone ( ) ) ) ;
727734 let dcx = dcx. handle ( ) ;
728735
729736 let module_name = & thin_module. shared . module_names [ thin_module. idx ] ;
0 commit comments