diff options
| author | bors <bors@rust-lang.org> | 2023-08-12 03:05:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-12 03:05:01 +0000 |
| commit | d1fa3e4de38d117c94e1cf0807ed629f679e0cab (patch) | |
| tree | 3559e983bf46807f9e245684d15b160155c08ae1 /compiler/rustc_codegen_ssa | |
| parent | d8fd588afa24f6fa5259a01b815912710713d62f (diff) | |
| parent | 4d0501412a3216ee4a495e071f4b5fdf43f56c4e (diff) | |
Auto merge of #114748 - cuviper:beta-next, r=cuviper
[beta] backport * Restrict linker version script of proc-macro crates to just its two symbols #114470 * bootstrap: config: fix version comparison bug #114440 * lint/ctypes: only try normalize #113921 * Avoid tls access while iterating through mpsc thread entries #113861 * Substitute types before checking inlining compatibility. #113802 * Revert "fix: bug etc/bash_complettion -> src/etc/... to avoid copy error" #113579 * lint/ctypes: fix () return type checks #113457 * Rename and allow cast_ref_to_mut lint #113422 * Ignore flaky clippy tests. #113621 r? cuviper
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index cd56f85cccd..8ac86fa4b26 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,19 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St symbols } +fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<String> { + // `exported_symbols` will be empty when !should_codegen. + if !tcx.sess.opts.output_types.should_codegen() { + return 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); + + vec![proc_macro_decls_name, metadata_symbol_name] +} + pub(crate) fn linked_symbols( tcx: TyCtxt<'_>, crate_type: CrateType, |
