@@ -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 {
@@ -431,6 +437,12 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
431437 // `SymbolExportLevel::Rust` export level but may end up being exported in dylibs.
432438 || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_COMPILER )
433439 || codegen_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER )
440+ // Right now, the only way to get "foreign item symbol aliases" is by being an EII-implementation.
441+ // EII implementations will generate under their own name but also under the name of some foreign item
442+ // (hence alias) that may be in another crate. These functions are marked as always-reachable since
443+ // it's very hard to track whether the original foreign item was reachable. It may live in another crate
444+ // and may be reachable from sibling crates.
445+ || !codegen_attrs. foreign_item_symbol_aliases . is_empty ( )
434446}
435447
436448/// See module-level doc comment above.
0 commit comments