refactor metadata_symbol_name

This commit is contained in:
Niko Matsakis 2017-04-13 18:08:36 -04:00
parent 8e26983c86
commit f2487b8152
3 changed files with 10 additions and 9 deletions

View File

@ -15,6 +15,7 @@ use back::symbol_names::symbol_name;
use util::nodemap::FxHashMap; use util::nodemap::FxHashMap;
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use rustc::session::config; use rustc::session::config;
use rustc::ty::TyCtxt;
use syntax::attr; use syntax::attr;
use trans_item::TransItem; use trans_item::TransItem;
@ -72,7 +73,7 @@ impl ExportedSymbols {
} }
if scx.sess().crate_types.borrow().contains(&config::CrateTypeDylib) { if scx.sess().crate_types.borrow().contains(&config::CrateTypeDylib) {
local_crate.push((scx.metadata_symbol_name(), local_crate.push((metadata_symbol_name(scx.tcx()),
SymbolExportLevel::Rust)); SymbolExportLevel::Rust));
} }
@ -173,6 +174,12 @@ impl ExportedSymbols {
} }
} }
pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
format!("rust_metadata_{}_{}",
tcx.crate_name(LOCAL_CRATE),
tcx.crate_disambiguator(LOCAL_CRATE))
}
pub fn crate_export_threshold(crate_type: config::CrateType) pub fn crate_export_threshold(crate_type: config::CrateType)
-> SymbolExportLevel { -> SymbolExportLevel {
match crate_type { match crate_type {

View File

@ -776,7 +776,7 @@ fn write_metadata(cx: &SharedCrateContext,
let llmeta = C_bytes_in_context(metadata_llcx, &compressed); let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false); let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
let name = cx.metadata_symbol_name(); let name = symbol_export::metadata_symbol_name(cx.tcx());
let buf = CString::new(name).unwrap(); let buf = CString::new(name).unwrap();
let llglobal = unsafe { let llglobal = unsafe {
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr()) llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr())

View File

@ -12,7 +12,7 @@ use llvm;
use llvm::{ContextRef, ModuleRef, ValueRef}; use llvm::{ContextRef, ModuleRef, ValueRef};
use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap, DepTrackingMapConfig}; use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap, DepTrackingMapConfig};
use rustc::hir; use rustc::hir;
use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::hir::def_id::DefId;
use rustc::traits; use rustc::traits;
use debuginfo; use debuginfo;
use callee; use callee;
@ -430,12 +430,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
pub fn translation_items(&self) -> &RefCell<FxHashSet<TransItem<'tcx>>> { pub fn translation_items(&self) -> &RefCell<FxHashSet<TransItem<'tcx>>> {
&self.translation_items &self.translation_items
} }
pub fn metadata_symbol_name(&self) -> String {
format!("rust_metadata_{}_{}",
self.tcx().crate_name(LOCAL_CRATE),
self.tcx().crate_disambiguator(LOCAL_CRATE))
}
} }
impl<'tcx> LocalCrateContext<'tcx> { impl<'tcx> LocalCrateContext<'tcx> {