Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0672762

Browse files
committedMar 14, 2025
Auto merge of #137736 - bjorn3:compiler_builtins_export_fix, r=petrochenkov
Don't attempt to export compiler-builtins symbols from rust dylibs They are marked with hidden visibility to prevent them from getting exported, so we shouldn't ask the linker to export them anyway. The only thing that does it cause a warning on macOS. Part of #136096 cc `@jyn514`
2 parents ecade53 + d73479e commit 0672762

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/linker.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,10 @@ fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -
17841784
let mut symbols = Vec::new();
17851785
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17861786
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
1787-
if info.level.is_below_threshold(export_threshold) {
1787+
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
1788+
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
1789+
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
1790+
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum) {
17881791
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
17891792
tcx, symbol, cnum,
17901793
));

‎compiler/rustc_passes/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ passes_unused_duplicate =
811811
passes_unused_empty_lints_note =
812812
attribute `{$name}` with an empty list has no effect
813813
814-
passes_unused_linker_warnings_note =
815-
the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked
814+
passes_unused_linker_messages_note =
815+
the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
816816
817817
passes_unused_multiple =
818818
multiple `{$name}` attributes

‎compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23872387
.iter()
23882388
.all(|kind| matches!(kind, CrateType::Rlib | CrateType::Staticlib));
23892389
if never_needs_link {
2390-
errors::UnusedNote::LinkerWarningsBinaryCrateOnly
2390+
errors::UnusedNote::LinkerMessagesBinaryCrateOnly
23912391
} else {
23922392
return;
23932393
}

‎compiler/rustc_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ pub(crate) enum UnusedNote {
770770
NoLints { name: Symbol },
771771
#[note(passes_unused_default_method_body_const_note)]
772772
DefaultMethodBodyConst,
773-
#[note(passes_unused_linker_warnings_note)]
774-
LinkerWarningsBinaryCrateOnly,
773+
#[note(passes_unused_linker_messages_note)]
774+
LinkerMessagesBinaryCrateOnly,
775775
}
776776

777777
#[derive(LintDiagnostic)]

‎tests/ui/lint/linker-warning.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ warning: unused attribute
1616
LL | #![allow(linker_messages)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
1818
|
19-
= note: the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked
19+
= note: the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
2020

2121
warning: 2 warnings emitted
2222

0 commit comments

Comments
 (0)
Failed to load comments.