Auto merge of #51966 - alexcrichton:llvm7, r=michaelwoerister
Upgrade to LLVM's master branch (LLVM 7) ### Current status ~~Blocked on a [performance regression](https://github.com/rust-lang/rust/pull/51966#issuecomment-402320576). The performance regression has an [upstream LLVM issue](https://bugs.llvm.org/show_bug.cgi?id=38047) and has also [been bisected](https://reviews.llvm.org/D44282) to an LLVM revision.~~ Ready to merge! --- This commit upgrades the main LLVM submodule to LLVM's current master branch. The LLD submodule is updated in tandem as well as compiler-builtins. Along the way support was also added for LLVM 7's new features. This primarily includes the support for custom section concatenation natively in LLD so we now add wasm custom sections in LLVM IR rather than having custom support in rustc itself for doing so. Some other miscellaneous changes are: * We now pass `--gc-sections` to `wasm-ld` * The optimization level is now passed to `wasm-ld` * A `--stack-first` option is passed to LLD to have stack overflow always cause a trap instead of corrupting static data * The wasm target for LLVM switched to `wasm32-unknown-unknown`. * The syntax for aligned pointers has changed in LLVM IR and tests are updated to reflect this. * ~~The `thumbv6m-none-eabi` target is disabled due to an [LLVM bug][llbug]~~ Nowadays we've been mostly only upgrading whenever there's a major release of LLVM but enough changes have been happening on the wasm target that there's been growing motivation for quite some time now to upgrade out version of LLD. To upgrade LLD, however, we need to upgrade LLVM to avoid needing to build yet another version of LLVM on the builders. The revision of LLVM in use here is arbitrarily chosen. We will likely need to continue to update it over time if and when we discover bugs. Once LLVM 7 is fully released we can switch to that channel as well. [llbug]: https://bugs.llvm.org/show_bug.cgi?id=37382 cc #50543
This commit is contained in:
commit
ae5b629efd
39 changed files with 202 additions and 198 deletions
|
@ -33,6 +33,7 @@ use back::link;
|
|||
use back::write::{self, OngoingCodegen, create_target_machine};
|
||||
use llvm::{ContextRef, ModuleRef, ValueRef, Vector, get_param};
|
||||
use llvm;
|
||||
use libc::c_uint;
|
||||
use metadata;
|
||||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc::middle::lang_items::StartFnLangItem;
|
||||
|
@ -74,10 +75,8 @@ use type_of::LayoutLlvmExt;
|
|||
use rustc::util::nodemap::{FxHashMap, FxHashSet, DefIdSet};
|
||||
use CrateInfo;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_target::spec::TargetTriple;
|
||||
|
||||
use std::any::Any;
|
||||
use std::collections::BTreeMap;
|
||||
use std::ffi::CString;
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
|
@ -1100,7 +1099,6 @@ impl CrateInfo {
|
|||
used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic),
|
||||
used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic),
|
||||
used_crate_source: FxHashMap(),
|
||||
wasm_custom_sections: BTreeMap::new(),
|
||||
wasm_imports: FxHashMap(),
|
||||
lang_item_to_crate: FxHashMap(),
|
||||
missing_lang_items: FxHashMap(),
|
||||
|
@ -1110,16 +1108,9 @@ impl CrateInfo {
|
|||
let load_wasm_items = tcx.sess.crate_types.borrow()
|
||||
.iter()
|
||||
.any(|c| *c != config::CrateTypeRlib) &&
|
||||
tcx.sess.opts.target_triple == TargetTriple::from_triple("wasm32-unknown-unknown");
|
||||
tcx.sess.opts.target_triple.triple() == "wasm32-unknown-unknown";
|
||||
|
||||
if load_wasm_items {
|
||||
info!("attempting to load all wasm sections");
|
||||
for &id in tcx.wasm_custom_sections(LOCAL_CRATE).iter() {
|
||||
let (name, contents) = fetch_wasm_section(tcx, id);
|
||||
info.wasm_custom_sections.entry(name)
|
||||
.or_insert(Vec::new())
|
||||
.extend(contents);
|
||||
}
|
||||
info.load_wasm_imports(tcx, LOCAL_CRATE);
|
||||
}
|
||||
|
||||
|
@ -1143,12 +1134,6 @@ impl CrateInfo {
|
|||
info.is_no_builtins.insert(cnum);
|
||||
}
|
||||
if load_wasm_items {
|
||||
for &id in tcx.wasm_custom_sections(cnum).iter() {
|
||||
let (name, contents) = fetch_wasm_section(tcx, id);
|
||||
info.wasm_custom_sections.entry(name)
|
||||
.or_insert(Vec::new())
|
||||
.extend(contents);
|
||||
}
|
||||
info.load_wasm_imports(tcx, cnum);
|
||||
}
|
||||
let missing = tcx.missing_lang_items(cnum);
|
||||
|
@ -1385,25 +1370,41 @@ mod temp_stable_hash_impls {
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch_wasm_section(tcx: TyCtxt, id: DefId) -> (String, Vec<u8>) {
|
||||
pub fn define_custom_section(cx: &CodegenCx, def_id: DefId) {
|
||||
use rustc::mir::interpret::GlobalId;
|
||||
|
||||
info!("loading wasm section {:?}", id);
|
||||
assert!(cx.tcx.sess.opts.target_triple.triple().starts_with("wasm32"));
|
||||
|
||||
let section = tcx.get_attrs(id)
|
||||
.iter()
|
||||
.find(|a| a.check_name("wasm_custom_section"))
|
||||
.expect("missing #[wasm_custom_section] attribute")
|
||||
.value_str()
|
||||
.expect("malformed #[wasm_custom_section] attribute");
|
||||
info!("loading wasm section {:?}", def_id);
|
||||
|
||||
let instance = ty::Instance::mono(tcx, id);
|
||||
let section = cx.tcx.codegen_fn_attrs(def_id).wasm_custom_section.unwrap();
|
||||
|
||||
let instance = ty::Instance::mono(cx.tcx, def_id);
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None
|
||||
};
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let val = tcx.const_eval(param_env.and(cid)).unwrap();
|
||||
let alloc = tcx.const_value_to_allocation(val);
|
||||
(section.to_string(), alloc.bytes.clone())
|
||||
let val = cx.tcx.const_eval(param_env.and(cid)).unwrap();
|
||||
let alloc = cx.tcx.const_value_to_allocation(val);
|
||||
|
||||
unsafe {
|
||||
let section = llvm::LLVMMDStringInContext(
|
||||
cx.llcx,
|
||||
section.as_str().as_ptr() as *const _,
|
||||
section.as_str().len() as c_uint,
|
||||
);
|
||||
let alloc = llvm::LLVMMDStringInContext(
|
||||
cx.llcx,
|
||||
alloc.bytes.as_ptr() as *const _,
|
||||
alloc.bytes.len() as c_uint,
|
||||
);
|
||||
let data = [section, alloc];
|
||||
let meta = llvm::LLVMMDNodeInContext(cx.llcx, data.as_ptr(), 2);
|
||||
llvm::LLVMAddNamedMetadataOperand(
|
||||
cx.llmod,
|
||||
"wasm.custom_sections\0".as_ptr() as *const _,
|
||||
meta,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue