@@ -233,19 +233,37 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
233
233
use rustc:: mir:: mono:: { Linkage , Visibility , MonoItem } ;
234
234
use rustc:: ty:: InstanceDef ;
235
235
236
+ // Normally, we require that shared monomorphizations are not hidden,
237
+ // because if we want to re-use a monomorphization from a Rust dylib, it
238
+ // needs to be exported.
239
+ // However, on platforms that don't allow for Rust dylibs, having
240
+ // external linkage is enough for monomorphization to be linked to.
241
+ let need_visibility = tcx. sess . target . target . options . dynamic_linking &&
242
+ !tcx. sess . target . target . options . only_cdylib ;
243
+
236
244
let ( _, cgus) = tcx. collect_and_partition_translation_items ( LOCAL_CRATE ) ;
237
245
238
246
for ( mono_item, & ( linkage, visibility) ) in cgus. iter ( )
239
247
. flat_map ( |cgu| cgu. items ( ) . iter ( ) ) {
240
- if linkage == Linkage :: External && visibility == Visibility :: Default {
241
- if let & MonoItem :: Fn ( Instance {
242
- def : InstanceDef :: Item ( def_id) ,
243
- substs,
244
- } ) = mono_item {
245
- if substs. types ( ) . next ( ) . is_some ( ) {
246
- symbols. push ( ( ExportedSymbol :: Generic ( def_id, substs) ,
247
- SymbolExportLevel :: Rust ) ) ;
248
- }
248
+ if linkage != Linkage :: External {
249
+ // We can only re-use things with external linkage, otherwise
250
+ // we'll get a linker error
251
+ continue
252
+ }
253
+
254
+ if need_visibility && visibility == Visibility :: Hidden {
255
+ // If we potentially share things from Rust dylibs, they must
256
+ // not be hidden
257
+ continue
258
+ }
259
+
260
+ if let & MonoItem :: Fn ( Instance {
261
+ def : InstanceDef :: Item ( def_id) ,
262
+ substs,
263
+ } ) = mono_item {
264
+ if substs. types ( ) . next ( ) . is_some ( ) {
265
+ symbols. push ( ( ExportedSymbol :: Generic ( def_id, substs) ,
266
+ SymbolExportLevel :: Rust ) ) ;
249
267
}
250
268
}
251
269
}
0 commit comments