Skip to content

Commit

Permalink
Allow for re-using hidden monomorphizations on platforms that don't s…
Browse files Browse the repository at this point in the history
…upport Rust dylibs.
  • Loading branch information
michaelwoerister committed Apr 6, 2018
1 parent ec55390 commit 07704a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

#[inline]
pub fn local_crate_exports_generics(self) -> bool {
debug_assert!(self.share_generics());

self.sess.crate_types.borrow().iter().any(|crate_type| {
match crate_type {
CrateTypeExecutable |
Expand Down
36 changes: 27 additions & 9 deletions src/librustc_trans/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,37 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
use rustc::mir::mono::{Linkage, Visibility, MonoItem};
use rustc::ty::InstanceDef;

// Normally, we require that shared monomorphizations are not hidden,
// because if we want to re-use a monomorphization from a Rust dylib, it
// needs to be exported.
// However, on platforms that don't allow for Rust dylibs, having
// external linkage is enough for monomorphization to be linked to.
let need_visibility = tcx.sess.target.target.options.dynamic_linking &&
!tcx.sess.target.target.options.only_cdylib;

let (_, cgus) = tcx.collect_and_partition_translation_items(LOCAL_CRATE);

for (mono_item, &(linkage, visibility)) in cgus.iter()
.flat_map(|cgu| cgu.items().iter()) {
if linkage == Linkage::External && visibility == Visibility::Default {
if let &MonoItem::Fn(Instance {
def: InstanceDef::Item(def_id),
substs,
}) = mono_item {
if substs.types().next().is_some() {
symbols.push((ExportedSymbol::Generic(def_id, substs),
SymbolExportLevel::Rust));
}
if linkage != Linkage::External {
// We can only re-use things with external linkage, otherwise
// we'll get a linker error
continue
}

if need_visibility && visibility == Visibility::Hidden {
// If we potentially share things from Rust dylibs, they must
// not be hidden
continue
}

if let &MonoItem::Fn(Instance {
def: InstanceDef::Item(def_id),
substs,
}) = mono_item {
if substs.types().next().is_some() {
symbols.push((ExportedSymbol::Generic(def_id, substs),
SymbolExportLevel::Rust));
}
}
}
Expand Down

0 comments on commit 07704a4

Please sign in to comment.