Don't show crate metadata symbol as exported symbol to downstream crates.
This commit is contained in:
parent
9f6d554638
commit
f5ab4d4cdd
4 changed files with 29 additions and 13 deletions
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use hir::def_id::DefId;
|
||||
use hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use std::cmp;
|
||||
use ty;
|
||||
|
||||
|
@ -87,3 +87,9 @@ impl_stable_hash_for!(enum self::ExportedSymbol {
|
|||
NonGeneric(def_id),
|
||||
NoDefId(symbol_name)
|
||||
});
|
||||
|
||||
pub fn metadata_symbol_name(tcx: ty::TyCtxt) -> String {
|
||||
format!("rust_metadata_{}_{}",
|
||||
tcx.original_crate_name(LOCAL_CRATE),
|
||||
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
|
||||
}
|
||||
|
|
|
@ -20,11 +20,12 @@ use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LOCAL_CRATE
|
|||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::ich::Fingerprint;
|
||||
use rustc::middle::dependency_format::Linkage;
|
||||
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
||||
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel,
|
||||
metadata_symbol_name};
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::mir;
|
||||
use rustc::traits::specialization_graph;
|
||||
use rustc::ty::{self, Ty, TyCtxt, ReprOptions};
|
||||
use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName};
|
||||
use rustc::ty::codec::{self as ty_codec, TyEncoder};
|
||||
|
||||
use rustc::session::config::{self, CrateTypeProcMacro};
|
||||
|
@ -1392,7 +1393,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
fn encode_exported_symbols(&mut self,
|
||||
exported_symbols: &[(ExportedSymbol, SymbolExportLevel)])
|
||||
-> LazySeq<(ExportedSymbol, SymbolExportLevel)> {
|
||||
self.lazy_seq(exported_symbols.iter().cloned())
|
||||
|
||||
// The metadata symbol name is special. It should not show up in
|
||||
// downstream crates.
|
||||
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
|
||||
|
||||
self.lazy_seq(exported_symbols
|
||||
.iter()
|
||||
.filter(|&&(ref exported_symbol, _)| {
|
||||
match *exported_symbol {
|
||||
ExportedSymbol::NoDefId(symbol_name) => {
|
||||
symbol_name != metadata_symbol_name
|
||||
},
|
||||
_ => true,
|
||||
}
|
||||
})
|
||||
.cloned())
|
||||
}
|
||||
|
||||
fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {
|
||||
|
|
|
@ -15,7 +15,7 @@ use monomorphize::Instance;
|
|||
use rustc::hir;
|
||||
use rustc::hir::def_id::CrateNum;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
|
||||
use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadata_symbol_name};
|
||||
use rustc::session::config;
|
||||
use rustc::ty::{TyCtxt, SymbolName};
|
||||
use rustc::ty::maps::Providers;
|
||||
|
@ -32,12 +32,6 @@ pub fn threshold(tcx: TyCtxt) -> SymbolExportLevel {
|
|||
crates_export_threshold(&tcx.sess.crate_types.borrow())
|
||||
}
|
||||
|
||||
pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
|
||||
format!("rust_metadata_{}_{}",
|
||||
tcx.crate_name(LOCAL_CRATE),
|
||||
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
|
||||
}
|
||||
|
||||
fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel {
|
||||
match crate_type {
|
||||
config::CrateTypeExecutable |
|
||||
|
|
|
@ -30,7 +30,6 @@ use super::ModuleKind;
|
|||
|
||||
use abi;
|
||||
use back::link;
|
||||
use back::symbol_export;
|
||||
use back::write::{self, OngoingCrateTranslation, create_target_machine};
|
||||
use llvm::{ContextRef, ModuleRef, ValueRef, Vector, get_param};
|
||||
use llvm;
|
||||
|
@ -45,6 +44,7 @@ use rustc::ty::maps::Providers;
|
|||
use rustc::dep_graph::{DepNode, DepConstructor};
|
||||
use rustc::ty::subst::Kind;
|
||||
use rustc::middle::cstore::{self, LinkMeta, LinkagePreference};
|
||||
use rustc::middle::exported_symbols;
|
||||
use rustc::util::common::{time, print_time_passes_entry};
|
||||
use rustc::session::config::{self, NoDebugInfo};
|
||||
use rustc::session::Session;
|
||||
|
@ -654,7 +654,7 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
|
|||
|
||||
let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
|
||||
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
|
||||
let name = symbol_export::metadata_symbol_name(tcx);
|
||||
let name = exported_symbols::metadata_symbol_name(tcx);
|
||||
let buf = CString::new(name).unwrap();
|
||||
let llglobal = unsafe {
|
||||
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr())
|
||||
|
|
Loading…
Add table
Reference in a new issue