@@ -2257,18 +2257,17 @@ pub fn update_linkage(ccx: &CrateContext,
2257
2257
}
2258
2258
}
2259
2259
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
+ }
2272
2271
}
2273
2272
}
2274
2273
@@ -2291,7 +2290,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
2291
2290
let empty_substs = ccx. empty_substs_for_def_id ( def_id) ;
2292
2291
let llfn = Callee :: def ( ccx, def_id, empty_substs) . reify ( ccx) . val ;
2293
2292
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 ) ;
2295
2294
update_linkage ( ccx,
2296
2295
llfn,
2297
2296
Some ( item. id ) ,
@@ -2347,13 +2346,9 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
2347
2346
enum_variant_size_lint ( ccx, enum_definition, item. span , item. id ) ;
2348
2347
}
2349
2348
}
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".
2357
2352
}
2358
2353
_ => { }
2359
2354
}
@@ -2711,6 +2706,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2711
2706
2712
2707
let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2713
2708
let codegen_unit_count = codegen_units. len ( ) ;
2709
+
2714
2710
assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
2715
2711
tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
2716
2712
@@ -2734,6 +2730,33 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2734
2730
} ;
2735
2731
}
2736
2732
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
+
2737
2760
{
2738
2761
let ccx = crate_context_list. get_ccx ( 0 ) ;
2739
2762
0 commit comments