about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-01 03:58:52 +0000
committerbors <bors@rust-lang.org>2022-08-01 03:58:52 +0000
commit25bb1c13bd472b75ceebee3b8dcf4dcbc431a8be (patch)
tree8e92c4599e20bcf41b53f8e21ac333653f348c51 /compiler/rustc_codegen_ssa/src
parent6423ab3a755fed97f75b2361849155d4e996d02f (diff)
parentb87f8a4d9c5b02be27d763bb76d66298f1c01ffe (diff)
downloadrust-25bb1c13bd472b75ceebee3b8dcf4dcbc431a8be.tar.gz
rust-25bb1c13bd472b75ceebee3b8dcf4dcbc431a8be.zip
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`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/linker.rs4
-rw-r--r--compiler/rustc_codegen_ssa/src/back/symbol_export.rs8
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..ce51b2e9531 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(#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" });
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,
             },
         ));
     }