@@ -25,7 +25,7 @@ use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
2525use rustc:: ty:: query:: Providers ;
2626use rustc:: middle:: cstore:: { self , LinkagePreference } ;
2727use rustc:: util:: common:: { time, print_time_passes_entry} ;
28- use rustc:: session:: config:: { self , EntryFnType , Lto } ;
28+ use rustc:: session:: config:: { self , CrateType , EntryFnType , Lto } ;
2929use rustc:: session:: Session ;
3030use rustc_mir:: monomorphize:: item:: DefPathBasedNames ;
3131use rustc_mir:: monomorphize:: Instance ;
@@ -550,12 +550,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
550550 } ) ;
551551 tcx. sess . profiler ( |p| p. end_activity ( "codegen crate metadata" ) ) ;
552552
553- let metadata_module = ModuleCodegen {
554- name : metadata_cgu_name,
555- module_llvm : metadata_llvm_module,
556- kind : ModuleKind :: Metadata ,
557- } ;
558-
559553 // Skip crate items and just output metadata in -Z no-codegen mode.
560554 if tcx. sess . opts . debugging_opts . no_codegen ||
561555 !tcx. sess . opts . output_types . should_codegen ( ) {
@@ -566,7 +560,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
566560 rx,
567561 1 ) ;
568562
569- ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
570563 ongoing_codegen. codegen_finished ( tcx) ;
571564
572565 assert_and_save_dep_graph ( tcx) ;
@@ -639,7 +632,24 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
639632 ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, allocator_module) ;
640633 }
641634
642- ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
635+ let needs_metadata_module = tcx. sess . crate_types . borrow ( ) . iter ( ) . any ( |ct| {
636+ match * ct {
637+ CrateType :: Dylib |
638+ CrateType :: ProcMacro => true ,
639+ CrateType :: Executable |
640+ CrateType :: Rlib |
641+ CrateType :: Staticlib |
642+ CrateType :: Cdylib => false ,
643+ }
644+ } ) ;
645+ if needs_metadata_module {
646+ let metadata_module = ModuleCodegen {
647+ name : metadata_cgu_name,
648+ module_llvm : metadata_llvm_module,
649+ kind : ModuleKind :: Metadata ,
650+ } ;
651+ ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
652+ }
643653
644654 // We sort the codegen units by size. This way we can schedule work for LLVM
645655 // a bit more efficiently.
0 commit comments