@@ -305,17 +305,35 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
305
305
let codegen_unit = codegen_units. entry ( codegen_unit_name. clone ( ) )
306
306
. or_insert_with ( make_codegen_unit) ;
307
307
308
+ let mut can_be_internalized = true ;
308
309
let ( linkage, visibility) = match trans_item. explicit_linkage ( tcx) {
309
310
Some ( explicit_linkage) => ( explicit_linkage, Visibility :: Default ) ,
310
311
None => {
311
312
match trans_item {
312
313
MonoItem :: Fn ( ref instance) => {
313
314
let visibility = match instance. def {
314
315
InstanceDef :: Item ( def_id) => {
315
- // If we encounter the lang start item, we set the visibility to
316
- // default.
316
+ // The `start_fn` lang item is actually a
317
+ // monomorphized instance of a function in the
318
+ // standard library, used for the `main`
319
+ // function. We don't want to export it so we
320
+ // tag it with `Hidden` visibility but this
321
+ // symbol is only referenced from the actual
322
+ // `main` symbol which we unfortunately don't
323
+ // know anything about during
324
+ // partitioning/collection. As a result we
325
+ // forcibly keep this symbol out of the
326
+ // `internalization_candidates` set.
327
+ //
328
+ // FIXME: eventually we don't want to always
329
+ // force this symbol to have hidden
330
+ // visibility, it should indeed be a candidate
331
+ // for internalization, but we have to
332
+ // understand that it's referenced from the
333
+ // `main` symbol we'll generate later.
317
334
if tcx. lang_items ( ) . start_fn ( ) == Some ( def_id) {
318
- Visibility :: Default
335
+ can_be_internalized = false ;
336
+ Visibility :: Hidden
319
337
} else if def_id. is_local ( ) {
320
338
if tcx. is_exported_symbol ( def_id) {
321
339
Visibility :: Default
@@ -350,7 +368,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
350
368
}
351
369
}
352
370
} ;
353
- if visibility == Visibility :: Hidden {
371
+ if visibility == Visibility :: Hidden && can_be_internalized {
354
372
internalization_candidates. insert ( trans_item) ;
355
373
}
356
374
0 commit comments