1
Fork 0

Auto merge of #99944 - bjorn3:hide_proc_macro_symbols, r=eddyb

Limit symbols exported from proc macros

Only `__rustc_proc_macro_decls_*__` and `rust_metadata_*` need to be
exported for proc macros to work. All other symbols only increase binary
size and have the potential to conflict with symbols from the host
compiler.

Fixes https://github.com/rust-lang/rust/issues/99909
Fixes #59998

cc `@eddyb`
This commit is contained in:
bors 2022-08-01 03:58:52 +00:00
commit 25bb1c13bd
15 changed files with 41 additions and 41 deletions

View file

@ -656,9 +656,7 @@ impl<'a> Linker for GccLinker<'a> {
return;
}
if crate_type == CrateType::ProcMacro {
return;
}
// FIXME(#99978) hide #[no_mangle] symbols for proc-macros
let is_windows = self.sess.target.is_like_windows;
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });

View file

@ -257,16 +257,18 @@ fn exported_symbols_provider_local<'tcx>(
}));
}
if tcx.sess.crate_types().contains(&CrateType::Dylib) {
if tcx.sess.crate_types().contains(&CrateType::Dylib)
|| tcx.sess.crate_types().contains(&CrateType::ProcMacro)
{
let symbol_name = metadata_symbol_name(tcx);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
used: true,
},
));
}