@@ -14,6 +14,7 @@ use rustc::middle::dependency_format::Linkage;
14
14
use rustc:: session:: Session ;
15
15
use rustc:: session:: config:: { self , CrateType , OptLevel , DebugInfo ,
16
16
LinkerPluginLto , Lto } ;
17
+ use rustc:: middle:: exported_symbols:: ExportedSymbol ;
17
18
use rustc:: ty:: TyCtxt ;
18
19
use rustc_target:: spec:: { LinkerFlavor , LldFlavor } ;
19
20
use rustc_serialize:: { json, Encoder } ;
@@ -1107,9 +1108,26 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1107
1108
if * dep_format == Linkage :: Static {
1108
1109
// ... we add its symbol list to our export list.
1109
1110
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 ;
1112
1113
}
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 ( ) ) ;
1113
1131
}
1114
1132
}
1115
1133
}
0 commit comments