@@ -598,6 +598,69 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
598
598
ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
599
599
}
600
600
601
+ // codegen idata sections for raw-dylib linking
602
+ let mut raw_dylib_imports = vec ! [ ] ;
603
+ let native_libs = tcx. native_libraries ( LOCAL_CRATE ) ;
604
+
605
+
606
+ for lib in native_libs. iter ( ) {
607
+ match lib. kind {
608
+ cstore:: NativeLibraryKind :: NativeRawDylib => {
609
+ if let ( Some ( dll_name) , Some ( def_id) ) = ( lib. name , lib. foreign_module ) {
610
+ let foreign_modules = tcx. foreign_modules ( LOCAL_CRATE ) ;
611
+ for f_mod in foreign_modules {
612
+ if f_mod. def_id == def_id {
613
+ let items = f_mod. foreign_items . iter ( ) . map ( |& def_id| {
614
+ let fn_attrs = tcx. codegen_fn_attrs ( def_id) ;
615
+ if fn_attrs. link_name . is_some ( ) {
616
+ RawDylibImportName :: Name ( fn_attrs. link_name . unwrap ( ) )
617
+ } else if fn_attrs. link_ordinal . is_some ( ) {
618
+ RawDylibImportName :: Ordinal ( fn_attrs. link_ordinal . unwrap ( ) )
619
+ } else {
620
+ let name = tcx. item_name ( def_id) ;
621
+ RawDylibImportName :: Name ( name)
622
+ }
623
+ } ) . collect ( ) ;
624
+
625
+ raw_dylib_imports. push ( RawDylibImports {
626
+ name : dll_name,
627
+ items,
628
+ } ) ;
629
+ }
630
+ }
631
+ } else {
632
+ bug ! (
633
+ "not enough information to link raw dylib!" ,
634
+ ) ;
635
+ }
636
+ } ,
637
+ _ => { } ,
638
+ }
639
+ }
640
+
641
+ if !raw_dylib_imports. is_empty ( ) {
642
+ let idata_cgu_name =
643
+ cgu_name_builder. build_cgu_name ( LOCAL_CRATE , & [ "crate" ] , Some ( "idata" ) ) . to_string ( ) ;
644
+ let mut idata_module = backend. new_metadata ( tcx, & idata_cgu_name) ;
645
+
646
+ tcx. sess . time ( "write_idata_sections" , || {
647
+ backend. write_idata_sections (
648
+ tcx,
649
+ & raw_dylib_imports,
650
+ & mut idata_module,
651
+ ) ;
652
+ } ) ;
653
+
654
+ let idata_module = ModuleCodegen {
655
+ name : idata_cgu_name,
656
+ module_llvm : idata_module,
657
+ kind : ModuleKind :: Regular ,
658
+ } ;
659
+ ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, idata_module) ;
660
+ }
661
+
662
+
663
+
601
664
// We sort the codegen units by size. This way we can schedule work for LLVM
602
665
// a bit more efficiently.
603
666
let codegen_units = {
0 commit comments