@@ -184,7 +184,13 @@ impl<'tcx> ReachableContext<'tcx> {
184184 CodegenFnAttrs :: EMPTY
185185 } ;
186186 let is_extern = codegen_attrs. contains_extern_indicator ( ) ;
187- if is_extern {
187+ // Right now, the only way to get "foreign item symbol aliases" is by being an EII-implementation.
188+ // EII implementations will generate under their own name but also under the name of some foreign item
189+ // (hence alias) that may be in another crate. These functions are marked as always-reachable since
190+ // it's very hard to track whether the original foreign item was reachable. It may live in another crate
191+ // and may be reachable from sibling crates.
192+ let has_foreign_aliases_eii = !codegen_attrs. foreign_item_symbol_aliases . is_empty ( ) ;
193+ if is_extern || has_foreign_aliases_eii {
188194 self . reachable_symbols . insert ( search_item) ;
189195 }
190196 } else {
@@ -429,6 +435,12 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
429435 // `SymbolExportLevel::Rust` export level but may end up being exported in dylibs.
430436 || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_COMPILER )
431437 || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER )
438+ // Right now, the only way to get "foreign item symbol aliases" is by being an EII-implementation.
439+ // EII implementations will generate under their own name but also under the name of some foreign item
440+ // (hence alias) that may be in another crate. These functions are marked as always-reachable since
441+ // it's very hard to track whether the original foreign item was reachable. It may live in another crate
442+ // and may be reachable from sibling crates.
443+ || !codegen_attrs. foreign_item_symbol_aliases . is_empty ( )
432444}
433445
434446/// See module-level doc comment above.
0 commit comments