@@ -81,19 +81,50 @@ impl ExportedSymbols {
81
81
for cnum in scx. sess ( ) . cstore . crates ( ) {
82
82
debug_assert ! ( cnum != LOCAL_CRATE ) ;
83
83
84
+ // If this crate is a plugin and/or a custom derive crate, then
85
+ // we're not even going to link those in so we skip those crates.
84
86
if scx. sess ( ) . cstore . plugin_registrar_fn ( cnum) . is_some ( ) ||
85
87
scx. sess ( ) . cstore . derive_registrar_fn ( cnum) . is_some ( ) {
86
88
continue ;
87
89
}
88
90
91
+ // Check to see if this crate is a "special runtime crate". These
92
+ // crates, implementation details of the standard library, typically
93
+ // have a bunch of `pub extern` and `#[no_mangle]` functions as the
94
+ // ABI between them. We don't want their symbols to have a `C`
95
+ // export level, however, as they're just implementation details.
96
+ // Down below we'll hardwire all of the symbols to the `Rust` export
97
+ // level instead.
98
+ let special_runtime_crate =
99
+ scx. sess ( ) . cstore . is_allocator ( cnum) ||
100
+ scx. sess ( ) . cstore . is_panic_runtime ( cnum) ||
101
+ scx. sess ( ) . cstore . is_compiler_builtins ( cnum) ;
102
+
89
103
let crate_exports = scx
90
104
. sess ( )
91
105
. cstore
92
106
. exported_symbols ( cnum)
93
107
. iter ( )
94
108
. map ( |& def_id| {
95
109
let name = Instance :: mono ( scx, def_id) . symbol_name ( scx) ;
96
- let export_level = export_level ( scx, def_id) ;
110
+ let export_level = if special_runtime_crate {
111
+ // We can probably do better here by just ensuring that
112
+ // it has hidden visibility rather than public
113
+ // visibility, as this is primarily here to ensure it's
114
+ // not stripped during LTO.
115
+ //
116
+ // In general though we won't link right if these
117
+ // symbols are stripped, and LTO currently strips them.
118
+ if name == "rust_eh_personality" ||
119
+ name == "rust_eh_register_frames" ||
120
+ name == "rust_eh_unregister_frames" {
121
+ SymbolExportLevel :: C
122
+ } else {
123
+ SymbolExportLevel :: Rust
124
+ }
125
+ } else {
126
+ export_level ( scx, def_id)
127
+ } ;
97
128
debug ! ( "EXPORTED SYMBOL (re-export): {} ({:?})" , name, export_level) ;
98
129
( name, export_level)
99
130
} )
0 commit comments