diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-07-30 12:16:33 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2022-07-30 12:16:33 +0000 |
| commit | 6098e795a20f03654ab967a3705a495454abb05b (patch) | |
| tree | 51e4551e46d31600c559ccb2b46a5300999032c5 /compiler/rustc_codegen_ssa | |
| parent | 760d8a2cb169974971cb54302c857bfed0070f6e (diff) | |
| download | rust-6098e795a20f03654ab967a3705a495454abb05b.tar.gz rust-6098e795a20f03654ab967a3705a495454abb05b.zip | |
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.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index a4bbdefbb87..3d77ddc3f84 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -656,9 +656,7 @@ impl<'a> Linker for GccLinker<'a> { return; } - if crate_type == CrateType::ProcMacro { - return; - } + // FIXME 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" }); diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index d1a267f7643..e6b6055759d 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -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, }, )); } |
