@@ -14,6 +14,7 @@ use rustc::middle::dependency_format::Linkage;
1414use rustc:: session:: Session ;
1515use rustc:: session:: config:: { self , CrateType , OptLevel , DebugInfo ,
1616 LinkerPluginLto , Lto } ;
17+ use rustc:: middle:: exported_symbols:: ExportedSymbol ;
1718use rustc:: ty:: TyCtxt ;
1819use rustc_target:: spec:: { LinkerFlavor , LldFlavor } ;
1920use rustc_serialize:: { json, Encoder } ;
@@ -1107,9 +1108,26 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
11071108 if * dep_format == Linkage :: Static {
11081109 // ... we add its symbol list to our export list.
11091110 for & ( symbol, level) in tcx. exported_symbols ( cnum) . iter ( ) {
1110- if level. is_below_threshold ( export_threshold) {
1111- symbols . push ( symbol . symbol_name ( tcx ) . to_string ( ) ) ;
1111+ if ! level. is_below_threshold ( export_threshold) {
1112+ continue ;
11121113 }
1114+
1115+ // Do not export generic symbols from upstream crates in linked
1116+ // artifact (notably the `dylib` crate type). The main reason
1117+ // for this is that `symbol_name` is actually wrong for generic
1118+ // symbols because it guesses the name we'd give them locally
1119+ // rather than the name it has upstream (depending on
1120+ // `share_generics` settings and such).
1121+ //
1122+ // To fix that issue we just say that linked artifacts, aka
1123+ // `dylib`s, never export generic symbols and they aren't
1124+ // available to downstream crates. (the not available part is
1125+ // handled elsewhere).
1126+ if let ExportedSymbol :: Generic ( ..) = symbol {
1127+ continue ;
1128+ }
1129+
1130+ symbols. push ( symbol. symbol_name ( tcx) . to_string ( ) ) ;
11131131 }
11141132 }
11151133 }
0 commit comments