Skip to content

Commit d228c51

Browse files
committed
visibility using std_internal_symbol
1 parent 0f62145 commit d228c51

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ fn process_builtin_attrs(
328328
if i.is_default { Linkage::LinkOnceAny } else { Linkage::External },
329329
Visibility::Default,
330330
));
331+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
331332
}
332333
}
333334
_ => {}

compiler/rustc_passes/src/reachable.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ impl Resolver<'_, '_> {
418418
&& !tcx.is_panic_runtime(cnum)
419419
&& !tcx.has_global_allocator(cnum)
420420
&& !tcx.has_panic_handler(cnum)
421+
&& tcx.externally_implementable_items(cnum).is_empty()
421422
}) {
422423
maybe_unused_extern_crates.insert(id, import.span);
423424
}

0 commit comments

Comments
 (0)