Skip to content

Commit 7cecab3

Browse files
authored
Unrolled build for #145055
Rollup merge of #145055 - bjorn3:move_metadata_symbol_export, r=saethlin Move metadata symbol export from exported_non_generic_symbols to exported_symbols The metadata symbol must not be encoded in the crate metadata, and must be exported from proc-macros. Handling the export of the metadata symbol in exported_symbols handles both things at once without requiring manual fixups elsewhere.
2 parents 67d45f4 + 186cef0 commit 7cecab3

File tree

3 files changed

+12
-38
lines changed

3 files changed

+12
-38
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,11 +1805,18 @@ pub(crate) fn exported_symbols(
18051805
.collect();
18061806
}
18071807

1808-
if let CrateType::ProcMacro = crate_type {
1808+
let mut symbols = if let CrateType::ProcMacro = crate_type {
18091809
exported_symbols_for_proc_macro_crate(tcx)
18101810
} else {
18111811
exported_symbols_for_non_proc_macro(tcx, crate_type)
1812+
};
1813+
1814+
if crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro {
1815+
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
1816+
symbols.push((metadata_symbol_name, SymbolExportKind::Data));
18121817
}
1818+
1819+
symbols
18131820
}
18141821

18151822
fn exported_symbols_for_non_proc_macro(
@@ -1842,12 +1849,8 @@ fn exported_symbols_for_proc_macro_crate(tcx: TyCtxt<'_>) -> Vec<(String, Symbol
18421849

18431850
let stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
18441851
let proc_macro_decls_name = tcx.sess.generate_proc_macro_decls_symbol(stable_crate_id);
1845-
let metadata_symbol_name = exported_symbols::metadata_symbol_name(tcx);
18461852

1847-
vec![
1848-
(proc_macro_decls_name, SymbolExportKind::Data),
1849-
(metadata_symbol_name, SymbolExportKind::Data),
1850-
]
1853+
vec![(proc_macro_decls_name, SymbolExportKind::Data)]
18511854
}
18521855

18531856
pub(crate) fn linked_symbols(

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId};
88
use rustc_middle::bug;
99
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1010
use rustc_middle::middle::exported_symbols::{
11-
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, metadata_symbol_name,
11+
ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
1212
};
1313
use rustc_middle::query::LocalCrate;
1414
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
@@ -289,23 +289,6 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
289289
}));
290290
}
291291

292-
if tcx.crate_types().contains(&CrateType::Dylib)
293-
|| tcx.crate_types().contains(&CrateType::ProcMacro)
294-
{
295-
let symbol_name = metadata_symbol_name(tcx);
296-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
297-
298-
symbols.push((
299-
exported_symbol,
300-
SymbolExportInfo {
301-
level: SymbolExportLevel::C,
302-
kind: SymbolExportKind::Data,
303-
used: true,
304-
rustc_std_internal_symbol: false,
305-
},
306-
));
307-
}
308-
309292
// Sort so we get a stable incr. comp. hash.
310293
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));
311294

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ use rustc_hir::find_attr;
1919
use rustc_hir_pretty::id_to_string;
2020
use rustc_middle::dep_graph::WorkProductId;
2121
use rustc_middle::middle::dependency_format::Linkage;
22-
use rustc_middle::middle::exported_symbols::metadata_symbol_name;
2322
use rustc_middle::mir::interpret;
2423
use rustc_middle::query::Providers;
2524
use rustc_middle::traits::specialization_graph;
25+
use rustc_middle::ty::AssocItemContainer;
2626
use rustc_middle::ty::codec::TyEncoder;
2727
use rustc_middle::ty::fast_reject::{self, TreatParams};
28-
use rustc_middle::ty::{AssocItemContainer, SymbolName};
2928
use rustc_middle::{bug, span_bug};
3029
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque};
3130
use rustc_session::config::{CrateType, OptLevel, TargetModifier};
@@ -2207,19 +2206,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
22072206
exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)],
22082207
) -> LazyArray<(ExportedSymbol<'static>, SymbolExportInfo)> {
22092208
empty_proc_macro!(self);
2210-
// The metadata symbol name is special. It should not show up in
2211-
// downstream crates.
2212-
let metadata_symbol_name = SymbolName::new(self.tcx, &metadata_symbol_name(self.tcx));
22132209

2214-
self.lazy_array(
2215-
exported_symbols
2216-
.iter()
2217-
.filter(|&(exported_symbol, _)| match *exported_symbol {
2218-
ExportedSymbol::NoDefId(symbol_name) => symbol_name != metadata_symbol_name,
2219-
_ => true,
2220-
})
2221-
.cloned(),
2222-
)
2210+
self.lazy_array(exported_symbols.iter().cloned())
22232211
}
22242212

22252213
fn encode_dylib_dependency_formats(&mut self) -> LazyArray<Option<LinkagePreference>> {

0 commit comments

Comments
 (0)