Skip to content

Commit f5ab4d4

Browse files
Don't show crate metadata symbol as exported symbol to downstream crates.
1 parent 9f6d554 commit f5ab4d4

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

src/librustc/middle/exported_symbols.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use hir::def_id::DefId;
11+
use hir::def_id::{DefId, LOCAL_CRATE};
1212
use std::cmp;
1313
use ty;
1414

@@ -87,3 +87,9 @@ impl_stable_hash_for!(enum self::ExportedSymbol {
8787
NonGeneric(def_id),
8888
NoDefId(symbol_name)
8989
});
90+
91+
pub fn metadata_symbol_name(tcx: ty::TyCtxt) -> String {
92+
format!("rust_metadata_{}_{}",
93+
tcx.original_crate_name(LOCAL_CRATE),
94+
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
95+
}

src/librustc_metadata/encoder.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LOCAL_CRATE
2020
use rustc::hir::map::definitions::DefPathTable;
2121
use rustc::ich::Fingerprint;
2222
use rustc::middle::dependency_format::Linkage;
23-
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
23+
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel,
24+
metadata_symbol_name};
2425
use rustc::middle::lang_items;
2526
use rustc::mir;
2627
use rustc::traits::specialization_graph;
27-
use rustc::ty::{self, Ty, TyCtxt, ReprOptions};
28+
use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName};
2829
use rustc::ty::codec::{self as ty_codec, TyEncoder};
2930

3031
use rustc::session::config::{self, CrateTypeProcMacro};
@@ -1392,7 +1393,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
13921393
fn encode_exported_symbols(&mut self,
13931394
exported_symbols: &[(ExportedSymbol, SymbolExportLevel)])
13941395
-> LazySeq<(ExportedSymbol, SymbolExportLevel)> {
1395-
self.lazy_seq(exported_symbols.iter().cloned())
1396+
1397+
// The metadata symbol name is special. It should not show up in
1398+
// downstream crates.
1399+
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
1400+
1401+
self.lazy_seq(exported_symbols
1402+
.iter()
1403+
.filter(|&&(ref exported_symbol, _)| {
1404+
match *exported_symbol {
1405+
ExportedSymbol::NoDefId(symbol_name) => {
1406+
symbol_name != metadata_symbol_name
1407+
},
1408+
_ => true,
1409+
}
1410+
})
1411+
.cloned())
13961412
}
13971413

13981414
fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {

src/librustc_trans/back/symbol_export.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use monomorphize::Instance;
1515
use rustc::hir;
1616
use rustc::hir::def_id::CrateNum;
1717
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
18-
use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
18+
use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadata_symbol_name};
1919
use rustc::session::config;
2020
use rustc::ty::{TyCtxt, SymbolName};
2121
use rustc::ty::maps::Providers;
@@ -32,12 +32,6 @@ pub fn threshold(tcx: TyCtxt) -> SymbolExportLevel {
3232
crates_export_threshold(&tcx.sess.crate_types.borrow())
3333
}
3434

35-
pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
36-
format!("rust_metadata_{}_{}",
37-
tcx.crate_name(LOCAL_CRATE),
38-
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
39-
}
40-
4135
fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel {
4236
match crate_type {
4337
config::CrateTypeExecutable |

src/librustc_trans/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use super::ModuleKind;
3030

3131
use abi;
3232
use back::link;
33-
use back::symbol_export;
3433
use back::write::{self, OngoingCrateTranslation, create_target_machine};
3534
use llvm::{ContextRef, ModuleRef, ValueRef, Vector, get_param};
3635
use llvm;
@@ -45,6 +44,7 @@ use rustc::ty::maps::Providers;
4544
use rustc::dep_graph::{DepNode, DepConstructor};
4645
use rustc::ty::subst::Kind;
4746
use rustc::middle::cstore::{self, LinkMeta, LinkagePreference};
47+
use rustc::middle::exported_symbols;
4848
use rustc::util::common::{time, print_time_passes_entry};
4949
use rustc::session::config::{self, NoDebugInfo};
5050
use rustc::session::Session;
@@ -654,7 +654,7 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
654654

655655
let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
656656
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
657-
let name = symbol_export::metadata_symbol_name(tcx);
657+
let name = exported_symbols::metadata_symbol_name(tcx);
658658
let buf = CString::new(name).unwrap();
659659
let llglobal = unsafe {
660660
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr())

0 commit comments

Comments
 (0)