@@ -13,6 +13,7 @@ use std::{env, mem, str};
13
13
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
14
14
use rustc_metadata:: find_native_static_library;
15
15
use rustc_middle:: middle:: dependency_format:: Linkage ;
16
+ use rustc_middle:: middle:: exported_symbols;
16
17
use rustc_middle:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportInfo , SymbolExportKind } ;
17
18
use rustc_middle:: ty:: TyCtxt ;
18
19
use rustc_session:: config:: { self , CrateType , DebugInfo , LinkerPluginLto , Lto , OptLevel , Strip } ;
@@ -659,8 +660,6 @@ impl<'a> Linker for GccLinker<'a> {
659
660
return ;
660
661
}
661
662
662
- // FIXME(#99978) hide #[no_mangle] symbols for proc-macros
663
-
664
663
let is_windows = self . sess . target . is_like_windows ;
665
664
let path = tmpdir. join ( if is_windows { "list.def" } else { "list" } ) ;
666
665
@@ -1679,8 +1678,15 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
1679
1678
return exports. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
1680
1679
}
1681
1680
1682
- let mut symbols = Vec :: new ( ) ;
1681
+ if let CrateType :: ProcMacro = crate_type {
1682
+ exported_symbols_for_proc_macro_crate ( tcx)
1683
+ } else {
1684
+ exported_symbols_for_non_proc_macro ( tcx, crate_type)
1685
+ }
1686
+ }
1683
1687
1688
+ fn exported_symbols_for_non_proc_macro ( tcx : TyCtxt < ' _ > , crate_type : CrateType ) -> Vec < String > {
1689
+ let mut symbols = Vec :: new ( ) ;
1684
1690
let export_threshold = symbol_export:: crates_export_threshold ( & [ crate_type] ) ;
1685
1691
for_each_exported_symbols_include_dep ( tcx, crate_type, |symbol, info, cnum| {
1686
1692
if info. level . is_below_threshold ( export_threshold) {
@@ -1691,6 +1697,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
1691
1697
symbols
1692
1698
}
1693
1699
1700
+ fn exported_symbols_for_proc_macro_crate ( tcx : TyCtxt < ' _ > ) -> Vec < String > {
1701
+ let mut symbols = Vec :: new ( ) ;
1702
+
1703
+ let stable_crate_id = tcx. sess . local_stable_crate_id ( ) ;
1704
+ let proc_macro_decls_name = tcx. sess . generate_proc_macro_decls_symbol ( stable_crate_id) ;
1705
+ let metadata_symbol_name = exported_symbols:: metadata_symbol_name ( tcx) ;
1706
+
1707
+ // You would think that both the two names would always be there, but in
1708
+ // pnkfelix's local experiments that was not case. So instead we walk the
1709
+ // list and only add them if they *are* there.
1710
+ for_each_exported_symbols_include_dep ( tcx, CrateType :: ProcMacro , |symbol, _info, cnum| {
1711
+ let name = symbol_export:: symbol_name_for_instance_in_crate ( tcx, symbol, cnum) ;
1712
+ if name == proc_macro_decls_name || name == metadata_symbol_name {
1713
+ symbols. push ( name) ;
1714
+ }
1715
+ } ) ;
1716
+
1717
+ return symbols;
1718
+ }
1719
+
1694
1720
pub ( crate ) fn linked_symbols (
1695
1721
tcx : TyCtxt < ' _ > ,
1696
1722
crate_type : CrateType ,
0 commit comments