remove metadata_*
from SharedCrateContext
No good reason for them to be in there.
This commit is contained in:
parent
ea376822a1
commit
15507bcb64
@ -32,7 +32,7 @@ use assert_module_sources;
|
||||
use back::link;
|
||||
use back::linker::LinkerInfo;
|
||||
use back::symbol_export::{self, ExportedSymbols};
|
||||
use llvm::{Linkage, ValueRef, Vector, get_param};
|
||||
use llvm::{ContextRef, Linkage, ModuleRef, ValueRef, Vector, get_param};
|
||||
use llvm;
|
||||
use rustc::hir::def_id::LOCAL_CRATE;
|
||||
use middle::lang_items::StartFnLangItem;
|
||||
@ -56,7 +56,7 @@ use common::CrateContext;
|
||||
use common::{type_is_zero_size, val_ty};
|
||||
use common;
|
||||
use consts;
|
||||
use context::{SharedCrateContext, CrateContextList};
|
||||
use context::{self, SharedCrateContext, CrateContextList};
|
||||
use debuginfo;
|
||||
use declare;
|
||||
use machine;
|
||||
@ -726,9 +726,13 @@ fn contains_null(s: &str) -> bool {
|
||||
|
||||
fn write_metadata(cx: &SharedCrateContext,
|
||||
exported_symbols: &NodeSet)
|
||||
-> EncodedMetadata {
|
||||
-> (ContextRef, ModuleRef, EncodedMetadata) {
|
||||
use flate;
|
||||
|
||||
let (metadata_llcx, metadata_llmod) = unsafe {
|
||||
context::create_context_and_module(cx.sess(), "metadata")
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
enum MetadataKind {
|
||||
None,
|
||||
@ -750,10 +754,10 @@ fn write_metadata(cx: &SharedCrateContext,
|
||||
}).max().unwrap();
|
||||
|
||||
if kind == MetadataKind::None {
|
||||
return EncodedMetadata {
|
||||
return (metadata_llcx, metadata_llmod, EncodedMetadata {
|
||||
raw_data: vec![],
|
||||
hashes: vec![],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
let cstore = &cx.tcx().sess.cstore;
|
||||
@ -761,19 +765,19 @@ fn write_metadata(cx: &SharedCrateContext,
|
||||
cx.link_meta(),
|
||||
exported_symbols);
|
||||
if kind == MetadataKind::Uncompressed {
|
||||
return metadata;
|
||||
return (metadata_llcx, metadata_llmod, metadata);
|
||||
}
|
||||
|
||||
assert!(kind == MetadataKind::Compressed);
|
||||
let mut compressed = cstore.metadata_encoding_version().to_vec();
|
||||
compressed.extend_from_slice(&flate::deflate_bytes(&metadata.raw_data));
|
||||
|
||||
let llmeta = C_bytes_in_context(cx.metadata_llcx(), &compressed);
|
||||
let llconst = C_struct_in_context(cx.metadata_llcx(), &[llmeta], false);
|
||||
let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
|
||||
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
|
||||
let name = cx.metadata_symbol_name();
|
||||
let buf = CString::new(name).unwrap();
|
||||
let llglobal = unsafe {
|
||||
llvm::LLVMAddGlobal(cx.metadata_llmod(), val_ty(llconst).to_ref(), buf.as_ptr())
|
||||
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst).to_ref(), buf.as_ptr())
|
||||
};
|
||||
unsafe {
|
||||
llvm::LLVMSetInitializer(llglobal, llconst);
|
||||
@ -787,9 +791,9 @@ fn write_metadata(cx: &SharedCrateContext,
|
||||
// metadata doesn't get loaded into memory.
|
||||
let directive = format!(".section {}", section_name);
|
||||
let directive = CString::new(directive).unwrap();
|
||||
llvm::LLVMSetModuleInlineAsm(cx.metadata_llmod(), directive.as_ptr())
|
||||
llvm::LLVMSetModuleInlineAsm(metadata_llmod, directive.as_ptr())
|
||||
}
|
||||
return metadata;
|
||||
return (metadata_llcx, metadata_llmod, metadata);
|
||||
}
|
||||
|
||||
/// Find any symbols that are defined in one compilation unit, but not declared
|
||||
@ -1070,16 +1074,17 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
exported_symbols,
|
||||
check_overflow);
|
||||
// Translate the metadata.
|
||||
let metadata = time(tcx.sess.time_passes(), "write metadata", || {
|
||||
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
|
||||
});
|
||||
let (metadata_llcx, metadata_llmod, metadata) =
|
||||
time(tcx.sess.time_passes(), "write metadata", || {
|
||||
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
|
||||
});
|
||||
|
||||
let metadata_module = ModuleTranslation {
|
||||
name: link::METADATA_MODULE_NAME.to_string(),
|
||||
symbol_name_hash: 0, // we always rebuild metadata, at least for now
|
||||
source: ModuleSource::Translated(ModuleLlvm {
|
||||
llcx: shared_ccx.metadata_llcx(),
|
||||
llmod: shared_ccx.metadata_llmod(),
|
||||
llcx: metadata_llcx,
|
||||
llmod: metadata_llmod,
|
||||
}),
|
||||
};
|
||||
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
|
||||
|
@ -65,9 +65,6 @@ pub struct Stats {
|
||||
/// crate, so it must not contain references to any LLVM data structures
|
||||
/// (aside from metadata-related ones).
|
||||
pub struct SharedCrateContext<'a, 'tcx: 'a> {
|
||||
metadata_llmod: ModuleRef,
|
||||
metadata_llcx: ContextRef,
|
||||
|
||||
exported_symbols: NodeSet,
|
||||
link_meta: LinkMeta,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
@ -347,7 +344,7 @@ pub fn is_pie_binary(sess: &Session) -> bool {
|
||||
!is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
|
||||
}
|
||||
|
||||
unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
|
||||
pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
|
||||
let llcx = llvm::LLVMContextCreate();
|
||||
let mod_name = CString::new(mod_name).unwrap();
|
||||
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
|
||||
@ -409,10 +406,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
exported_symbols: NodeSet,
|
||||
check_overflow: bool)
|
||||
-> SharedCrateContext<'b, 'tcx> {
|
||||
let (metadata_llcx, metadata_llmod) = unsafe {
|
||||
create_context_and_module(&tcx.sess, "metadata")
|
||||
};
|
||||
|
||||
// An interesting part of Windows which MSVC forces our hand on (and
|
||||
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
|
||||
// attributes in LLVM IR as well as native dependencies (in C these
|
||||
@ -459,8 +452,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
|
||||
|
||||
SharedCrateContext {
|
||||
metadata_llmod: metadata_llmod,
|
||||
metadata_llcx: metadata_llcx,
|
||||
exported_symbols: exported_symbols,
|
||||
link_meta: link_meta,
|
||||
empty_param_env: tcx.empty_parameter_environment(),
|
||||
@ -492,14 +483,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
ty.is_sized(self.tcx, &self.empty_param_env, DUMMY_SP)
|
||||
}
|
||||
|
||||
pub fn metadata_llmod(&self) -> ModuleRef {
|
||||
self.metadata_llmod
|
||||
}
|
||||
|
||||
pub fn metadata_llcx(&self) -> ContextRef {
|
||||
self.metadata_llcx
|
||||
}
|
||||
|
||||
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
|
||||
&self.exported_symbols
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user