diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2023-07-21 09:41:07 -0400 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2023-08-04 11:29:01 -0400 |
| commit | 3000c24afc37fe09c65772a71331002a7505dc11 (patch) | |
| tree | c3643397b958cd2bbc750aafbea4fa1e5687066f /compiler/rustc_codegen_ssa/src/back | |
| parent | defed6257aa93dfbe798900d959f825ac5410de6 (diff) | |
| download | rust-3000c24afc37fe09c65772a71331002a7505dc11.tar.gz rust-3000c24afc37fe09c65772a71331002a7505dc11.zip | |
special-case proc-macro crates in rustc_codegen_ssa::back::linker::exported_symbols to only export the two symbols that proc-macros need.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 4c04fc60b98..74b81733356 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -13,6 +13,7 @@ use std::{env, mem, str}; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_metadata::find_native_static_library; use rustc_middle::middle::dependency_format::Linkage; +use rustc_middle::middle::exported_symbols; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; @@ -659,8 +660,6 @@ impl<'a> Linker for GccLinker<'a> { 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" }); @@ -1679,8 +1678,15 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St return exports.iter().map(ToString::to_string).collect(); } - let mut symbols = Vec::new(); + if let CrateType::ProcMacro = crate_type { + exported_symbols_for_proc_macro_crate(tcx) + } else { + exported_symbols_for_non_proc_macro(tcx, crate_type) + } +} +fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> { + let mut symbols = Vec::new(); let export_threshold = symbol_export::crates_export_threshold(&[crate_type]); for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| { if info.level.is_below_threshold(export_threshold) { @@ -1691,6 +1697,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St symbols } +fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> { + let mut symbols = Vec::new(); + + let stable_crate_id = tcx.sess.local_stable_crate_id(); + let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id); + let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx); + + // You would think that both the two names would always be there, but in + // pnkfelix's local experiments that was not case. So instead we walk the + // list and only add them if they *are* there. + for_each_exported_symbols_include_dep(tcx, CrateType::ProcMacro, |symbol, _info, cnum| { + let name = symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum); + if name == proc_macro_decls_name || name == metadata_symbol_name { + symbols.push(name); + } + }); + + return symbols; +} + pub(crate) fn linked_symbols( tcx: TyCtxt<'_>, crate_type: CrateType, |
