@@ -2257,18 +2257,17 @@ pub fn update_linkage(ccx: &CrateContext,
22572257 }
22582258}
22592259
2260- fn set_global_section ( ccx : & CrateContext , llval : ValueRef , i : & hir:: Item ) {
2261- match attr:: first_attr_value_str_by_name ( & i. attrs , "link_section" ) {
2262- Some ( sect) => {
2263- if contains_null ( & sect) {
2264- ccx. sess ( ) . fatal ( & format ! ( "Illegal null byte in link_section value: `{}`" , & sect) ) ;
2265- }
2266- unsafe {
2267- let buf = CString :: new ( sect. as_bytes ( ) ) . unwrap ( ) ;
2268- llvm:: LLVMSetSection ( llval, buf. as_ptr ( ) ) ;
2269- }
2270- } ,
2271- None => ( )
2260+ pub fn set_link_section ( ccx : & CrateContext ,
2261+ llval : ValueRef ,
2262+ attrs : & [ ast:: Attribute ] ) {
2263+ if let Some ( sect) = attr:: first_attr_value_str_by_name ( attrs, "link_section" ) {
2264+ if contains_null ( & sect) {
2265+ ccx. sess ( ) . fatal ( & format ! ( "Illegal null byte in link_section value: `{}`" , & sect) ) ;
2266+ }
2267+ unsafe {
2268+ let buf = CString :: new ( sect. as_bytes ( ) ) . unwrap ( ) ;
2269+ llvm:: LLVMSetSection ( llval, buf. as_ptr ( ) ) ;
2270+ }
22722271 }
22732272}
22742273
@@ -2291,7 +2290,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
22912290 let empty_substs = ccx. empty_substs_for_def_id ( def_id) ;
22922291 let llfn = Callee :: def ( ccx, def_id, empty_substs) . reify ( ccx) . val ;
22932292 trans_fn ( ccx, & decl, & body, llfn, empty_substs, item. id ) ;
2294- set_global_section ( ccx, llfn, item) ;
2293+ set_link_section ( ccx, llfn, & item. attrs ) ;
22952294 update_linkage ( ccx,
22962295 llfn,
22972296 Some ( item. id ) ,
@@ -2347,13 +2346,9 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
23472346 enum_variant_size_lint ( ccx, enum_definition, item. span , item. id ) ;
23482347 }
23492348 }
2350- hir:: ItemStatic ( _, m, ref expr) => {
2351- let g = match consts:: trans_static ( ccx, m, expr, item. id , & item. attrs ) {
2352- Ok ( g) => g,
2353- Err ( err) => ccx. tcx ( ) . sess . span_fatal ( expr. span , & err. description ( ) ) ,
2354- } ;
2355- set_global_section ( ccx, g, item) ;
2356- update_linkage ( ccx, g, Some ( item. id ) , OriginalTranslation ) ;
2349+ hir:: ItemStatic ( ..) => {
2350+ // Don't do anything here. Translation of statics has been moved to
2351+ // being "collector-driven".
23572352 }
23582353 _ => { }
23592354 }
@@ -2711,6 +2706,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27112706
27122707 let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
27132708 let codegen_unit_count = codegen_units. len ( ) ;
2709+
27142710 assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
27152711 tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
27162712
@@ -2734,6 +2730,33 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
27342730 } ;
27352731 }
27362732
2733+ // Instantiate translation items without filling out definitions yet...
2734+ for ccx in crate_context_list. iter ( ) {
2735+ for ( & trans_item, & linkage) in & ccx. codegen_unit ( ) . items {
2736+ trans_item. predefine ( & ccx, linkage) ;
2737+ }
2738+ }
2739+
2740+ // ... and now that we have everything pre-defined, fill out those definitions.
2741+ for ccx in crate_context_list. iter ( ) {
2742+ for ( & trans_item, _) in & ccx. codegen_unit ( ) . items {
2743+ match trans_item {
2744+ TransItem :: Static ( node_id) => {
2745+ let item = ccx. tcx ( ) . map . expect_item ( node_id) ;
2746+ if let hir:: ItemStatic ( _, m, ref expr) = item. node {
2747+ match consts:: trans_static ( & ccx, m, expr, item. id , & item. attrs ) {
2748+ Ok ( _) => { /* Cool, everything's alright. */ } ,
2749+ Err ( err) => ccx. tcx ( ) . sess . span_fatal ( expr. span , & err. description ( ) ) ,
2750+ } ;
2751+ } else {
2752+ span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
2753+ }
2754+ }
2755+ _ => { }
2756+ }
2757+ }
2758+ }
2759+
27372760 {
27382761 let ccx = crate_context_list. get_ccx ( 0 ) ;
27392762
0 commit comments