rustc: Switch start_fn to hidden visibility
This'll avoid exporting a symbol from binaries unnecessarily and should help the linker clean things up if it can.
This commit is contained in:
parent
81e375dba5
commit
2cdd1c4df3
1 changed files with 22 additions and 4 deletions
|
|
@ -305,6 +305,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
let codegen_unit = codegen_units.entry(codegen_unit_name.clone())
|
||||
.or_insert_with(make_codegen_unit);
|
||||
|
||||
let mut can_be_internalized = true;
|
||||
let (linkage, visibility) = match trans_item.explicit_linkage(tcx) {
|
||||
Some(explicit_linkage) => (explicit_linkage, Visibility::Default),
|
||||
None => {
|
||||
|
|
@ -312,10 +313,27 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
MonoItem::Fn(ref instance) => {
|
||||
let visibility = match instance.def {
|
||||
InstanceDef::Item(def_id) => {
|
||||
// If we encounter the lang start item, we set the visibility to
|
||||
// default.
|
||||
// The `start_fn` lang item is actually a
|
||||
// monomorphized instance of a function in the
|
||||
// standard library, used for the `main`
|
||||
// function. We don't want to export it so we
|
||||
// tag it with `Hidden` visibility but this
|
||||
// symbol is only referenced from the actual
|
||||
// `main` symbol which we unfortunately don't
|
||||
// know anything about during
|
||||
// partitioning/collection. As a result we
|
||||
// forcibly keep this symbol out of the
|
||||
// `internalization_candidates` set.
|
||||
//
|
||||
// FIXME: eventually we don't want to always
|
||||
// force this symbol to have hidden
|
||||
// visibility, it should indeed be a candidate
|
||||
// for internalization, but we have to
|
||||
// understand that it's referenced from the
|
||||
// `main` symbol we'll generate later.
|
||||
if tcx.lang_items().start_fn() == Some(def_id) {
|
||||
Visibility::Default
|
||||
can_be_internalized = false;
|
||||
Visibility::Hidden
|
||||
} else if def_id.is_local() {
|
||||
if tcx.is_exported_symbol(def_id) {
|
||||
Visibility::Default
|
||||
|
|
@ -350,7 +368,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
}
|
||||
};
|
||||
if visibility == Visibility::Hidden {
|
||||
if visibility == Visibility::Hidden && can_be_internalized {
|
||||
internalization_candidates.insert(trans_item);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue