@@ -265,15 +265,11 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
265
265
let mut codegen_units = FnvHashMap ( ) ;
266
266
267
267
for trans_item in trans_items {
268
- let is_root = match trans_item {
269
- TransItem :: Static ( ..) => true ,
270
- TransItem :: DropGlue ( ..) => false ,
271
- TransItem :: Fn ( _) => !trans_item. is_from_extern_crate ( ) ,
272
- } ;
268
+ let is_root = !trans_item. is_instantiated_only_on_demand ( ) ;
273
269
274
270
if is_root {
275
271
let characteristic_def_id = characteristic_def_id_of_trans_item ( tcx, trans_item) ;
276
- let is_volatile = trans_item. is_lazily_instantiated ( ) ;
272
+ let is_volatile = trans_item. is_generic_fn ( ) ;
277
273
278
274
let codegen_unit_name = match characteristic_def_id {
279
275
Some ( def_id) => compute_codegen_unit_name ( tcx, def_id, is_volatile) ,
@@ -304,9 +300,9 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
304
300
// it might be used in another codegen unit.
305
301
llvm:: ExternalLinkage
306
302
} else {
307
- // Monomorphizations of generic functions are
308
- // always weak-odr
309
- llvm :: WeakODRLinkage
303
+ // In the current setup, generic functions cannot
304
+ // be roots.
305
+ unreachable ! ( )
310
306
}
311
307
}
312
308
}
@@ -395,25 +391,23 @@ fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartit
395
391
if let Some ( linkage) = codegen_unit. items . get ( & trans_item) {
396
392
// This is a root, just copy it over
397
393
new_codegen_unit. items . insert ( trans_item, * linkage) ;
394
+ } else if initial_partitioning. roots . contains ( & trans_item) {
395
+ // This item will be instantiated in some other codegen unit,
396
+ // so we just add it here with AvailableExternallyLinkage
397
+ new_codegen_unit. items . insert ( trans_item,
398
+ llvm:: AvailableExternallyLinkage ) ;
399
+ } else if trans_item. is_from_extern_crate ( ) && !trans_item. is_generic_fn ( ) {
400
+ // An instantiation of this item is always available in the
401
+ // crate it was imported from.
402
+ new_codegen_unit. items . insert ( trans_item,
403
+ llvm:: AvailableExternallyLinkage ) ;
398
404
} else {
399
- if initial_partitioning. roots . contains ( & trans_item) {
400
- // This item will be instantiated in some other codegen unit,
401
- // so we just add it here with AvailableExternallyLinkage
402
- new_codegen_unit. items . insert ( trans_item,
403
- llvm:: AvailableExternallyLinkage ) ;
404
- } else if trans_item. is_from_extern_crate ( ) && !trans_item. is_generic_fn ( ) {
405
- // An instantiation of this item is always available in the
406
- // crate it was imported from.
407
- new_codegen_unit. items . insert ( trans_item,
408
- llvm:: AvailableExternallyLinkage ) ;
409
- } else {
410
- // We can't be sure if this will also be instantiated
411
- // somewhere else, so we add an instance here with
412
- // LinkOnceODRLinkage. That way the item can be discarded if
413
- // it's not needed (inlined) after all.
414
- new_codegen_unit. items . insert ( trans_item,
415
- llvm:: LinkOnceODRLinkage ) ;
416
- }
405
+ assert ! ( trans_item. is_instantiated_only_on_demand( ) ) ;
406
+ // We can't be sure if this will also be instantiated
407
+ // somewhere else, so we add an instance here with
408
+ // InternalLinkage so we don't get any conflicts.
409
+ new_codegen_unit. items . insert ( trans_item,
410
+ llvm:: InternalLinkage ) ;
417
411
}
418
412
}
419
413
@@ -521,17 +515,19 @@ fn single_codegen_unit<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
521
515
}
522
516
}
523
517
TransItem :: DropGlue ( _) => {
524
- llvm:: PrivateLinkage
518
+ llvm:: InternalLinkage
525
519
}
526
520
TransItem :: Fn ( instance) => {
527
- if trans_item. is_generic_fn ( ) ||
528
- trans_item. is_from_extern_crate ( ) ||
529
- !reachable. contains ( & tcx. map
530
- . as_local_node_id ( instance. def )
531
- . unwrap ( ) ) {
521
+ if trans_item. is_generic_fn ( ) {
532
522
llvm:: InternalLinkage
533
- } else {
523
+ } else if trans_item. is_from_extern_crate ( ) {
524
+ llvm:: AvailableExternallyLinkage
525
+ } else if reachable. contains ( & tcx. map
526
+ . as_local_node_id ( instance. def )
527
+ . unwrap ( ) ) {
534
528
llvm:: ExternalLinkage
529
+ } else {
530
+ llvm:: InternalLinkage
535
531
}
536
532
}
537
533
}
0 commit comments