@@ -247,19 +247,37 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
247247 use rustc:: mir:: mono:: { Linkage , Visibility , MonoItem } ;
248248 use rustc:: ty:: InstanceDef ;
249249
250+ // Normally, we require that shared monomorphizations are not hidden,
251+ // because if we want to re-use a monomorphization from a Rust dylib, it
252+ // needs to be exported.
253+ // However, on platforms that don't allow for Rust dylibs, having
254+ // external linkage is enough for monomorphization to be linked to.
255+ let need_visibility = tcx. sess . target . target . options . dynamic_linking &&
256+ !tcx. sess . target . target . options . only_cdylib ;
257+
250258 let ( _, cgus) = tcx. collect_and_partition_translation_items ( LOCAL_CRATE ) ;
251259
252260 for ( mono_item, & ( linkage, visibility) ) in cgus. iter ( )
253261 . flat_map ( |cgu| cgu. items ( ) . iter ( ) ) {
254- if linkage == Linkage :: External && visibility == Visibility :: Default {
255- if let & MonoItem :: Fn ( Instance {
256- def : InstanceDef :: Item ( def_id) ,
257- substs,
258- } ) = mono_item {
259- if substs. types ( ) . next ( ) . is_some ( ) {
260- symbols. push ( ( ExportedSymbol :: Generic ( def_id, substs) ,
261- SymbolExportLevel :: Rust ) ) ;
262- }
262+ if linkage != Linkage :: External {
263+ // We can only re-use things with external linkage, otherwise
264+ // we'll get a linker error
265+ continue
266+ }
267+
268+ if need_visibility && visibility == Visibility :: Hidden {
269+ // If we potentially share things from Rust dylibs, they must
270+ // not be hidden
271+ continue
272+ }
273+
274+ if let & MonoItem :: Fn ( Instance {
275+ def : InstanceDef :: Item ( def_id) ,
276+ substs,
277+ } ) = mono_item {
278+ if substs. types ( ) . next ( ) . is_some ( ) {
279+ symbols. push ( ( ExportedSymbol :: Generic ( def_id, substs) ,
280+ SymbolExportLevel :: Rust ) ) ;
263281 }
264282 }
265283 }
0 commit comments