From c327a4258084e34412fc6ee94f82276adb3e1069 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 26 Aug 2021 21:58:34 +0300 Subject: [PATCH 01/91] ty::layout: intern `FnAbi`s as `&'tcx`. --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 6f7ca51d038..06d1fc717cc 100644 --- a/src/common.rs +++ b/src/common.rs @@ -239,7 +239,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) instance: Instance<'tcx>, pub(crate) symbol_name: SymbolName<'tcx>, pub(crate) mir: &'tcx Body<'tcx>, - pub(crate) fn_abi: Option>>, + pub(crate) fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>, pub(crate) bcx: FunctionBuilder<'clif>, pub(crate) block_map: IndexVec, From bdb56872b7c416bfff3ddf19a7c4cd71e460c5c2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 2 Sep 2021 00:09:34 +0300 Subject: [PATCH 02/91] ty::layout: replicate `layout_of` setup for `fn_abi_of_{fn_ptr,instance}`. --- src/abi/mod.rs | 12 +++++----- src/base.rs | 5 ++--- src/common.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++- src/constant.rs | 4 +--- src/pretty_clif.rs | 5 ++--- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 13790409e59..6317e1d5d1a 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -5,7 +5,7 @@ mod pass_mode; mod returning; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use rustc_middle::ty::layout::FnAbiExt; +use rustc_middle::ty::layout::FnAbiOf; use rustc_target::abi::call::{Conv, FnAbi}; use rustc_target::spec::abi::Abi; @@ -53,7 +53,7 @@ pub(crate) fn get_function_sig<'tcx>( inst: Instance<'tcx>, ) -> Signature { assert!(!inst.substs.needs_infer()); - clif_sig_from_fn_abi(tcx, triple, &FnAbi::of_instance(&RevealAllLayoutCx(tcx), inst, &[])) + clif_sig_from_fn_abi(tcx, triple, &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, &[])) } /// Instance must be monomorphized @@ -355,9 +355,9 @@ pub(crate) fn codegen_terminator_call<'tcx>( .map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))) .collect::>(); let fn_abi = if let Some(instance) = instance { - FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), instance, &extra_args) + RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, &extra_args) } else { - FnAbi::of_fn_ptr(&RevealAllLayoutCx(fx.tcx), fn_ty.fn_sig(fx.tcx), &extra_args) + RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), &extra_args) }; let is_cold = instance @@ -525,7 +525,7 @@ pub(crate) fn codegen_drop<'tcx>( def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0), substs: drop_instance.substs, }; - let fn_abi = FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), virtual_drop, &[]); + let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, &[]); let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi); let sig = fx.bcx.import_signature(sig); @@ -534,7 +534,7 @@ pub(crate) fn codegen_drop<'tcx>( _ => { assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _))); - let fn_abi = FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), drop_instance, &[]); + let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, &[]); let arg_value = drop_place.place_ref( fx, diff --git a/src/base.rs b/src/base.rs index d29558a4e1f..872c7edc791 100644 --- a/src/base.rs +++ b/src/base.rs @@ -3,8 +3,7 @@ use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_index::vec::IndexVec; use rustc_middle::ty::adjustment::PointerCast; -use rustc_middle::ty::layout::FnAbiExt; -use rustc_target::abi::call::FnAbi; +use rustc_middle::ty::layout::FnAbiOf; use crate::constant::ConstantCx; use crate::prelude::*; @@ -62,7 +61,7 @@ pub(crate) fn codegen_fn<'tcx>( instance, symbol_name, mir, - fn_abi: Some(FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])), + fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])), bcx, block_map, diff --git a/src/common.rs b/src/common.rs index 06d1fc717cc..4a8be89460f 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,7 @@ use rustc_index::vec::IndexVec; -use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers}; +use rustc_middle::ty::layout::{ + FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, +}; use rustc_middle::ty::SymbolName; use rustc_target::abi::call::FnAbi; use rustc_target::abi::{Integer, Primitive}; @@ -266,6 +268,20 @@ impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { } } +impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { + type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>; + + #[inline] + fn handle_fn_abi_err( + &self, + err: FnAbiError<'tcx>, + span: Span, + fn_abi_request: FnAbiRequest<'_, 'tcx>, + ) -> ! { + RevealAllLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request) + } +} + impl<'tcx> layout::HasTyCtxt<'tcx> for FunctionCx<'_, '_, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'tcx> { self.tcx @@ -378,6 +394,43 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { } } +impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { + type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>; + + #[inline] + fn handle_fn_abi_err( + &self, + err: FnAbiError<'tcx>, + span: Span, + fn_abi_request: FnAbiRequest<'_, 'tcx>, + ) -> ! { + if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { + self.0.sess.span_fatal(span, &err.to_string()) + } else { + match fn_abi_request { + FnAbiRequest::OfFnPtr { sig, extra_args } => { + span_bug!( + span, + "`fn_abi_of_fn_ptr({}, {:?})` failed: {}", + sig, + extra_args, + err + ); + } + FnAbiRequest::OfInstance { instance, extra_args } => { + span_bug!( + span, + "`fn_abi_of_instance({}, {:?})` failed: {}", + instance, + extra_args, + err + ); + } + } + } + } +} + impl<'tcx> layout::HasTyCtxt<'tcx> for RevealAllLayoutCx<'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'tcx> { self.0 diff --git a/src/constant.rs b/src/constant.rs index 424a0d742d1..5c4991f1fb6 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -129,9 +129,7 @@ pub(crate) fn codegen_constant<'tcx>( }; let const_val = match const_.val { ConstKind::Value(const_val) => const_val, - ConstKind::Unevaluated(uv) - if fx.tcx.is_static(uv.def.did) => - { + ConstKind::Unevaluated(uv) if fx.tcx.is_static(uv.def.did) => { assert!(uv.substs(fx.tcx).is_empty()); assert!(uv.promoted.is_none()); diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 05db74745a1..0b80ef1c04e 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -61,9 +61,8 @@ use cranelift_codegen::{ write::{FuncWriter, PlainWriter}, }; -use rustc_middle::ty::layout::FnAbiExt; +use rustc_middle::ty::layout::FnAbiOf; use rustc_session::config::OutputType; -use rustc_target::abi::call::FnAbi; use crate::prelude::*; @@ -81,7 +80,7 @@ impl CommentWriter { vec![ format!("symbol {}", tcx.symbol_name(instance).name), format!("instance {:?}", instance), - format!("abi {:?}", FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])), + format!("abi {:?}", RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])), String::new(), ] } else { From 7389f91ea76aa91b12dad6997d1401e8fbd5aa50 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 2 Sep 2021 00:29:15 +0300 Subject: [PATCH 03/91] Querify `fn_abi_of_{fn_ptr,instance}`. --- src/abi/mod.rs | 23 ++++++++++++++--------- src/base.rs | 2 +- src/common.rs | 4 ++-- src/pretty_clif.rs | 5 ++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 6317e1d5d1a..15bb9067805 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -53,7 +53,11 @@ pub(crate) fn get_function_sig<'tcx>( inst: Instance<'tcx>, ) -> Signature { assert!(!inst.substs.needs_infer()); - clif_sig_from_fn_abi(tcx, triple, &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, &[])) + clif_sig_from_fn_abi( + tcx, + triple, + &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()), + ) } /// Instance must be monomorphized @@ -350,14 +354,13 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; let extra_args = &args[fn_sig.inputs().len()..]; - let extra_args = extra_args - .iter() - .map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))) - .collect::>(); + let extra_args = fx + .tcx + .mk_type_list(extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx)))); let fn_abi = if let Some(instance) = instance { - RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, &extra_args) + RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args) } else { - RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), &extra_args) + RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), extra_args) }; let is_cold = instance @@ -525,7 +528,8 @@ pub(crate) fn codegen_drop<'tcx>( def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0), substs: drop_instance.substs, }; - let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, &[]); + let fn_abi = + RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty()); let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi); let sig = fx.bcx.import_signature(sig); @@ -534,7 +538,8 @@ pub(crate) fn codegen_drop<'tcx>( _ => { assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _))); - let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, &[]); + let fn_abi = + RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty()); let arg_value = drop_place.place_ref( fx, diff --git a/src/base.rs b/src/base.rs index 872c7edc791..d8fa2c76904 100644 --- a/src/base.rs +++ b/src/base.rs @@ -61,7 +61,7 @@ pub(crate) fn codegen_fn<'tcx>( instance, symbol_name, mir, - fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])), + fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())), bcx, block_map, diff --git a/src/common.rs b/src/common.rs index 4a8be89460f..0e84681d9ad 100644 --- a/src/common.rs +++ b/src/common.rs @@ -276,7 +276,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { &self, err: FnAbiError<'tcx>, span: Span, - fn_abi_request: FnAbiRequest<'_, 'tcx>, + fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { RevealAllLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request) } @@ -402,7 +402,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> { &self, err: FnAbiError<'tcx>, span: Span, - fn_abi_request: FnAbiRequest<'_, 'tcx>, + fn_abi_request: FnAbiRequest<'tcx>, ) -> ! { if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err { self.0.sess.span_fatal(span, &err.to_string()) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 0b80ef1c04e..ec846d71960 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -80,7 +80,10 @@ impl CommentWriter { vec![ format!("symbol {}", tcx.symbol_name(instance).name), format!("instance {:?}", instance), - format!("abi {:?}", RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, &[])), + format!( + "abi {:?}", + RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()) + ), String::new(), ] } else { From b6b1a239729c05fd398e0e39670210811d40adaf Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 19 Sep 2021 13:56:58 +0200 Subject: [PATCH 04/91] Merge commit 'c66d21c78cb52efdd81e03d0f263de8a4c1448d9' into sync_cg_clif-2021-09-19 --- .gitignore | 2 +- Cargo.lock | 40 ++--- build_sysroot/Cargo.lock | 41 +++-- build_system/prepare.rs | 10 +- clean_all.sh | 2 +- docs/usage.md | 2 + example/alloc_example.rs | 2 +- example/mini_core_hello_world.rs | 2 +- ...able-simd-Disable-unsupported-tests.patch} | 51 +++--- ...027-sysroot-128bit-atomic-operations.patch | 41 ++++- rust-toolchain | 2 +- scripts/test_rustc_tests.sh | 2 +- scripts/tests.sh | 4 +- src/archive.rs | 74 +++++---- src/backend.rs | 152 ------------------ src/bin/cg_clif.rs | 3 + src/bin/cg_clif_build_sysroot.rs | 4 +- src/debuginfo/emit.rs | 6 +- src/debuginfo/mod.rs | 1 + src/debuginfo/object.rs | 85 ++++++++++ src/debuginfo/unwind.rs | 5 +- src/driver/aot.rs | 23 ++- src/lib.rs | 4 +- src/metadata.rs | 68 +++++++- 24 files changed, 332 insertions(+), 294 deletions(-) rename patches/{0001-stdsimd-Disable-unsupported-tests.patch => 0001-portable-simd-Disable-unsupported-tests.patch} (77%) delete mode 100644 src/backend.rs create mode 100644 src/debuginfo/object.rs diff --git a/.gitignore b/.gitignore index 25080488a88..b6567aca786 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ perf.data.old /rand /regex /simple-raytracer -/stdsimd +/portable-simd diff --git a/Cargo.lock b/Cargo.lock index 23c1fdc6ee4..4afddf76869 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,16 +33,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -57,8 +57,8 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -66,18 +66,18 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" [[package]] name = "cranelift-entity" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" [[package]] name = "cranelift-frontend" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "cranelift-codegen", "log", @@ -87,8 +87,8 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "anyhow", "cranelift-codegen", @@ -104,8 +104,8 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "anyhow", "cranelift-codegen", @@ -115,8 +115,8 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "cranelift-codegen", "libc", @@ -125,8 +125,8 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#5deda279775dca5e37449c829cda1f6276d6542b" +version = "0.76.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index e068f084234..22be21cb8de 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.14.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" +checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" dependencies = [ "compiler_builtins", "gimli", @@ -40,9 +40,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" +checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" [[package]] name = "cfg-if" @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.46" +version = "0.1.50" dependencies = [ "rustc-std-workspace-core", ] @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" +checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -132,13 +132,23 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.98" +version = "0.2.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-core", +] + [[package]] name = "miniz_oxide" version = "0.4.4" @@ -154,11 +164,12 @@ dependencies = [ [[package]] name = "object" -version = "0.22.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" dependencies = [ "compiler_builtins", + "memchr", "rustc-std-workspace-alloc", "rustc-std-workspace-core", ] @@ -195,9 +206,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", @@ -286,9 +297,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4b2051b605a..ae9a35048bd 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -28,11 +28,11 @@ pub(crate) fn prepare() { ); clone_repo( - "stdsimd", - "https://github.com/rust-lang/stdsimd", - "be96995d8ddec03fac9a0caf4d4c51c7fbc33507", + "portable-simd", + "https://github.com/rust-lang/portable-simd", + "8cf7a62e5d2552961df51e5200aaa5b7c890a4bf", ); - apply_patches("stdsimd", Path::new("stdsimd")); + apply_patches("portable-simd", Path::new("portable-simd")); clone_repo( "simple-raytracer", @@ -92,7 +92,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.46", + "0.1.50", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/clean_all.sh b/clean_all.sh index 23e5bf2e0a8..865de7d234f 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -3,4 +3,4 @@ set -e rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} rm -rf target/ build/ perf.data{,.old} -rm -rf rand/ regex/ simple-raytracer/ stdsimd/ +rm -rf rand/ regex/ simple-raytracer/ portable-simd/ diff --git a/docs/usage.md b/docs/usage.md index 87eec0e818b..bcc5745d9d1 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -24,6 +24,8 @@ $ $cg_clif_dir/build/bin/cg_clif my_crate.rs ## Jit mode +> ⚠⚠⚠ The JIT mode is highly experimental. It may be slower than AOT compilation due to lack of incremental compilation. It may also be hard to setup if you have cargo dependencies. ⚠⚠⚠ + In jit mode cg_clif will immediately execute your code without creating an executable file. > This requires all dependencies to be available as dynamic library. diff --git a/example/alloc_example.rs b/example/alloc_example.rs index 2a9f7e58e01..d0d492e9674 100644 --- a/example/alloc_example.rs +++ b/example/alloc_example.rs @@ -1,4 +1,4 @@ -#![feature(start, core_intrinsics, alloc_prelude, alloc_error_handler)] +#![feature(start, core_intrinsics, alloc_prelude, alloc_error_handler, box_syntax)] #![no_std] extern crate alloc; diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 6e13e4dcbfb..cbfdb3c44f3 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,4 +1,4 @@ -#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local)] +#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, box_syntax)] #![no_core] #![allow(dead_code, non_camel_case_types)] diff --git a/patches/0001-stdsimd-Disable-unsupported-tests.patch b/patches/0001-portable-simd-Disable-unsupported-tests.patch similarity index 77% rename from patches/0001-stdsimd-Disable-unsupported-tests.patch rename to patches/0001-portable-simd-Disable-unsupported-tests.patch index 731c60fda58..2e683694663 100644 --- a/patches/0001-stdsimd-Disable-unsupported-tests.patch +++ b/patches/0001-portable-simd-Disable-unsupported-tests.patch @@ -4,21 +4,20 @@ Date: Sun, 25 Jul 2021 18:39:31 +0200 Subject: [PATCH] Disable unsupported tests --- - crates/core_simd/src/array.rs | 2 ++ - crates/core_simd/src/lib.rs | 2 +- + crates/core_simd/src/vector.rs | 2 ++ crates/core_simd/src/math.rs | 4 ++++ crates/core_simd/tests/masks.rs | 12 ------------ crates/core_simd/tests/ops_macros.rs | 6 ++++++ crates/core_simd/tests/round.rs | 2 ++ 6 files changed, 15 insertions(+), 13 deletions(-) -diff --git a/crates/core_simd/src/array.rs b/crates/core_simd/src/array.rs +diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 25c5309..2b3d819 100644 ---- a/crates/core_simd/src/array.rs -+++ b/crates/core_simd/src/array.rs +--- a/crates/core_simd/src/vector.rs ++++ b/crates/core_simd/src/vector.rs @@ -22,6 +22,7 @@ where - #[must_use] - fn splat(val: Self::Scalar) -> Self; + self.0 + } + /* /// SIMD gather: construct a SIMD vector by reading from a slice, using potentially discontiguous indices. @@ -31,27 +30,14 @@ index 25c5309..2b3d819 100644 + */ } - macro_rules! impl_simdarray_for { -diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs -index a64904d..299eb11 100644 ---- a/crates/core_simd/src/lib.rs -+++ b/crates/core_simd/src/lib.rs -@@ -1,7 +1,7 @@ - #![no_std] - #![allow(incomplete_features)] - #![feature( -- const_generics, -+ const_generics, - platform_intrinsics, - repr_simd, - simd_ffi, + impl Copy for Simd diff --git a/crates/core_simd/src/math.rs b/crates/core_simd/src/math.rs index 7290a28..e394730 100644 --- a/crates/core_simd/src/math.rs +++ b/crates/core_simd/src/math.rs @@ -2,6 +2,7 @@ macro_rules! impl_uint_arith { - ($(($name:ident, $n:ident)),+) => { - $( impl $name where Self: crate::LanesAtMost32 { + ($($ty:ty),+) => { + $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { + /* /// Lanewise saturating add. @@ -66,8 +52,8 @@ index 7290a28..e394730 100644 } } @@ -46,6 +48,7 @@ macro_rules! impl_int_arith { - ($(($name:ident, $n:ident)),+) => { - $( impl $name where Self: crate::LanesAtMost32 { + ($($ty:ty),+) => { + $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { + /* /// Lanewise saturating add. @@ -85,21 +71,22 @@ diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs index 61d8e44..2bccae2 100644 --- a/crates/core_simd/tests/masks.rs +++ b/crates/core_simd/tests/masks.rs -@@ -67,18 +67,6 @@ macro_rules! test_mask_api { +@@ -67,19 +67,6 @@ macro_rules! test_mask_api { assert_eq!(int.to_array(), [-1, 0, 0, -1, 0, 0, -1, 0]); - assert_eq!(core_simd::$name::<8>::from_int(int), mask); + assert_eq!(core_simd::Mask::<$type, 8>::from_int(int), mask); } - +- #[cfg(feature = "generic_const_exprs")] - #[test] - fn roundtrip_bitmask_conversion() { - let values = [ - true, false, false, true, false, false, true, false, - true, true, false, false, false, false, false, true, - ]; -- let mask = core_simd::$name::<16>::from_array(values); +- let mask = core_simd::Mask::<$type, 16>::from_array(values); - let bitmask = mask.to_bitmask(); - assert_eq!(bitmask, [0b01001001, 0b10000011]); -- assert_eq!(core_simd::$name::<16>::from_bitmask(bitmask), mask); +- assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask); - } } } @@ -122,7 +109,7 @@ index cb39e73..fc0ebe1 100644 } + */ - fn sqrt() { + fn recip() { test_helpers::test_unary_elementwise( @@ -581,6 +585,7 @@ macro_rules! impl_float_tests { }); @@ -138,8 +125,8 @@ index cb39e73..fc0ebe1 100644 } + */ } - } - } + + #[cfg(feature = "std")] diff --git a/crates/core_simd/tests/round.rs b/crates/core_simd/tests/round.rs index 37044a7..4cdc6b7 100644 --- a/crates/core_simd/tests/round.rs diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch index cda8153083c..e2d07bd1267 100644 --- a/patches/0027-sysroot-128bit-atomic-operations.patch +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -1,4 +1,4 @@ -From 6a4e6f5dc8c8a529a822eb9b57f9e57519595439 Mon Sep 17 00:00:00 2001 +From ad7ffe71baba46865f2e65266ab025920dfdc20b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 18 Feb 2021 18:45:28 +0100 Subject: [PATCH] Disable 128bit atomic operations @@ -8,7 +8,8 @@ Cranelift doesn't support them yet library/core/src/panic/unwind_safe.rs | 6 ----- library/core/src/sync/atomic.rs | 38 --------------------------- library/core/tests/atomic.rs | 4 --- - 3 files changed, 48 deletions(-) + library/std/src/time/monotonic.rs | 6 +++-- + 4 files changed, 4 insertions(+), 50 deletions(-) diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs index 092b7cf..158cf71 100644 @@ -35,10 +36,10 @@ index 092b7cf..158cf71 100644 #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs -index 0194c58..25a0038 100644 +index d9de37e..8293fce 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs -@@ -2229,44 +2229,6 @@ atomic_int! { +@@ -2234,44 +2234,6 @@ atomic_int! { "AtomicU64::new(0)", u64 AtomicU64 ATOMIC_U64_INIT } @@ -98,6 +99,38 @@ index b735957..ea728b6 100644 #[cfg(target_has_atomic = "ptr")] assert_eq!(align_of::(), size_of::()); #[cfg(target_has_atomic = "ptr")] +diff --git a/library/std/src/time/monotonic.rs b/library/std/src/time/monotonic.rs +index fa96b7a..2854f9c 100644 +--- a/library/std/src/time/monotonic.rs ++++ b/library/std/src/time/monotonic.rs +@@ -5,7 +5,7 @@ pub(super) fn monotonize(raw: time::Instant) -> time::Instant { + inner::monotonize(raw) + } + +-#[cfg(all(target_has_atomic = "64", not(target_has_atomic = "128")))] ++#[cfg(target_has_atomic = "64")] + pub mod inner { + use crate::sync::atomic::AtomicU64; + use crate::sync::atomic::Ordering::*; +@@ -70,6 +70,7 @@ pub mod inner { + } + } + ++/* + #[cfg(target_has_atomic = "128")] + pub mod inner { + use crate::sync::atomic::AtomicU128; +@@ -94,8 +95,9 @@ pub mod inner { + ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap() + } + } ++*/ + +-#[cfg(not(any(target_has_atomic = "64", target_has_atomic = "128")))] ++#[cfg(not(target_has_atomic = "64"))] + pub mod inner { + use crate::cmp; + use crate::sys::time; -- 2.26.2.7.g19db9cfb68 diff --git a/rust-toolchain b/rust-toolchain index f074ebe7a42..360570b3ae7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-08-05" +channel = "nightly-2021-09-19" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 0ac49dd3574..b714d47fec2 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -11,7 +11,7 @@ pushd rust cargo install ripgrep rm -r src/test/ui/{extern/,panics/,unsized-locals/,thinlto/,simd*,*lto*.rs,linkage*,unwind-*.rs} || true -for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto" src/test/ui); do +for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// needs-asm-support" src/test/ui); do rm $test done diff --git a/scripts/tests.sh b/scripts/tests.sh index 0eef710239b..28a7980d661 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -137,8 +137,8 @@ function extended_sysroot_tests() { fi popd - pushd stdsimd - echo "[TEST] rust-lang/stdsimd" + pushd portable-simd + echo "[TEST] rust-lang/portable-simd" ../build/cargo clean ../build/cargo build --all-targets --target $TARGET_TRIPLE if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then diff --git a/src/archive.rs b/src/archive.rs index 0fa228fc944..8a1f6543990 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,17 +1,20 @@ //! Creation of ar archives like for the lib and staticlib crate type use std::collections::BTreeMap; +use std::convert::TryFrom; use std::fs::File; +use std::io::{self, Read, Seek}; use std::path::{Path, PathBuf}; use rustc_codegen_ssa::back::archive::ArchiveBuilder; use rustc_session::Session; -use object::{Object, ObjectSymbol, SymbolKind}; +use object::read::archive::ArchiveFile; +use object::{Object, ObjectSymbol, ReadCache, SymbolKind}; #[derive(Debug)] enum ArchiveEntry { - FromArchive { archive_index: usize, entry_index: usize }, + FromArchive { archive_index: usize, file_range: (u64, u64) }, File(PathBuf), } @@ -21,29 +24,28 @@ pub(crate) struct ArArchiveBuilder<'a> { use_gnu_style_archive: bool, no_builtin_ranlib: bool, - src_archives: Vec<(PathBuf, ar::Archive)>, + src_archives: Vec, // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at // the end of an archive for linkers to not get confused. - entries: Vec<(String, ArchiveEntry)>, + entries: Vec<(Vec, ArchiveEntry)>, } impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self { let (src_archives, entries) = if let Some(input) = input { - let mut archive = ar::Archive::new(File::open(input).unwrap()); + let read_cache = ReadCache::new(File::open(input).unwrap()); + let archive = ArchiveFile::parse(&read_cache).unwrap(); let mut entries = Vec::new(); - let mut i = 0; - while let Some(entry) = archive.next_entry() { + for entry in archive.members() { let entry = entry.unwrap(); entries.push(( - String::from_utf8(entry.header().identifier().to_vec()).unwrap(), - ArchiveEntry::FromArchive { archive_index: 0, entry_index: i }, + entry.name().to_vec(), + ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() }, )); - i += 1; } - (vec![(input.to_owned(), archive)], entries) + (vec![read_cache.into_inner()], entries) } else { (vec![], Vec::new()) }; @@ -61,21 +63,21 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } fn src_files(&mut self) -> Vec { - self.entries.iter().map(|(name, _)| name.clone()).collect() + self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect() } fn remove_file(&mut self, name: &str) { let index = self .entries .iter() - .position(|(entry_name, _)| entry_name == name) + .position(|(entry_name, _)| entry_name == name.as_bytes()) .expect("Tried to remove file not existing in src archive"); self.entries.remove(index); } fn add_file(&mut self, file: &Path) { self.entries.push(( - file.file_name().unwrap().to_str().unwrap().to_string(), + file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(), ArchiveEntry::File(file.to_owned()), )); } @@ -84,22 +86,23 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { where F: FnMut(&str) -> bool + 'static, { - let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?); + let read_cache = ReadCache::new(std::fs::File::open(&archive_path)?); + let archive = ArchiveFile::parse(&read_cache).unwrap(); let archive_index = self.src_archives.len(); - let mut i = 0; - while let Some(entry) = archive.next_entry() { - let entry = entry?; - let file_name = String::from_utf8(entry.header().identifier().to_vec()) - .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?; + for entry in archive.members() { + let entry = entry.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; + let file_name = String::from_utf8(entry.name().to_vec()) + .map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?; if !skip(&file_name) { - self.entries - .push((file_name, ArchiveEntry::FromArchive { archive_index, entry_index: i })); + self.entries.push(( + file_name.into_bytes(), + ArchiveEntry::FromArchive { archive_index, file_range: entry.file_range() }, + )); } - i += 1; } - self.src_archives.push((archive_path.to_owned(), archive)); + self.src_archives.push(read_cache.into_inner()); Ok(()) } @@ -121,14 +124,14 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { // FIXME only read the symbol table of the object files to avoid having to keep all // object files in memory at once, or read them twice. let data = match entry { - ArchiveEntry::FromArchive { archive_index, entry_index } => { + ArchiveEntry::FromArchive { archive_index, file_range } => { // FIXME read symbols from symtab - use std::io::Read; - let (ref _src_archive_path, ref mut src_archive) = - self.src_archives[archive_index]; - let mut entry = src_archive.jump_to_entry(entry_index).unwrap(); - let mut data = Vec::new(); - entry.read_to_end(&mut data).unwrap(); + let src_read_cache = &mut self.src_archives[archive_index]; + + src_read_cache.seek(io::SeekFrom::Start(file_range.0)).unwrap(); + let mut data = std::vec::from_elem(0, usize::try_from(file_range.1).unwrap()); + src_read_cache.read_exact(&mut data).unwrap(); + data } ArchiveEntry::File(file) => std::fs::read(file).unwrap_or_else(|err| { @@ -143,7 +146,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { match object::File::parse(&*data) { Ok(object) => { symbol_table.insert( - entry_name.as_bytes().to_vec(), + entry_name.to_vec(), object .symbols() .filter_map(|symbol| { @@ -168,7 +171,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } else { sess.fatal(&format!( "error parsing `{}` during archive creation: {}", - entry_name, err + String::from_utf8_lossy(&entry_name), + err )); } } @@ -187,7 +191,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { err )); }), - entries.iter().map(|(name, _)| name.as_bytes().to_vec()).collect(), + entries.iter().map(|(name, _)| name.clone()).collect(), ar::GnuSymbolTableFormat::Size32, symbol_table, ) @@ -210,7 +214,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { // Add all files for (entry_name, data) in entries.into_iter() { - let header = ar::Header::new(entry_name.into_bytes(), data.len() as u64); + let header = ar::Header::new(entry_name, data.len() as u64); match builder { BuilderKind::Bsd(ref mut builder) => builder.append(&header, &mut &*data).unwrap(), BuilderKind::Gnu(ref mut builder) => builder.append(&header, &mut &*data).unwrap(), diff --git a/src/backend.rs b/src/backend.rs deleted file mode 100644 index 05c06bac27d..00000000000 --- a/src/backend.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! Abstraction around the object writing crate - -use std::convert::{TryFrom, TryInto}; - -use rustc_data_structures::fx::FxHashMap; -use rustc_session::Session; - -use cranelift_codegen::isa::TargetIsa; -use cranelift_module::FuncId; -use cranelift_object::{ObjectBuilder, ObjectModule, ObjectProduct}; - -use object::write::*; -use object::{RelocationEncoding, SectionKind, SymbolFlags}; - -use gimli::SectionId; - -use crate::debuginfo::{DebugReloc, DebugRelocName}; - -pub(crate) trait WriteMetadata { - fn add_rustc_section(&mut self, symbol_name: String, data: Vec); -} - -impl WriteMetadata for object::write::Object { - fn add_rustc_section(&mut self, symbol_name: String, data: Vec) { - let segment = self.segment_name(object::write::StandardSegment::Data).to_vec(); - let section_id = self.add_section(segment, b".rustc".to_vec(), object::SectionKind::Data); - let offset = self.append_section_data(section_id, &data, 1); - // For MachO and probably PE this is necessary to prevent the linker from throwing away the - // .rustc section. For ELF this isn't necessary, but it also doesn't harm. - self.add_symbol(object::write::Symbol { - name: symbol_name.into_bytes(), - value: offset, - size: data.len() as u64, - kind: object::SymbolKind::Data, - scope: object::SymbolScope::Dynamic, - weak: false, - section: SymbolSection::Section(section_id), - flags: SymbolFlags::None, - }); - } -} - -pub(crate) trait WriteDebugInfo { - type SectionId: Copy; - - fn add_debug_section(&mut self, name: SectionId, data: Vec) -> Self::SectionId; - fn add_debug_reloc( - &mut self, - section_map: &FxHashMap, - from: &Self::SectionId, - reloc: &DebugReloc, - ); -} - -impl WriteDebugInfo for ObjectProduct { - type SectionId = (object::write::SectionId, object::write::SymbolId); - - fn add_debug_section( - &mut self, - id: SectionId, - data: Vec, - ) -> (object::write::SectionId, object::write::SymbolId) { - let name = if self.object.format() == object::BinaryFormat::MachO { - id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info - } else { - id.name().to_string() - } - .into_bytes(); - - let segment = self.object.segment_name(StandardSegment::Debug).to_vec(); - // FIXME use SHT_X86_64_UNWIND for .eh_frame - let section_id = self.object.add_section( - segment, - name, - if id == SectionId::EhFrame { SectionKind::ReadOnlyData } else { SectionKind::Debug }, - ); - self.object - .section_mut(section_id) - .set_data(data, if id == SectionId::EhFrame { 8 } else { 1 }); - let symbol_id = self.object.section_symbol(section_id); - (section_id, symbol_id) - } - - fn add_debug_reloc( - &mut self, - section_map: &FxHashMap, - from: &Self::SectionId, - reloc: &DebugReloc, - ) { - let (symbol, symbol_offset) = match reloc.name { - DebugRelocName::Section(id) => (section_map.get(&id).unwrap().1, 0), - DebugRelocName::Symbol(id) => { - let symbol_id = self.function_symbol(FuncId::from_u32(id.try_into().unwrap())); - self.object - .symbol_section_and_offset(symbol_id) - .expect("Debug reloc for undef sym???") - } - }; - self.object - .add_relocation( - from.0, - Relocation { - offset: u64::from(reloc.offset), - symbol, - kind: reloc.kind, - encoding: RelocationEncoding::Generic, - size: reloc.size * 8, - addend: i64::try_from(symbol_offset).unwrap() + reloc.addend, - }, - ) - .unwrap(); - } -} - -pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec { - let triple = crate::target_triple(sess); - - let binary_format = match triple.binary_format { - target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf, - target_lexicon::BinaryFormat::Coff => object::BinaryFormat::Coff, - target_lexicon::BinaryFormat::Macho => object::BinaryFormat::MachO, - binary_format => sess.fatal(&format!("binary format {} is unsupported", binary_format)), - }; - let architecture = match triple.architecture { - target_lexicon::Architecture::X86_32(_) => object::Architecture::I386, - target_lexicon::Architecture::X86_64 => object::Architecture::X86_64, - target_lexicon::Architecture::Arm(_) => object::Architecture::Arm, - target_lexicon::Architecture::Aarch64(_) => object::Architecture::Aarch64, - architecture => { - sess.fatal(&format!("target architecture {:?} is unsupported", architecture,)) - } - }; - let endian = match triple.endianness().unwrap() { - target_lexicon::Endianness::Little => object::Endianness::Little, - target_lexicon::Endianness::Big => object::Endianness::Big, - }; - - let mut metadata_object = object::write::Object::new(binary_format, architecture, endian); - metadata_object.add_file_symbol(name.as_bytes().to_vec()); - f(&mut metadata_object); - metadata_object.write().unwrap() -} - -pub(crate) fn make_module(sess: &Session, isa: Box, name: String) -> ObjectModule { - let mut builder = - ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap(); - // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size - // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections - // can easily double the amount of time necessary to perform linking. - builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false)); - ObjectModule::new(builder) -} diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index a044b43b864..b924f2085a0 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -1,4 +1,7 @@ #![feature(rustc_private, once_cell)] +#![warn(rust_2018_idioms)] +#![warn(unused_lifetimes)] +#![warn(unreachable_pub)] extern crate rustc_data_structures; extern crate rustc_driver; diff --git a/src/bin/cg_clif_build_sysroot.rs b/src/bin/cg_clif_build_sysroot.rs index e7cd5edbbf6..bde4d71b9a3 100644 --- a/src/bin/cg_clif_build_sysroot.rs +++ b/src/bin/cg_clif_build_sysroot.rs @@ -7,8 +7,10 @@ //! target crates. #![feature(rustc_private)] +#![warn(rust_2018_idioms)] +#![warn(unused_lifetimes)] +#![warn(unreachable_pub)] -extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_interface; extern crate rustc_session; diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index fb6ccd7c535..c8c2d50b034 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -1,16 +1,16 @@ //! Write the debuginfo into an object file. +use cranelift_object::ObjectProduct; use rustc_data_structures::fx::FxHashMap; use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer}; use gimli::{RunTimeEndian, SectionId}; -use crate::backend::WriteDebugInfo; - +use super::object::WriteDebugInfo; use super::DebugContext; impl DebugContext<'_> { - pub(crate) fn emit(&mut self, product: &mut P) { + pub(crate) fn emit(&mut self, product: &mut ObjectProduct) { let unit_range_list_id = self.dwarf.unit.ranges.add(self.unit_range_list.clone()); let root = self.dwarf.unit.root(); let root = self.dwarf.unit.get_mut(root); diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index cabe3e43b34..6d172817cb1 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -2,6 +2,7 @@ mod emit; mod line_info; +mod object; mod unwind; use crate::prelude::*; diff --git a/src/debuginfo/object.rs b/src/debuginfo/object.rs new file mode 100644 index 00000000000..9984dc92c44 --- /dev/null +++ b/src/debuginfo/object.rs @@ -0,0 +1,85 @@ +use std::convert::{TryFrom, TryInto}; + +use rustc_data_structures::fx::FxHashMap; + +use cranelift_module::FuncId; +use cranelift_object::ObjectProduct; + +use object::write::{Relocation, StandardSegment}; +use object::{RelocationEncoding, SectionKind}; + +use gimli::SectionId; + +use crate::debuginfo::{DebugReloc, DebugRelocName}; + +pub(super) trait WriteDebugInfo { + type SectionId: Copy; + + fn add_debug_section(&mut self, name: SectionId, data: Vec) -> Self::SectionId; + fn add_debug_reloc( + &mut self, + section_map: &FxHashMap, + from: &Self::SectionId, + reloc: &DebugReloc, + ); +} + +impl WriteDebugInfo for ObjectProduct { + type SectionId = (object::write::SectionId, object::write::SymbolId); + + fn add_debug_section( + &mut self, + id: SectionId, + data: Vec, + ) -> (object::write::SectionId, object::write::SymbolId) { + let name = if self.object.format() == object::BinaryFormat::MachO { + id.name().replace('.', "__") // machO expects __debug_info instead of .debug_info + } else { + id.name().to_string() + } + .into_bytes(); + + let segment = self.object.segment_name(StandardSegment::Debug).to_vec(); + // FIXME use SHT_X86_64_UNWIND for .eh_frame + let section_id = self.object.add_section( + segment, + name, + if id == SectionId::EhFrame { SectionKind::ReadOnlyData } else { SectionKind::Debug }, + ); + self.object + .section_mut(section_id) + .set_data(data, if id == SectionId::EhFrame { 8 } else { 1 }); + let symbol_id = self.object.section_symbol(section_id); + (section_id, symbol_id) + } + + fn add_debug_reloc( + &mut self, + section_map: &FxHashMap, + from: &Self::SectionId, + reloc: &DebugReloc, + ) { + let (symbol, symbol_offset) = match reloc.name { + DebugRelocName::Section(id) => (section_map.get(&id).unwrap().1, 0), + DebugRelocName::Symbol(id) => { + let symbol_id = self.function_symbol(FuncId::from_u32(id.try_into().unwrap())); + self.object + .symbol_section_and_offset(symbol_id) + .expect("Debug reloc for undef sym???") + } + }; + self.object + .add_relocation( + from.0, + Relocation { + offset: u64::from(reloc.offset), + symbol, + kind: reloc.kind, + encoding: RelocationEncoding::Generic, + size: reloc.size * 8, + addend: i64::try_from(symbol_offset).unwrap() + reloc.addend, + }, + ) + .unwrap(); + } +} diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index d1251e749f3..f0896ea0e16 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -4,10 +4,11 @@ use crate::prelude::*; use cranelift_codegen::isa::{unwind::UnwindInfo, TargetIsa}; +use cranelift_object::ObjectProduct; use gimli::write::{Address, CieId, EhFrame, FrameTable, Section}; use gimli::RunTimeEndian; -use crate::backend::WriteDebugInfo; +use super::object::WriteDebugInfo; pub(crate) struct UnwindContext { endian: RunTimeEndian, @@ -55,7 +56,7 @@ impl UnwindContext { } } - pub(crate) fn emit(self, product: &mut P) { + pub(crate) fn emit(self, product: &mut ObjectProduct) { let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 3de706ed6d7..40cbc5e1a7e 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -11,8 +11,10 @@ use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::{CodegenUnit, MonoItem}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{DebugInfo, OutputType}; +use rustc_session::Session; -use cranelift_object::ObjectModule; +use cranelift_codegen::isa::TargetIsa; +use cranelift_object::{ObjectBuilder, ObjectModule}; use crate::{prelude::*, BackendConfig}; @@ -24,6 +26,16 @@ impl HashStable for ModuleCodegenResult { } } +fn make_module(sess: &Session, isa: Box, name: String) -> ObjectModule { + let mut builder = + ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap(); + // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size + // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections + // can easily double the amount of time necessary to perform linking. + builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false)); + ObjectModule::new(builder) +} + fn emit_module( tcx: TyCtxt<'_>, backend_config: &BackendConfig, @@ -104,7 +116,7 @@ fn module_codegen( let mono_items = cgu.items_in_deterministic_order(tcx); let isa = crate::build_isa(tcx.sess, &backend_config); - let mut module = crate::backend::make_module(tcx.sess, isa, cgu_name.as_str().to_string()); + let mut module = make_module(tcx.sess, isa, cgu_name.as_str().to_string()); let mut cx = crate::CodegenCx::new( tcx, @@ -227,8 +239,7 @@ pub(crate) fn run_aot( tcx.sess.abort_if_errors(); let isa = crate::build_isa(tcx.sess, &backend_config); - let mut allocator_module = - crate::backend::make_module(tcx.sess, isa, "allocator_shim".to_string()); + let mut allocator_module = make_module(tcx.sess, isa, "allocator_shim".to_string()); assert_eq!(pointer_ty(tcx), allocator_module.target_config().pointer_type()); let mut allocator_unwind_context = UnwindContext::new(tcx, allocator_module.isa(), true); let created_alloc_shim = @@ -266,9 +277,7 @@ pub(crate) fn run_aot( let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); - let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| { - crate::metadata::write_metadata(tcx, object); - }); + let obj = crate::metadata::new_metadata_object(tcx, &metadata_cgu_name, &metadata); if let Err(err) = std::fs::write(&tmp_file, obj) { tcx.sess.fatal(&format!("error writing metadata object file: {}", err)); diff --git a/src/lib.rs b/src/lib.rs index 87193e3ef53..2ceccdd3499 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -#![feature(rustc_private, decl_macro, never_type, hash_drain_filter, vec_into_raw_parts, once_cell)] +#![feature(rustc_private, decl_macro)] +#![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -44,7 +45,6 @@ mod abi; mod allocator; mod analyze; mod archive; -mod backend; mod base; mod cast; mod codegen_i128; diff --git a/src/metadata.rs b/src/metadata.rs index db24bf65eb5..9afa999a87d 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -1,20 +1,72 @@ //! Writing of the rustc metadata for dylibs +use object::write::{Object, StandardSegment, Symbol, SymbolSection}; +use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope}; + +use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::ty::TyCtxt; -use crate::backend::WriteMetadata; - // Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 -pub(crate) fn write_metadata(tcx: TyCtxt<'_>, object: &mut O) { +pub(crate) fn new_metadata_object(tcx: TyCtxt<'_>, cgu_name: &str, metadata: &EncodedMetadata) -> Vec { use snap::write::FrameEncoder; use std::io::Write; - let metadata = tcx.encode_metadata(); let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); - object.add_rustc_section( - rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx), - compressed, - ); + let triple = crate::target_triple(tcx.sess); + + let binary_format = match triple.binary_format { + target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf, + target_lexicon::BinaryFormat::Coff => object::BinaryFormat::Coff, + target_lexicon::BinaryFormat::Macho => object::BinaryFormat::MachO, + binary_format => tcx.sess.fatal(&format!("binary format {} is unsupported", binary_format)), + }; + let architecture = match triple.architecture { + target_lexicon::Architecture::Aarch64(_) => object::Architecture::Aarch64, + target_lexicon::Architecture::Arm(_) => object::Architecture::Arm, + target_lexicon::Architecture::Avr => object::Architecture::Avr, + target_lexicon::Architecture::Hexagon => object::Architecture::Hexagon, + target_lexicon::Architecture::Mips32(_) => object::Architecture::Mips, + target_lexicon::Architecture::Mips64(_) => object::Architecture::Mips64, + target_lexicon::Architecture::Msp430 => object::Architecture::Msp430, + target_lexicon::Architecture::Powerpc => object::Architecture::PowerPc, + target_lexicon::Architecture::Powerpc64 => object::Architecture::PowerPc64, + target_lexicon::Architecture::Powerpc64le => todo!(), + target_lexicon::Architecture::Riscv32(_) => object::Architecture::Riscv32, + target_lexicon::Architecture::Riscv64(_) => object::Architecture::Riscv64, + target_lexicon::Architecture::S390x => object::Architecture::S390x, + target_lexicon::Architecture::Sparc64 => object::Architecture::Sparc64, + target_lexicon::Architecture::Sparcv9 => object::Architecture::Sparc64, + target_lexicon::Architecture::X86_32(_) => object::Architecture::I386, + target_lexicon::Architecture::X86_64 => object::Architecture::X86_64, + architecture => { + tcx.sess.fatal(&format!("target architecture {:?} is unsupported", architecture,)) + } + }; + let endian = match triple.endianness().unwrap() { + target_lexicon::Endianness::Little => object::Endianness::Little, + target_lexicon::Endianness::Big => object::Endianness::Big, + }; + + let mut object = Object::new(binary_format, architecture, endian); + object.add_file_symbol(cgu_name.as_bytes().to_vec()); + + let segment = object.segment_name(StandardSegment::Data).to_vec(); + let section_id = object.add_section(segment, b".rustc".to_vec(), SectionKind::Data); + let offset = object.append_section_data(section_id, &compressed, 1); + // For MachO and probably PE this is necessary to prevent the linker from throwing away the + // .rustc section. For ELF this isn't necessary, but it also doesn't harm. + object.add_symbol(Symbol { + name: rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx).into_bytes(), + value: offset, + size: compressed.len() as u64, + kind: SymbolKind::Data, + scope: SymbolScope::Dynamic, + weak: false, + section: SymbolSection::Section(section_id), + flags: SymbolFlags::None, + }); + + object.write().unwrap() } From 181d72a94727e941e0695509c655b7bfcbc7aacc Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 19 Sep 2021 10:36:17 -0400 Subject: [PATCH 05/91] Adjust to SourceType::InTree in several places These were left over in migrations to subtrees, which should generally be treated as-if it was local. Also fixes a warning caused by this change. --- src/bin/cg_clif_build_sysroot.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/cg_clif_build_sysroot.rs b/src/bin/cg_clif_build_sysroot.rs index e7cd5edbbf6..89e0cb8d90e 100644 --- a/src/bin/cg_clif_build_sysroot.rs +++ b/src/bin/cg_clif_build_sysroot.rs @@ -8,7 +8,6 @@ #![feature(rustc_private)] -extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_interface; extern crate rustc_session; From 8b843373a853184734f42b67e7bd7a0f9827433a Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 19 Sep 2021 12:49:55 -0400 Subject: [PATCH 06/91] Migrate to 2021 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6f40fc0fcb8..61d40702a32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustc_codegen_cranelift" version = "0.1.0" -edition = "2018" +edition = "2021" [lib] crate-type = ["dylib"] From bca98abea6fd19465a29d39ff3af44414ed1a851 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 6 Sep 2021 18:33:23 +0100 Subject: [PATCH 07/91] Introduce `Rvalue::ShallowInitBox` --- src/base.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/base.rs b/src/base.rs index d8fa2c76904..1b30edd2938 100644 --- a/src/base.rs +++ b/src/base.rs @@ -701,6 +701,13 @@ fn codegen_stmt<'tcx>( let len = codegen_array_len(fx, place); lval.write_cvalue(fx, CValue::by_val(len, usize_layout)); } + Rvalue::ShallowInitBox(ref operand, content_ty) => { + let content_ty = fx.monomorphize(content_ty); + let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty)); + let operand = codegen_operand(fx, operand); + let operand = operand.load_scalar(fx); + lval.write_cvalue(fx, CValue::by_val(operand, box_layout)); + } Rvalue::NullaryOp(NullOp::Box, content_ty) => { let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap(); let content_ty = fx.monomorphize(content_ty); From 1a9014e062c8f3bf0734f044f349ca8191cbc2a6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 27 Sep 2021 11:17:24 +0200 Subject: [PATCH 08/91] Rustup to rustc 1.57.0-nightly (e78178505 2021-09-26) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 360570b3ae7..b4a45874eaf 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-09-19" +channel = "nightly-2021-09-27" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From f71d36056668e45981d46472785c7628cb0ac1e7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 27 Sep 2021 11:20:04 +0200 Subject: [PATCH 09/91] Fix unused import warning TryInto is part of the 2021 edition prelude --- src/debuginfo/emit.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index c8c2d50b034..4120ba6e533 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -69,8 +69,6 @@ impl WriterRelocate { /// Perform the collected relocations to be usable for JIT usage. #[cfg(feature = "jit")] pub(super) fn relocate_for_jit(mut self, jit_module: &cranelift_jit::JITModule) -> Vec { - use std::convert::TryInto; - for reloc in self.relocs.drain(..) { match reloc.name { super::DebugRelocName::Section(_) => unreachable!(), From 1eec1814dd1f60d6addd5fd5824b6d29fd7c5ca4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 30 Sep 2021 15:17:43 +0200 Subject: [PATCH 10/91] Update Cranelift --- Cargo.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4afddf76869..73e85a44b37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,16 +33,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -57,8 +57,8 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -66,18 +66,18 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" [[package]] name = "cranelift-entity" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" [[package]] name = "cranelift-frontend" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "cranelift-codegen", "log", @@ -87,8 +87,8 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "anyhow", "cranelift-codegen", @@ -104,8 +104,8 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "anyhow", "cranelift-codegen", @@ -115,8 +115,8 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "cranelift-codegen", "libc", @@ -125,8 +125,8 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.76.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#9c550fcf41425942ed97c747f0169b2ca81f9c1b" +version = "0.77.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" dependencies = [ "anyhow", "cranelift-codegen", From 79529433d8041bb7aa5006437c6bad6b683f7778 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 30 Sep 2021 15:22:19 +0200 Subject: [PATCH 11/91] Update dependencies --- Cargo.lock | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73e85a44b37..a55c2efe031 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.42" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "595d3cfa7a60d4555cb5067b99f07142a08ea778de5cf993f7b75c7d8fabc486" +checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" [[package]] name = "ar" @@ -21,9 +21,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cfg-if" @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.98" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "libloading" @@ -206,15 +206,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "object" -version = "0.26.0" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55827317fb4c08822499848a14237d2874d6f139828893017237e7ab93eb386" +checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" dependencies = [ "crc32fast", "indexmap", @@ -271,15 +271,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "target-lexicon" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0652da4c4121005e9ed22b79f6c5f2d9e2752906b53a33e9490489ba421a6fb" +checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" [[package]] name = "winapi" From a1e052e9c5f1ab17533528572871f5bf538e06fe Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 01:59:00 +0100 Subject: [PATCH 12/91] Move encode_metadata out of CrateStore. --- scripts/filter_profile.rs | 2 +- src/metadata.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index 7a51293f5cd..33814727eb1 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -96,7 +96,7 @@ fn main() -> Result<(), Box> { stack = &stack[..index + REPORT_SYMBOL_NAMES.len()]; } - const ENCODE_METADATA: &str = "rustc_middle::ty::context::TyCtxt::encode_metadata"; + const ENCODE_METADATA: &str = "rustc_metadata::encode_metadata"; if let Some(index) = stack.find(ENCODE_METADATA) { stack = &stack[..index + ENCODE_METADATA.len()]; } diff --git a/src/metadata.rs b/src/metadata.rs index 9afa999a87d..7b769dff370 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -7,7 +7,11 @@ use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::ty::TyCtxt; // Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 -pub(crate) fn new_metadata_object(tcx: TyCtxt<'_>, cgu_name: &str, metadata: &EncodedMetadata) -> Vec { +pub(crate) fn new_metadata_object( + tcx: TyCtxt<'_>, + cgu_name: &str, + metadata: &EncodedMetadata, +) -> Vec { use snap::write::FrameEncoder; use std::io::Write; From c730fdf1ff4053cc9752a259cb07ae0cf350f2c2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 24 Sep 2021 18:15:36 +0200 Subject: [PATCH 13/91] Move EncodedMetadata to rustc_metadata. --- src/driver/aot.rs | 2 +- src/lib.rs | 2 +- src/metadata.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 40cbc5e1a7e..32cc50eebe4 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -6,8 +6,8 @@ use std::path::PathBuf; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::{CodegenUnit, MonoItem}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{DebugInfo, OutputType}; diff --git a/src/lib.rs b/src/lib.rs index 2ceccdd3499..beb97edf09e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,8 +30,8 @@ use std::any::Any; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; use rustc_errors::ErrorReported; +use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_session::config::OutputFilenames; use rustc_session::Session; diff --git a/src/metadata.rs b/src/metadata.rs index 7b769dff370..1c8fd0b01d9 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -3,7 +3,7 @@ use object::write::{Object, StandardSegment, Symbol, SymbolSection}; use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope}; -use rustc_middle::middle::cstore::EncodedMetadata; +use rustc_metadata::EncodedMetadata; use rustc_middle::ty::TyCtxt; // Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 @@ -16,7 +16,7 @@ pub(crate) fn new_metadata_object( use std::io::Write; let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); - FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); + FrameEncoder::new(&mut compressed).write_all(metadata.raw_data()).unwrap(); let triple = crate::target_triple(tcx.sess); From c0ee240da34dbc633a0c15f5afa4338232b8617e Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Tue, 28 Sep 2021 20:49:57 +0200 Subject: [PATCH 14/91] Update compiler/rustc_codegen_cranelift/scripts/filter_profile.rs Co-authored-by: bjorn3 --- scripts/filter_profile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index 33814727eb1..a0e99267c2b 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -96,7 +96,7 @@ fn main() -> Result<(), Box> { stack = &stack[..index + REPORT_SYMBOL_NAMES.len()]; } - const ENCODE_METADATA: &str = "rustc_metadata::encode_metadata"; + const ENCODE_METADATA: &str = "rustc_metadata::rmeta::encoder::encode_metadata"; if let Some(index) = stack.find(ENCODE_METADATA) { stack = &stack[..index + ENCODE_METADATA.len()]; } From fa8cd1ecc2b8b25c1a3a42460130736f42954ab2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 1 Oct 2021 15:37:48 +0200 Subject: [PATCH 15/91] Update Cranelift This version no longer has the old x86 backend --- Cargo.lock | 20 ++++++++++---------- src/debuginfo/mod.rs | 44 +++++++++++--------------------------------- src/lib.rs | 8 +++----- 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a55c2efe031..e2f6b92e6ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" [[package]] name = "cranelift-entity" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" [[package]] name = "cranelift-frontend" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#fa108d9a86827a28c7bfb8ff98033734b2a5fd33" +source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 6d172817cb1..dd19dd5d2b9 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -10,7 +10,7 @@ use crate::prelude::*; use rustc_index::vec::IndexVec; use cranelift_codegen::entity::EntityRef; -use cranelift_codegen::ir::{LabelValueLoc, StackSlots, ValueLabel, ValueLoc}; +use cranelift_codegen::ir::{LabelValueLoc, ValueLabel}; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::ValueLocRange; @@ -67,7 +67,12 @@ impl<'tcx> DebugContext<'tcx> { rustc_interface::util::version_str().unwrap_or("unknown version"), cranelift_codegen::VERSION, ); - let comp_dir = tcx.sess.opts.working_dir.to_string_lossy(FileNameDisplayPreference::Remapped).into_owned(); + let comp_dir = tcx + .sess + .opts + .working_dir + .to_string_lossy(FileNameDisplayPreference::Remapped) + .into_owned(); let (name, file_info) = match tcx.sess.local_crate_source_file.clone() { Some(path) => { let name = path.to_string_lossy().into_owned(); @@ -250,7 +255,7 @@ impl<'tcx> DebugContext<'tcx> { // FIXME make it more reliable and implement scopes before re-enabling this. if false { - let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap(); + let value_labels_ranges = std::collections::HashMap::new(); // FIXME for (local, _local_decl) in mir.local_decls.iter_enumerated() { let ty = self.tcx.subst_and_normalize_erasing_regions( @@ -264,7 +269,6 @@ impl<'tcx> DebugContext<'tcx> { self, isa, symbol, - context, &local_map, &value_labels_ranges, Place { local, projection: ty::List::empty() }, @@ -283,7 +287,6 @@ fn place_location<'tcx>( debug_context: &mut DebugContext<'tcx>, isa: &dyn TargetIsa, symbol: usize, - context: &Context, local_map: &IndexVec>, #[allow(rustc::default_hash_types)] value_labels_ranges: &std::collections::HashMap< ValueLabel, @@ -306,12 +309,7 @@ fn place_location<'tcx>( addend: i64::from(value_loc_range.start), }, end: Address::Symbol { symbol, addend: i64::from(value_loc_range.end) }, - data: translate_loc( - isa, - value_loc_range.loc, - &context.func.stack_slots, - ) - .unwrap(), + data: translate_loc(isa, value_loc_range.loc).unwrap(), }) .collect(), ); @@ -340,34 +338,14 @@ fn place_location<'tcx>( AttributeValue::Exprloc(Expression::new()) // For PointerBase::Stack: - //AttributeValue::Exprloc(translate_loc(ValueLoc::Stack(*stack_slot), &context.func.stack_slots).unwrap()) + //AttributeValue::Exprloc(translate_loc(ValueLoc::Stack(*stack_slot)).unwrap()) } } } // Adapted from https://github.com/CraneStation/wasmtime/blob/5a1845b4caf7a5dba8eda1fef05213a532ed4259/crates/debug/src/transform/expression.rs#L59-L137 -fn translate_loc( - isa: &dyn TargetIsa, - loc: LabelValueLoc, - stack_slots: &StackSlots, -) -> Option { +fn translate_loc(isa: &dyn TargetIsa, loc: LabelValueLoc) -> Option { match loc { - LabelValueLoc::ValueLoc(ValueLoc::Reg(reg)) => { - let machine_reg = isa.map_dwarf_register(reg).unwrap(); - let mut expr = Expression::new(); - expr.op_reg(gimli::Register(machine_reg)); - Some(expr) - } - LabelValueLoc::ValueLoc(ValueLoc::Stack(ss)) => { - if let Some(ss_offset) = stack_slots[ss].offset { - let mut expr = Expression::new(); - expr.op_breg(X86_64::RBP, i64::from(ss_offset) + 16); - Some(expr) - } else { - None - } - } - LabelValueLoc::ValueLoc(ValueLoc::Unassigned) => unreachable!(), LabelValueLoc::Reg(reg) => { let machine_reg = isa.map_regalloc_reg_to_dwarf(reg).unwrap(); let mut expr = Expression::new(); diff --git a/src/lib.rs b/src/lib.rs index 2ceccdd3499..41ac4602151 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,16 +268,14 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { - let builder = cranelift_native::builder_with_options(variant, true).unwrap(); + let builder = cranelift_native::builder_with_options(true).unwrap(); builder } Some(value) => { let mut builder = - cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant) + cranelift_codegen::isa::lookup(target_triple.clone()) .unwrap_or_else(|err| { sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); }); @@ -288,7 +286,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { let mut builder = - cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant) + cranelift_codegen::isa::lookup(target_triple.clone()) .unwrap_or_else(|err| { sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); }); From d78b05408c08a5fb68fc5a51f8bcdd0c173334eb Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 2 Oct 2021 14:50:15 +0200 Subject: [PATCH 16/91] Rustup to rustc 1.57.0-nightly (dd2de8dd8 2021-10-01) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 22be21cb8de..595207b60fa 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.102" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index b4a45874eaf..b57afdadc55 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-09-27" +channel = "nightly-2021-10-02" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 376268684103dd95a9319e032b935addc2beb295 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 2 Oct 2021 14:51:08 +0200 Subject: [PATCH 17/91] Rustfmt --- src/archive.rs | 1 - src/base.rs | 3 +-- src/lib.rs | 16 +++++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 55590f2a675..8a1f6543990 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -104,7 +104,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { self.src_archives.push(read_cache.into_inner()); Ok(()) - } fn update_symbols(&mut self) {} diff --git a/src/base.rs b/src/base.rs index 1b30edd2938..1703675139a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -744,8 +744,7 @@ fn codegen_stmt<'tcx>( NullOp::AlignOf => layout.align.abi.bytes(), NullOp::Box => unreachable!(), }; - let val = - CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into()); + let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into()); lval.write_cvalue(fx, val); } Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() { diff --git a/src/lib.rs b/src/lib.rs index 64328a44950..2f3821dee79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ mod vtable; mod prelude { pub(crate) use std::convert::{TryFrom, TryInto}; - pub(crate) use rustc_span::{Span, FileNameDisplayPreference}; + pub(crate) use rustc_span::{FileNameDisplayPreference, Span}; pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE}; pub(crate) use rustc_middle::bug; @@ -275,10 +275,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { let mut builder = - cranelift_codegen::isa::lookup(target_triple.clone()) - .unwrap_or_else(|err| { - sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); - }); + cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| { + sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); + }); if let Err(_) = builder.enable(value) { sess.fatal("the specified target cpu isn't currently supported by Cranelift."); } @@ -286,10 +285,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { let mut builder = - cranelift_codegen::isa::lookup(target_triple.clone()) - .unwrap_or_else(|err| { - sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); - }); + cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| { + sess.fatal(&format!("can't compile for {}: {}", target_triple, err)); + }); if target_triple.architecture == target_lexicon::Architecture::X86_64 { // Don't use "haswell" as the default, as it implies `has_lzcnt`. // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. From c42f61dff1123b4568f88349734be1a430316df0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:02:03 +0100 Subject: [PATCH 18/91] Move rustc_middle::middle::cstore to rustc_session. --- src/archive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 8a1f6543990..71f510c037f 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -242,7 +242,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { fn inject_dll_import_lib( &mut self, _lib_name: &str, - _dll_imports: &[rustc_middle::middle::cstore::DllImport], + _dll_imports: &[rustc_session::cstore::DllImport], _tmpdir: &rustc_data_structures::temp_dir::MaybeTempDir, ) { bug!("injecting dll imports is not supported"); From d47e09eed9aaddca0d340f798d0396560bffacf1 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 7 Oct 2021 11:29:01 +0200 Subject: [PATCH 19/91] Turn tcx.vtable_allocation() into a query. --- src/vtable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index f97d416b66f..36b3725ef42 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -68,7 +68,7 @@ pub(crate) fn get_vtable<'tcx>( ty: Ty<'tcx>, trait_ref: Option>, ) -> Value { - let alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref)); let data_id = data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, Mutability::Not); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); From a1ff9ca4a08157c9c62e02391a258db72d51f220 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 9 Oct 2021 15:16:19 +0200 Subject: [PATCH 20/91] Rustup to rustc 1.57.0-nightly (db68ca511 2021-10-08) --- build_sysroot/Cargo.lock | 4 ++-- patches/0027-sysroot-128bit-atomic-operations.patch | 4 ++-- rust-toolchain | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 595207b60fa..593c0efda87 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -40,9 +40,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" [[package]] name = "cfg-if" diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch index e2d07bd1267..ffee641457a 100644 --- a/patches/0027-sysroot-128bit-atomic-operations.patch +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -107,7 +107,7 @@ index fa96b7a..2854f9c 100644 inner::monotonize(raw) } --#[cfg(all(target_has_atomic = "64", not(target_has_atomic = "128")))] +-#[cfg(any(all(target_has_atomic = "64", not(target_has_atomic = "128")), target_arch = "aarch64"))] +#[cfg(target_has_atomic = "64")] pub mod inner { use crate::sync::atomic::AtomicU64; @@ -117,7 +117,7 @@ index fa96b7a..2854f9c 100644 } +/* - #[cfg(target_has_atomic = "128")] + #[cfg(all(target_has_atomic = "128", not(target_arch = "aarch64")))] pub mod inner { use crate::sync::atomic::AtomicU128; @@ -94,8 +95,9 @@ pub mod inner { diff --git a/rust-toolchain b/rust-toolchain index b57afdadc55..cf294a2535f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-10-02" +channel = "nightly-2021-10-09" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 96f83a5b3a3e01d473152b187dc33b079729ce43 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 12 Oct 2021 05:06:37 +0000 Subject: [PATCH 21/91] Add const_eval_select intrinsic --- src/abi/mod.rs | 4 ++-- src/intrinsics/mod.rs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 15bb9067805..78fdf9c02d0 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -309,13 +309,13 @@ pub(crate) fn codegen_terminator_call<'tcx>( span: Span, func: &Operand<'tcx>, args: &[Operand<'tcx>], - destination: Option<(Place<'tcx>, BasicBlock)>, + mir_dest: Option<(Place<'tcx>, BasicBlock)>, ) { let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx)); let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx)); - let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb)); + let destination = mir_dest.map(|(place, bb)| (codegen_place(fx, place), bb)); // Handle special calls like instrinsics and empty drop glue. let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() { diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 48183b2d4f6..313b62c5770 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -407,11 +407,9 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( destination: Option<(CPlace<'tcx>, BasicBlock)>, span: Span, ) { - let def_id = instance.def_id(); + let intrinsic = fx.tcx.item_name(instance.def_id()); let substs = instance.substs; - let intrinsic = fx.tcx.item_name(def_id); - let ret = match destination { Some((place, _)) => place, None => { From f6119d3437b91b20da6752a6712908c139ee4849 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 12 Oct 2021 14:47:57 +0200 Subject: [PATCH 22/91] Update Cranelift --- Cargo.lock | 20 ++++++++++---------- src/abi/pass_mode.rs | 1 - src/base.rs | 1 - src/inline_asm.rs | 1 - src/pretty_clif.rs | 13 ++++--------- src/value_and_place.rs | 2 -- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2f6b92e6ba..cdf471d81eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" [[package]] name = "cranelift-entity" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" [[package]] name = "cranelift-frontend" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#bae4ec642798ff448ca88eab771b6fcea71e7884" +source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 2144e7ed67a..2a9b399b9ed 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -204,7 +204,6 @@ pub(super) fn from_casted_value<'tcx>( // It may also be smaller for example when the type is a wrapper around an integer with a // larger alignment than the integer. size: (std::cmp::max(abi_param_size, layout_size) + 15) / 16 * 16, - offset: None, }); let ptr = Pointer::new(fx.bcx.ins().stack_addr(pointer_ty(fx.tcx), stack_slot, 0)); let mut offset = 0; diff --git a/src/base.rs b/src/base.rs index 1703675139a..b16b43cc4f8 100644 --- a/src/base.rs +++ b/src/base.rs @@ -203,7 +203,6 @@ pub(crate) fn verify_func( tcx.sess.err(&format!("{:?}", err)); let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error( &func, - None, Some(Box::new(writer)), err, ); diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 09c5e6031c7..e0116c8b778 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -263,7 +263,6 @@ fn call_inline_asm<'tcx>( ) { let stack_slot = fx.bcx.func.create_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, - offset: None, size: u32::try_from(slot_size.bytes()).unwrap(), }); if fx.clif_comments.enabled() { diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index ec846d71960..4dffb89e105 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -57,7 +57,7 @@ use std::io::Write; use cranelift_codegen::{ entity::SecondaryMap, - ir::{entities::AnyEntity, function::DisplayFunctionAnnotations}, + ir::entities::AnyEntity, write::{FuncWriter, PlainWriter}, }; @@ -129,7 +129,6 @@ impl FuncWriter for &'_ CommentWriter { &mut self, w: &mut dyn fmt::Write, func: &Function, - reg_info: Option<&isa::RegInfo>, ) -> Result { for comment in &self.global_comments { if !comment.is_empty() { @@ -142,7 +141,7 @@ impl FuncWriter for &'_ CommentWriter { writeln!(w)?; } - self.super_preamble(w, func, reg_info) + self.super_preamble(w, func) } fn write_entity_definition( @@ -165,11 +164,10 @@ impl FuncWriter for &'_ CommentWriter { &mut self, w: &mut dyn fmt::Write, func: &Function, - isa: Option<&dyn isa::TargetIsa>, block: Block, indent: usize, ) -> fmt::Result { - PlainWriter.write_block_header(w, func, isa, block, indent) + PlainWriter.write_block_header(w, func, block, indent) } fn write_instruction( @@ -177,11 +175,10 @@ impl FuncWriter for &'_ CommentWriter { w: &mut dyn fmt::Write, func: &Function, aliases: &SecondaryMap>, - isa: Option<&dyn isa::TargetIsa>, inst: Inst, indent: usize, ) -> fmt::Result { - PlainWriter.write_instruction(w, func, aliases, isa, inst, indent)?; + PlainWriter.write_instruction(w, func, aliases, inst, indent)?; if let Some(comment) = self.entity_comments.get(&inst.into()) { writeln!(w, "; {}", comment.replace('\n', "\n; "))?; } @@ -249,7 +246,6 @@ pub(crate) fn write_clif_file<'tcx>( &mut clif_comments, &mut clif, &context.func, - &DisplayFunctionAnnotations { isa: Some(isa), value_ranges: None }, ) .unwrap(); @@ -278,7 +274,6 @@ impl fmt::Debug for FunctionCx<'_, '_, '_> { &mut &self.clif_comments, &mut clif, &self.bcx.func, - &DisplayFunctionAnnotations::default(), ) .unwrap(); writeln!(f, "\n{}", clif) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 30d5340935f..b13dc54653b 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -329,7 +329,6 @@ impl<'tcx> CPlace<'tcx> { // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to // specify stack slot alignment. size: (u32::try_from(layout.size.bytes()).unwrap() + 15) / 16 * 16, - offset: None, }); CPlace { inner: CPlaceInner::Addr(Pointer::stack_slot(stack_slot), None), layout } } @@ -472,7 +471,6 @@ impl<'tcx> CPlace<'tcx> { // FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to // specify stack slot alignment. size: (src_ty.bytes() + 15) / 16 * 16, - offset: None, }); let ptr = Pointer::stack_slot(stack_slot); ptr.store(fx, data, MemFlags::trusted()); From b2061c6fac7d5a2bdc141e2ef3379477a44274ae Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 13 Oct 2021 16:59:59 +0200 Subject: [PATCH 23/91] Update Cranelift --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cdf471d81eb..4a6d0573100 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" [[package]] name = "cranelift-entity" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" [[package]] name = "cranelift-frontend" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#783bb1f759705cc1d5116340431015cee6728760" +source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" dependencies = [ "anyhow", "cranelift-codegen", From e0705f6c6566d55ace29a3beac1a5f565468d845 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 15 Oct 2021 01:41:31 +0200 Subject: [PATCH 24/91] Remove alloc::prelude As per the libs team decision in #58935. Closes #58935 --- example/alloc_example.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/alloc_example.rs b/example/alloc_example.rs index d0d492e9674..bc1594d82ec 100644 --- a/example/alloc_example.rs +++ b/example/alloc_example.rs @@ -1,10 +1,10 @@ -#![feature(start, core_intrinsics, alloc_prelude, alloc_error_handler, box_syntax)] +#![feature(start, core_intrinsics, alloc_error_handler, box_syntax)] #![no_std] extern crate alloc; extern crate alloc_system; -use alloc::prelude::v1::*; +use alloc::boxed::Box; use alloc_system::System; From a513f51cc5aebf265d6926c460a66f713a9e5e5c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 17 Oct 2021 15:29:57 +0200 Subject: [PATCH 25/91] Re-enable incremental compilation for the sysroot rust-lang/rust#74946 for fixed --- build_system/build_sysroot.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 642abc41f45..9a5430a606b 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -193,8 +193,6 @@ fn build_clif_sysroot_for_triple( "RUSTC", env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"), ); - // FIXME Enable incremental again once rust-lang/rust#74946 is fixed - build_cmd.env("CARGO_INCREMENTAL", "0").env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); spawn_and_wait(build_cmd); // Copy all relevant files to the sysroot From a81804dde821fc85981c6ce3ef9ec8620c9eb348 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 17 Oct 2021 17:05:00 +0200 Subject: [PATCH 26/91] Disable a failing test --- scripts/test_rustc_tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index b714d47fec2..d40fd374ee9 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -88,6 +88,8 @@ rm -r src/test/run-make/fmt-write-bloat/ # tests an optimization rm src/test/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support +rm src/test/ui/command/command-current-dir.rs # can't find libstd.so + echo "[TEST] rustc test suite" RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui} popd From b987c3ba18881462ab51bd2f77960c491c48aff6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 17 Oct 2021 22:42:19 +0200 Subject: [PATCH 27/91] Remove unnecessary Lazy Found by m-ou-se in https://github.com/bjorn3/rustc_codegen_cranelift/pull/1166#discussion_r730468919 --- src/driver/jit.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 76fbc9ad51e..31f335bbd7d 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -3,7 +3,7 @@ use std::cell::RefCell; use std::ffi::CString; -use std::lazy::{Lazy, SyncOnceCell}; +use std::lazy::SyncOnceCell; use std::os::raw::{c_char, c_int}; use std::sync::{mpsc, Mutex}; @@ -50,12 +50,11 @@ impl UnsafeMessage { fn send(self) -> Result<(), mpsc::SendError> { thread_local! { /// The Sender owned by the local thread - static LOCAL_MESSAGE_SENDER: Lazy> = Lazy::new(|| + static LOCAL_MESSAGE_SENDER: mpsc::Sender = GLOBAL_MESSAGE_SENDER .get().unwrap() .lock().unwrap() - .clone() - ); + .clone(); } LOCAL_MESSAGE_SENDER.with(|sender| sender.send(self)) } From 62b111fcee2e830b660a13087fdac9f49df4e1a5 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 16 Oct 2021 22:31:48 +0200 Subject: [PATCH 28/91] Make hash_result an Option. --- src/driver/aot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 32cc50eebe4..0a8d6122aa7 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -224,7 +224,7 @@ pub(crate) fn run_aot( tcx, (backend_config.clone(), cgu.name()), module_codegen, - rustc_middle::dep_graph::hash_result, + Some(rustc_middle::dep_graph::hash_result), ); if let Some((id, product)) = work_product { From f85436d78ac9b7a2f709672285aa11437d14ba91 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 21 Oct 2021 15:19:38 +0200 Subject: [PATCH 29/91] Update Cranelift and object --- Cargo.lock | 28 ++++++++++++++-------------- Cargo.toml | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a6d0573100..d7c878beea4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" [[package]] name = "cranelift-entity" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" [[package]] name = "cranelift-frontend" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#6a970d096e57b03fbbb44350212d129f0eb52bb6" +source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" dependencies = [ "anyhow", "cranelift-codegen", @@ -212,9 +212,9 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "object" -version = "0.26.2" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2" +checksum = "c821014c18301591b89b843809ef953af9e3df0496c232d5c0611b0a52aac363" dependencies = [ "crc32fast", "indexmap", @@ -223,9 +223,9 @@ dependencies = [ [[package]] name = "regalloc" -version = "0.0.31" +version = "0.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" +checksum = "a6304468554ed921da3d32c355ea107b8d13d7b8996c3adfb7aab48d3bc321f4" dependencies = [ "log", "rustc-hash", diff --git a/Cargo.toml b/Cargo.toml index 61d40702a32..c891d2cc33f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", opti cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git" } target-lexicon = "0.12.0" gimli = { version = "0.25.0", default-features = false, features = ["write"]} -object = { version = "0.26.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.0.2" From 03eae0d138aa68fe57a80beddfc6b161a14b71b8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 21 Oct 2021 20:18:01 +0200 Subject: [PATCH 30/91] Remove unncesessary TryFrom and TryInto impls --- src/archive.rs | 1 - src/debuginfo/object.rs | 2 -- src/lib.rs | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 71f510c037f..14f1f9d61df 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -1,7 +1,6 @@ //! Creation of ar archives like for the lib and staticlib crate type use std::collections::BTreeMap; -use std::convert::TryFrom; use std::fs::File; use std::io::{self, Read, Seek}; use std::path::{Path, PathBuf}; diff --git a/src/debuginfo/object.rs b/src/debuginfo/object.rs index 9984dc92c44..9dc9b2cf9f8 100644 --- a/src/debuginfo/object.rs +++ b/src/debuginfo/object.rs @@ -1,5 +1,3 @@ -use std::convert::{TryFrom, TryInto}; - use rustc_data_structures::fx::FxHashMap; use cranelift_module::FuncId; diff --git a/src/lib.rs b/src/lib.rs index 2f3821dee79..c392069cbe0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,8 +71,6 @@ mod value_and_place; mod vtable; mod prelude { - pub(crate) use std::convert::{TryFrom, TryInto}; - pub(crate) use rustc_span::{FileNameDisplayPreference, Span}; pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE}; From ace8ad443b77fa5fa6ab616b8bc1c8edd482080f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 27 Oct 2021 14:17:26 +0200 Subject: [PATCH 31/91] Rustup to rustc 1.58.0-nightly (2e259541f 2021-10-26) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 593c0efda87..9aca6186e60 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.103" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index cf294a2535f..b3c301defd3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-10-09" +channel = "nightly-2021-10-27" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From a229b941063575b8d91fe4a7bf16da4b12251caa Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 27 Oct 2021 14:37:57 +0200 Subject: [PATCH 32/91] Disable rustc test requiring rustdoc --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index d40fd374ee9..86bafcffef7 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -65,6 +65,7 @@ rm src/test/incremental/lto.rs # requires lto rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same +rm -r src/test/run-make/rustdoc-scrape-examples-multiple # same rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/pretty/asm.rs # inline asm From 152d914a5725b0ef9a62fd98ecd68e373782c835 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 27 Oct 2021 16:44:51 +0200 Subject: [PATCH 33/91] Revert libc update It causes the macOS CI to fail. See rust-lang/libc#2484 --- build_sysroot/Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 9aca6186e60..593c0efda87 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.105" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" dependencies = [ "rustc-std-workspace-core", ] From 93708a5937f8adc0f90f7d86217c2f95580721a9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 29 Oct 2021 16:22:45 +0200 Subject: [PATCH 34/91] Use crates.io releases of Cranelift I originally switched the Cranelift dependencies to use git as cg_clif required a lot of new Cranelift features. With crates.io dependencies I would have to wait for a new release every time. With git dependencies I could start using the new features as soon as they were merged. Currently there aren't a lot of new Cranelift features necessary anymore and those that are useful are no longer blocking compilation of lots of crates. There was some concern expressed about using git dependencies in the main rust repo, so all together I think it is best to switch to crates.io releases and if necessary wait a bit before merging changes requiring newer Cranelift commits. --- Cargo.lock | 50 ++++++++++++++++++++++++++++++-------------------- Cargo.toml | 12 ++++++------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7c878beea4..141509bcffa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,16 +33,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc0cb7df82c8cf8f2e6a8dd394a0932a71369c160cc9b027dca414fced242513" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe4463c15fa42eee909e61e5eac4866b7c6d22d0d8c621e57a0c5380753bfa8c" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -57,8 +59,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793f6a94a053a55404ea16e1700202a88101672b8cd6b4df63e13cde950852bf" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -66,18 +69,21 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44aa1846df275bce5eb30379d65964c7afc63c05a117076e62a119c25fe174be" [[package]] name = "cranelift-entity" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3a45d8d6318bf8fc518154d9298eab2a8154ec068a8885ff113f6db8d69bb3a" [[package]] name = "cranelift-frontend" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e07339bd461766deb7605169de039e01954768ff730fa1254e149001884a8525" dependencies = [ "cranelift-codegen", "log", @@ -87,8 +93,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e8f0d60fb5d67f7a1e5c49db38ba96d1c846921faef02085fc5590b74781747" dependencies = [ "anyhow", "cranelift-codegen", @@ -104,8 +111,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "825ac7e0959cbe7ddc9cc21209f0319e611a57f9fcb2b723861fe7ef2017e651" dependencies = [ "anyhow", "cranelift-codegen", @@ -115,8 +123,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e2fca76ff57e0532936a71e3fc267eae6a19a86656716479c66e7f912e3d7b" dependencies = [ "cranelift-codegen", "libc", @@ -125,8 +134,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.77.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git#e04357505eb05760f2ea94cebeef6e8370cd9458" +version = "0.78.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55500d0fc9bb05c0944fc4506649249d28f55bd4fe95b87f0e55bf41058f0e6d" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/Cargo.toml b/Cargo.toml index c891d2cc33f..87173f26e26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", features = ["unwind", "all-arch"] } -cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git" } -cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", optional = true } -cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git" } +cranelift-codegen = { version = "0.78.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.78.0" +cranelift-module = "0.78.0" +cranelift-native = "0.78.0" +cranelift-jit = { version = "0.78.0", optional = true } +cranelift-object = "0.78.0" target-lexicon = "0.12.0" gimli = { version = "0.25.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } From a3201a3ff7f7f7f6d1497e0fd8503ac95753e978 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 17 Nov 2021 21:01:35 +0100 Subject: [PATCH 35/91] Rustup to rustc 1.58.0-nightly (3b7b7c91a 2021-11-16) --- build_sysroot/Cargo.lock | 12 ++++++------ rust-toolchain | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 593c0efda87..2937f362161 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -40,9 +40,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -67,9 +67,9 @@ version = "0.0.0" [[package]] name = "dlmalloc" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332570860c2edf2d57914987bf9e24835425f75825086b6ba7d1e6a3e4f1f254" +checksum = "a6fe28e0bf9357092740362502f5cc7955d8dc125ebda71dec72336c2e15c62e" dependencies = [ "compiler_builtins", "libc", @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.103" +version = "0.2.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index b3c301defd3..5333b32e9b6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-10-27" +channel = "nightly-2021-11-17" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 0a6cfc22935831b012cfa7d84c8a028c86404091 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 18 Nov 2021 19:27:32 +0100 Subject: [PATCH 36/91] Implement new simd_shuffle signature --- src/intrinsics/simd.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 43e68b4afa9..73f5d367686 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -67,7 +67,34 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( _ if intrinsic.as_str().starts_with("simd_shuffle"), (c x, c y, o idx) { validate_simd_type!(fx, intrinsic, span, x.layout().ty); - let n: u16 = intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap(); + // If this intrinsic is the older "simd_shuffleN" form, simply parse the integer. + // If there is no suffix, use the index array length. + let n: u16 = if intrinsic == sym::simd_shuffle { + // Make sure this is actually an array, since typeck only checks the length-suffixed + // version of this intrinsic. + let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx)); + match idx_ty.kind() { + ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => { + len.try_eval_usize(fx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(|| { + span_bug!(span, "could not evaluate shuffle index array length") + }).try_into().unwrap() + } + _ => { + fx.tcx.sess.span_err( + span, + &format!( + "simd_shuffle index must be an array of `u32`, got `{}`", + idx_ty, + ), + ); + // Prevent verifier error + crate::trap::trap_unreachable(fx, "compilation should not have succeeded"); + return; + } + } + } else { + intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap() + }; assert_eq!(x.layout(), y.layout()); let layout = x.layout(); From b72269c3b91ff9ade29c35306dd8a048d257f501 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 18 Nov 2021 19:27:49 +0100 Subject: [PATCH 37/91] Implement simd_reduce_{min,max} for floats --- src/intrinsics/simd.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 73f5d367686..6c0631d9ecb 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -405,27 +405,27 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( }; simd_reduce_min, (c v) { - // FIXME support floats validate_simd_type!(fx, intrinsic, span, v.layout().ty); simd_reduce(fx, v, None, ret, |fx, layout, a, b| { - let lt = fx.bcx.ins().icmp(if layout.ty.is_signed() { - IntCC::SignedLessThan - } else { - IntCC::UnsignedLessThan - }, a, b); + let lt = match layout.ty.kind() { + ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedLessThan, a, b), + ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedLessThan, a, b), + ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::LessThan, a, b), + _ => unreachable!(), + }; fx.bcx.ins().select(lt, a, b) }); }; simd_reduce_max, (c v) { - // FIXME support floats validate_simd_type!(fx, intrinsic, span, v.layout().ty); simd_reduce(fx, v, None, ret, |fx, layout, a, b| { - let gt = fx.bcx.ins().icmp(if layout.ty.is_signed() { - IntCC::SignedGreaterThan - } else { - IntCC::UnsignedGreaterThan - }, a, b); + let gt = match layout.ty.kind() { + ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedGreaterThan, a, b), + ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, a, b), + ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::GreaterThan, a, b), + _ => unreachable!(), + }; fx.bcx.ins().select(gt, a, b) }); }; From b898a1f610223ba520b8d0641eb80d1afa8507ee Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 18 Nov 2021 19:30:28 +0100 Subject: [PATCH 38/91] Update to latest portable-simd version --- build_system/prepare.rs | 2 +- ...table-simd-Disable-unsupported-tests.patch | 165 +++++++++--------- 2 files changed, 79 insertions(+), 88 deletions(-) diff --git a/build_system/prepare.rs b/build_system/prepare.rs index ae9a35048bd..b3ee56753be 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -30,7 +30,7 @@ pub(crate) fn prepare() { clone_repo( "portable-simd", "https://github.com/rust-lang/portable-simd", - "8cf7a62e5d2552961df51e5200aaa5b7c890a4bf", + "b8d6b6844602f80af79cd96401339ec594d472d8", ); apply_patches("portable-simd", Path::new("portable-simd")); diff --git a/patches/0001-portable-simd-Disable-unsupported-tests.patch b/patches/0001-portable-simd-Disable-unsupported-tests.patch index 2e683694663..c1325908691 100644 --- a/patches/0001-portable-simd-Disable-unsupported-tests.patch +++ b/patches/0001-portable-simd-Disable-unsupported-tests.patch @@ -1,41 +1,20 @@ -From 6bfce5dc2cbf834c74dbccb7538adc08c6eb57e7 Mon Sep 17 00:00:00 2001 +From 97c473937382a5b5858d9cce3c947855d23b2dc5 Mon Sep 17 00:00:00 2001 From: bjorn3 -Date: Sun, 25 Jul 2021 18:39:31 +0200 +Date: Thu, 18 Nov 2021 19:28:40 +0100 Subject: [PATCH] Disable unsupported tests --- - crates/core_simd/src/vector.rs | 2 ++ - crates/core_simd/src/math.rs | 4 ++++ - crates/core_simd/tests/masks.rs | 12 ------------ - crates/core_simd/tests/ops_macros.rs | 6 ++++++ - crates/core_simd/tests/round.rs | 2 ++ - 6 files changed, 15 insertions(+), 13 deletions(-) + crates/core_simd/src/math.rs | 6 ++++++ + crates/core_simd/src/vector.rs | 2 ++ + crates/core_simd/tests/masks.rs | 2 ++ + crates/core_simd/tests/ops_macros.rs | 4 ++++ + 4 files changed, 14 insertions(+) -diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs -index 25c5309..2b3d819 100644 ---- a/crates/core_simd/src/vector.rs -+++ b/crates/core_simd/src/vector.rs -@@ -22,6 +22,7 @@ where - self.0 - } - -+ /* - /// SIMD gather: construct a SIMD vector by reading from a slice, using potentially discontiguous indices. - /// If an index is out of bounds, that lane instead selects the value from the "or" vector. - /// ``` -@@ -150,6 +151,7 @@ where - // Cleared ☢️ *mut T Zone - } - } -+ */ - } - - impl Copy for Simd diff --git a/crates/core_simd/src/math.rs b/crates/core_simd/src/math.rs -index 7290a28..e394730 100644 +index 2bae414..2f87499 100644 --- a/crates/core_simd/src/math.rs +++ b/crates/core_simd/src/math.rs -@@ -2,6 +2,7 @@ macro_rules! impl_uint_arith { +@@ -5,6 +5,7 @@ macro_rules! impl_uint_arith { ($($ty:ty),+) => { $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { @@ -43,15 +22,15 @@ index 7290a28..e394730 100644 /// Lanewise saturating add. /// /// # Examples -@@ -38,6 +39,7 @@ macro_rules! impl_uint_arith { +@@ -43,6 +44,7 @@ macro_rules! impl_uint_arith { pub fn saturating_sub(self, second: Self) -> Self { - unsafe { crate::intrinsics::simd_saturating_sub(self, second) } + unsafe { simd_saturating_sub(self, second) } } + */ })+ } } -@@ -46,6 +48,7 @@ macro_rules! impl_int_arith { +@@ -51,6 +53,7 @@ macro_rules! impl_int_arith { ($($ty:ty),+) => { $( impl Simd<$ty, LANES> where LaneCount: SupportedLaneCount { @@ -59,7 +38,23 @@ index 7290a28..e394730 100644 /// Lanewise saturating add. /// /// # Examples -@@ -141,6 +144,7 @@ macro_rules! impl_int_arith { +@@ -89,6 +92,7 @@ macro_rules! impl_int_arith { + pub fn saturating_sub(self, second: Self) -> Self { + unsafe { simd_saturating_sub(self, second) } + } ++ */ + + /// Lanewise absolute value, implemented in Rust. + /// Every lane becomes its absolute value. +@@ -109,6 +113,7 @@ macro_rules! impl_int_arith { + (self^m) - m + } + ++ /* + /// Lanewise saturating absolute value, implemented in Rust. + /// As abs(), except the MIN value becomes MAX instead of itself. + /// +@@ -151,6 +156,7 @@ macro_rules! impl_int_arith { pub fn saturating_neg(self) -> Self { Self::splat(0).saturating_sub(self) } @@ -67,51 +62,51 @@ index 7290a28..e394730 100644 })+ } } +diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs +index 7c5ec2b..c8631e8 100644 +--- a/crates/core_simd/src/vector.rs ++++ b/crates/core_simd/src/vector.rs +@@ -75,6 +75,7 @@ where + Self(array) + } + ++ /* + /// Reads from potentially discontiguous indices in `slice` to construct a SIMD vector. + /// If an index is out-of-bounds, the lane is instead selected from the `or` vector. + /// +@@ -297,6 +298,7 @@ where + // Cleared ☢️ *mut T Zone + } + } ++ */ + } + + impl Copy for Simd diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs -index 61d8e44..2bccae2 100644 +index 6a8ecd3..68fcb49 100644 --- a/crates/core_simd/tests/masks.rs +++ b/crates/core_simd/tests/masks.rs -@@ -67,19 +67,6 @@ macro_rules! test_mask_api { - assert_eq!(int.to_array(), [-1, 0, 0, -1, 0, 0, -1, 0]); +@@ -68,6 +68,7 @@ macro_rules! test_mask_api { assert_eq!(core_simd::Mask::<$type, 8>::from_int(int), mask); } -- -- #[cfg(feature = "generic_const_exprs")] -- #[test] -- fn roundtrip_bitmask_conversion() { -- let values = [ -- true, false, false, true, false, false, true, false, -- true, true, false, false, false, false, false, true, -- ]; -- let mask = core_simd::Mask::<$type, 16>::from_array(values); -- let bitmask = mask.to_bitmask(); -- assert_eq!(bitmask, [0b01001001, 0b10000011]); -- assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask); -- } + ++ /* + #[cfg(feature = "generic_const_exprs")] + #[test] + fn roundtrip_bitmask_conversion() { +@@ -80,6 +81,7 @@ macro_rules! test_mask_api { + assert_eq!(bitmask, [0b01001001, 0b10000011]); + assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask); + } ++ */ } } } diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs -index cb39e73..fc0ebe1 100644 +index 31b7ee2..bd04b3c 100644 --- a/crates/core_simd/tests/ops_macros.rs +++ b/crates/core_simd/tests/ops_macros.rs -@@ -435,6 +435,7 @@ macro_rules! impl_float_tests { - ) - } - -+ /* - fn mul_add() { - test_helpers::test_ternary_elementwise( - &Vector::::mul_add, -@@ -442,6 +443,7 @@ macro_rules! impl_float_tests { - &|_, _, _| true, - ) - } -+ */ - - fn recip() { - test_helpers::test_unary_elementwise( -@@ -581,6 +585,7 @@ macro_rules! impl_float_tests { +@@ -567,6 +567,7 @@ macro_rules! impl_float_tests { }); } @@ -119,7 +114,7 @@ index cb39e73..fc0ebe1 100644 fn horizontal_max() { test_helpers::test_1(&|x| { let vmax = Vector::::from_array(x).horizontal_max(); -@@ -604,6 +609,7 @@ macro_rules! impl_float_tests { +@@ -590,6 +591,7 @@ macro_rules! impl_float_tests { Ok(()) }); } @@ -127,26 +122,22 @@ index cb39e73..fc0ebe1 100644 } #[cfg(feature = "std")] -diff --git a/crates/core_simd/tests/round.rs b/crates/core_simd/tests/round.rs -index 37044a7..4cdc6b7 100644 ---- a/crates/core_simd/tests/round.rs -+++ b/crates/core_simd/tests/round.rs -@@ -25,6 +25,7 @@ macro_rules! float_rounding_test { - ) - } +@@ -604,6 +606,7 @@ macro_rules! impl_float_tests { + ) + } -+ /* - fn round() { - test_helpers::test_unary_elementwise( - &Vector::::round, -@@ -32,6 +33,7 @@ macro_rules! float_rounding_test { - &|_| true, - ) ++ /* + fn mul_add() { + test_helpers::test_ternary_elementwise( + &Vector::::mul_add, +@@ -611,6 +614,7 @@ macro_rules! impl_float_tests { + &|_, _, _| true, + ) + } ++ */ } -+ */ - - fn trunc() { - test_helpers::test_unary_elementwise( + } + } -- 2.26.2.7.g19db9cfb68 From 294f6e574f7c36d27d43cacd566c980fbf97b800 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 01:44:32 +0000 Subject: [PATCH 39/91] Implement register allocation for inline assembly --- src/inline_asm.rs | 283 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 210 insertions(+), 73 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index e0116c8b778..07bb2622735 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -6,6 +6,7 @@ use std::fmt::Write; use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_middle::mir::InlineAsmOperand; +use rustc_span::Symbol; use rustc_target::asm::*; pub(crate) fn codegen_inline_asm<'tcx>( @@ -115,11 +116,21 @@ pub(crate) fn codegen_inline_asm<'tcx>( offset }; + let mut asm_gen = InlineAssemblyGenerator { + tcx: fx.tcx, + arch: InlineAsmArch::X86_64, + template, + operands, + options, + registers: Vec::new(), + }; + asm_gen.allocate_registers(); + // FIXME overlap input and output slots to save stack space - for operand in operands { + for (i, operand) in operands.iter().enumerate() { match *operand { InlineAsmOperand::In { reg, ref value } => { - let reg = expect_reg(reg); + let reg = asm_gen.registers[i].unwrap(); clobbered_regs.push((reg, new_slot(reg.reg_class()))); inputs.push(( reg, @@ -128,7 +139,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( )); } InlineAsmOperand::Out { reg, late: _, place } => { - let reg = expect_reg(reg); + let reg = asm_gen.registers[i].unwrap(); clobbered_regs.push((reg, new_slot(reg.reg_class()))); if let Some(place) = place { outputs.push(( @@ -139,7 +150,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( } } InlineAsmOperand::InOut { reg, late: _, ref in_value, out_place } => { - let reg = expect_reg(reg); + let reg = asm_gen.registers[i].unwrap(); clobbered_regs.push((reg, new_slot(reg.reg_class()))); inputs.push(( reg, @@ -164,94 +175,220 @@ pub(crate) fn codegen_inline_asm<'tcx>( fx.inline_asm_index += 1; let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index); - let generated_asm = generate_asm_wrapper( - &asm_name, - InlineAsmArch::X86_64, - options, - template, - clobbered_regs, - &inputs, - &outputs, - ); + let generated_asm = asm_gen.generate_asm_wrapper(&asm_name, clobbered_regs, &inputs, &outputs); fx.cx.global_asm.push_str(&generated_asm); call_inline_asm(fx, &asm_name, slot_size, inputs, outputs); } -fn generate_asm_wrapper( - asm_name: &str, +struct InlineAssemblyGenerator<'a, 'tcx> { + tcx: TyCtxt<'tcx>, arch: InlineAsmArch, + template: &'a [InlineAsmTemplatePiece], + operands: &'a [InlineAsmOperand<'tcx>], options: InlineAsmOptions, - template: &[InlineAsmTemplatePiece], - clobbered_regs: Vec<(InlineAsmReg, Size)>, - inputs: &[(InlineAsmReg, Size, Value)], - outputs: &[(InlineAsmReg, Size, CPlace<'_>)], -) -> String { - let mut generated_asm = String::new(); - writeln!(generated_asm, ".globl {}", asm_name).unwrap(); - writeln!(generated_asm, ".type {},@function", asm_name).unwrap(); - writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap(); - writeln!(generated_asm, "{}:", asm_name).unwrap(); + registers: Vec>, +} - generated_asm.push_str(".intel_syntax noprefix\n"); - generated_asm.push_str(" push rbp\n"); - generated_asm.push_str(" mov rbp,rdi\n"); +impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { + fn allocate_registers(&mut self) { + let sess = self.tcx.sess; + let map = allocatable_registers( + self.arch, + |feature| sess.target_features.contains(&Symbol::intern(feature)), + &sess.target, + ); + let mut allocated = FxHashMap::<_, (bool, bool)>::default(); + let mut regs = vec![None; self.operands.len()]; - // Save clobbered registers - if !options.contains(InlineAsmOptions::NORETURN) { - // FIXME skip registers saved by the calling convention - for &(reg, offset) in &clobbered_regs { - save_register(&mut generated_asm, arch, reg, offset); - } - } - - // Write input registers - for &(reg, offset, _value) in inputs { - restore_register(&mut generated_asm, arch, reg, offset); - } - - if options.contains(InlineAsmOptions::ATT_SYNTAX) { - generated_asm.push_str(".att_syntax\n"); - } - - // The actual inline asm - for piece in template { - match piece { - InlineAsmTemplatePiece::String(s) => { - generated_asm.push_str(s); + // Add explicit registers to the allocated set. + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::In { reg: InlineAsmRegOrRegClass::Reg(reg), .. } => { + regs[i] = Some(reg); + allocated.entry(reg).or_default().0 = true; + } + InlineAsmOperand::Out { + reg: InlineAsmRegOrRegClass::Reg(reg), late: true, .. + } => { + regs[i] = Some(reg); + allocated.entry(reg).or_default().1 = true; + } + InlineAsmOperand::Out { reg: InlineAsmRegOrRegClass::Reg(reg), .. } + | InlineAsmOperand::InOut { reg: InlineAsmRegOrRegClass::Reg(reg), .. } => { + regs[i] = Some(reg); + allocated.insert(reg, (true, true)); + } + _ => (), } - InlineAsmTemplatePiece::Placeholder { operand_idx: _, modifier: _, span: _ } => todo!(), } - } - generated_asm.push('\n'); - if options.contains(InlineAsmOptions::ATT_SYNTAX) { + // Allocate out/inout/inlateout registers first because they are more constrained. + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::Out { + reg: InlineAsmRegOrRegClass::RegClass(class), + late: false, + .. + } + | InlineAsmOperand::InOut { + reg: InlineAsmRegOrRegClass::RegClass(class), .. + } => { + let mut alloc_reg = None; + for ® in &map[&class] { + let mut used = false; + reg.overlapping_regs(|r| { + if allocated.contains_key(&r) { + used = true; + } + }); + + if !used { + alloc_reg = Some(reg); + break; + } + } + + let reg = alloc_reg.expect("cannot allocate registers"); + regs[i] = Some(reg); + allocated.insert(reg, (true, true)); + } + _ => (), + } + } + + // Allocate in/lateout. + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::In { reg: InlineAsmRegOrRegClass::RegClass(class), .. } => { + let mut alloc_reg = None; + for ® in &map[&class] { + let mut used = false; + reg.overlapping_regs(|r| { + if allocated.get(&r).copied().unwrap_or_default().0 { + used = true; + } + }); + + if !used { + alloc_reg = Some(reg); + break; + } + } + + let reg = alloc_reg.expect("cannot allocate registers"); + regs[i] = Some(reg); + allocated.entry(reg).or_default().0 = true; + } + InlineAsmOperand::Out { + reg: InlineAsmRegOrRegClass::RegClass(class), + late: true, + .. + } => { + let mut alloc_reg = None; + for ® in &map[&class] { + let mut used = false; + reg.overlapping_regs(|r| { + if allocated.get(&r).copied().unwrap_or_default().1 { + used = true; + } + }); + + if !used { + alloc_reg = Some(reg); + break; + } + } + + let reg = alloc_reg.expect("cannot allocate registers"); + regs[i] = Some(reg); + allocated.entry(reg).or_default().1 = true; + } + _ => (), + } + } + + self.registers = regs; + } + + fn generate_asm_wrapper( + &self, + asm_name: &str, + clobbered_regs: Vec<(InlineAsmReg, Size)>, + inputs: &[(InlineAsmReg, Size, Value)], + outputs: &[(InlineAsmReg, Size, CPlace<'_>)], + ) -> String { + let mut generated_asm = String::new(); + writeln!(generated_asm, ".globl {}", asm_name).unwrap(); + writeln!(generated_asm, ".type {},@function", asm_name).unwrap(); + writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap(); + writeln!(generated_asm, "{}:", asm_name).unwrap(); + generated_asm.push_str(".intel_syntax noprefix\n"); - } + generated_asm.push_str(" push rbp\n"); + generated_asm.push_str(" mov rbp,rdi\n"); - if !options.contains(InlineAsmOptions::NORETURN) { - // Read output registers - for &(reg, offset, _place) in outputs { - save_register(&mut generated_asm, arch, reg, offset); + // Save clobbered registers + if !self.options.contains(InlineAsmOptions::NORETURN) { + // FIXME skip registers saved by the calling convention + for &(reg, offset) in &clobbered_regs { + save_register(&mut generated_asm, self.arch, reg, offset); + } } - // Restore clobbered registers - for &(reg, offset) in clobbered_regs.iter().rev() { - restore_register(&mut generated_asm, arch, reg, offset); + // Write input registers + for &(reg, offset, _value) in inputs { + restore_register(&mut generated_asm, self.arch, reg, offset); } - generated_asm.push_str(" pop rbp\n"); - generated_asm.push_str(" ret\n"); - } else { - generated_asm.push_str(" ud2\n"); + if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { + generated_asm.push_str(".att_syntax\n"); + } + + // The actual inline asm + for piece in self.template { + match piece { + InlineAsmTemplatePiece::String(s) => { + generated_asm.push_str(s); + } + InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span: _ } => { + self.registers[*operand_idx] + .unwrap() + .emit(&mut generated_asm, self.arch, *modifier) + .unwrap(); + } + } + } + generated_asm.push('\n'); + + if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { + generated_asm.push_str(".intel_syntax noprefix\n"); + } + + if !self.options.contains(InlineAsmOptions::NORETURN) { + // Read output registers + for &(reg, offset, _place) in outputs { + save_register(&mut generated_asm, self.arch, reg, offset); + } + + // Restore clobbered registers + for &(reg, offset) in clobbered_regs.iter().rev() { + restore_register(&mut generated_asm, self.arch, reg, offset); + } + + generated_asm.push_str(" pop rbp\n"); + generated_asm.push_str(" ret\n"); + } else { + generated_asm.push_str(" ud2\n"); + } + + generated_asm.push_str(".att_syntax\n"); + writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap(); + generated_asm.push_str(".text\n"); + generated_asm.push_str("\n\n"); + + generated_asm } - - generated_asm.push_str(".att_syntax\n"); - writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap(); - generated_asm.push_str(".text\n"); - generated_asm.push_str("\n\n"); - - generated_asm } fn call_inline_asm<'tcx>( From 8f729d69dacb5423474e5876287d1bf4ed199fce Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 01:48:22 +0000 Subject: [PATCH 40/91] Remove expect_reg --- src/inline_asm.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 07bb2622735..771f3056ec2 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -42,8 +42,10 @@ pub(crate) fn codegen_inline_asm<'tcx>( assert_eq!(operands.len(), 4); let (leaf, eax_place) = match operands[1] { InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { - let reg = expect_reg(reg); - assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::ax)); + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)) + ); ( crate::base::codegen_operand(fx, in_value).load_scalar(fx), crate::base::codegen_place(fx, out_place.unwrap()), @@ -65,8 +67,10 @@ pub(crate) fn codegen_inline_asm<'tcx>( }; let (sub_leaf, ecx_place) = match operands[2] { InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { - let reg = expect_reg(reg); - assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::cx)); + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)) + ); ( crate::base::codegen_operand(fx, in_value).load_scalar(fx), crate::base::codegen_place(fx, out_place.unwrap()), @@ -76,8 +80,10 @@ pub(crate) fn codegen_inline_asm<'tcx>( }; let edx_place = match operands[3] { InlineAsmOperand::Out { reg, late: true, place } => { - let reg = expect_reg(reg); - assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::dx)); + assert_eq!( + reg, + InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)) + ); crate::base::codegen_place(fx, place.unwrap()) } _ => unreachable!(), @@ -437,13 +443,6 @@ fn call_inline_asm<'tcx>( } } -fn expect_reg(reg_or_class: InlineAsmRegOrRegClass) -> InlineAsmReg { - match reg_or_class { - InlineAsmRegOrRegClass::Reg(reg) => reg, - InlineAsmRegOrRegClass::RegClass(class) => unimplemented!("{:?}", class), - } -} - fn save_register(generated_asm: &mut String, arch: InlineAsmArch, reg: InlineAsmReg, offset: Size) { match arch { InlineAsmArch::X86_64 => { From 7a2314ac880e05ea633127aae6d4ac9a2c576d33 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:05:56 +0000 Subject: [PATCH 41/91] Move stack slot allocation to a new fn --- src/inline_asm.rs | 93 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 771f3056ec2..dde776d8e51 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -103,25 +103,10 @@ pub(crate) fn codegen_inline_asm<'tcx>( crate::trap::trap_unimplemented(fx, "Alloca is not supported"); } - let mut slot_size = Size::from_bytes(0); let mut clobbered_regs = Vec::new(); let mut inputs = Vec::new(); let mut outputs = Vec::new(); - let mut new_slot = |reg_class: InlineAsmRegClass| { - let reg_size = reg_class - .supported_types(InlineAsmArch::X86_64) - .iter() - .map(|(ty, _)| ty.size()) - .max() - .unwrap(); - let align = rustc_target::abi::Align::from_bytes(reg_size.bytes()).unwrap(); - slot_size = slot_size.align_to(align); - let offset = slot_size; - slot_size += reg_size; - offset - }; - let mut asm_gen = InlineAssemblyGenerator { tcx: fx.tcx, arch: InlineAsmArch::X86_64, @@ -129,44 +114,49 @@ pub(crate) fn codegen_inline_asm<'tcx>( operands, options, registers: Vec::new(), + stack_slots_clobber: Vec::new(), + stack_slots_input: Vec::new(), + stack_slots_output: Vec::new(), + stack_slot_size: Size::from_bytes(0), }; asm_gen.allocate_registers(); + asm_gen.allocate_stack_slots(); // FIXME overlap input and output slots to save stack space for (i, operand) in operands.iter().enumerate() { match *operand { InlineAsmOperand::In { reg, ref value } => { let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, new_slot(reg.reg_class()))); + clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); inputs.push(( reg, - new_slot(reg.reg_class()), + asm_gen.stack_slots_input[i].unwrap(), crate::base::codegen_operand(fx, value).load_scalar(fx), )); } InlineAsmOperand::Out { reg, late: _, place } => { let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, new_slot(reg.reg_class()))); + clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); if let Some(place) = place { outputs.push(( reg, - new_slot(reg.reg_class()), + asm_gen.stack_slots_output[i].unwrap(), crate::base::codegen_place(fx, place), )); } } InlineAsmOperand::InOut { reg, late: _, ref in_value, out_place } => { let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, new_slot(reg.reg_class()))); + clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); inputs.push(( reg, - new_slot(reg.reg_class()), + asm_gen.stack_slots_input[i].unwrap(), crate::base::codegen_operand(fx, in_value).load_scalar(fx), )); if let Some(out_place) = out_place { outputs.push(( reg, - new_slot(reg.reg_class()), + asm_gen.stack_slots_output[i].unwrap(), crate::base::codegen_place(fx, out_place), )); } @@ -184,7 +174,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( let generated_asm = asm_gen.generate_asm_wrapper(&asm_name, clobbered_regs, &inputs, &outputs); fx.cx.global_asm.push_str(&generated_asm); - call_inline_asm(fx, &asm_name, slot_size, inputs, outputs); + call_inline_asm(fx, &asm_name, asm_gen.stack_slot_size, inputs, outputs); } struct InlineAssemblyGenerator<'a, 'tcx> { @@ -194,6 +184,10 @@ struct InlineAssemblyGenerator<'a, 'tcx> { operands: &'a [InlineAsmOperand<'tcx>], options: InlineAsmOptions, registers: Vec>, + stack_slots_clobber: Vec>, + stack_slots_input: Vec>, + stack_slots_output: Vec>, + stack_slot_size: Size, } impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { @@ -317,6 +311,59 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { self.registers = regs; } + fn allocate_stack_slots(&mut self) { + let mut slot_size = Size::from_bytes(0); + let mut slots_clobber = vec![None; self.operands.len()]; + let mut slots_input = vec![None; self.operands.len()]; + let mut slots_output = vec![None; self.operands.len()]; + + let mut new_slot = |reg_class: InlineAsmRegClass| { + let reg_size = reg_class + .supported_types(InlineAsmArch::X86_64) + .iter() + .map(|(ty, _)| ty.size()) + .max() + .unwrap(); + let align = rustc_target::abi::Align::from_bytes(reg_size.bytes()).unwrap(); + slot_size = slot_size.align_to(align); + let offset = slot_size; + slot_size += reg_size; + offset + }; + + // FIXME overlap input and output slots to save stack space + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::In { reg, .. } => { + slots_clobber[i] = Some(new_slot(reg.reg_class())); + slots_input[i] = Some(new_slot(reg.reg_class())); + } + InlineAsmOperand::Out { reg, place, .. } => { + slots_clobber[i] = Some(new_slot(reg.reg_class())); + if place.is_some() { + slots_output[i] = Some(new_slot(reg.reg_class())); + } + } + InlineAsmOperand::InOut { reg, out_place, .. } => { + slots_clobber[i] = Some(new_slot(reg.reg_class())); + let slot = new_slot(reg.reg_class()); + slots_input[i] = Some(slot); + if out_place.is_some() { + slots_output[i] = Some(slot); + } + } + InlineAsmOperand::Const { value: _ } => (), + InlineAsmOperand::SymFn { value: _ } => (), + InlineAsmOperand::SymStatic { def_id: _ } => (), + } + } + + self.stack_slots_clobber = slots_clobber; + self.stack_slots_input = slots_input; + self.stack_slots_output = slots_output; + self.stack_slot_size = slot_size; + } + fn generate_asm_wrapper( &self, asm_name: &str, From 01248ba91c56c9c97a557fc782438dde0c1f174d Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:28:16 +0000 Subject: [PATCH 42/91] Code cleanup as a follow up to the previous commit --- src/inline_asm.rs | 85 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index dde776d8e51..8b999f3c55a 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -103,7 +103,6 @@ pub(crate) fn codegen_inline_asm<'tcx>( crate::trap::trap_unimplemented(fx, "Alloca is not supported"); } - let mut clobbered_regs = Vec::new(); let mut inputs = Vec::new(); let mut outputs = Vec::new(); @@ -122,40 +121,37 @@ pub(crate) fn codegen_inline_asm<'tcx>( asm_gen.allocate_registers(); asm_gen.allocate_stack_slots(); + let inline_asm_index = fx.inline_asm_index; + fx.inline_asm_index += 1; + let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index); + + let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); + fx.cx.global_asm.push_str(&generated_asm); + // FIXME overlap input and output slots to save stack space for (i, operand) in operands.iter().enumerate() { match *operand { - InlineAsmOperand::In { reg, ref value } => { - let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); + InlineAsmOperand::In { reg: _, ref value } => { inputs.push(( - reg, asm_gen.stack_slots_input[i].unwrap(), crate::base::codegen_operand(fx, value).load_scalar(fx), )); } - InlineAsmOperand::Out { reg, late: _, place } => { - let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); + InlineAsmOperand::Out { reg: _, late: _, place } => { if let Some(place) = place { outputs.push(( - reg, asm_gen.stack_slots_output[i].unwrap(), crate::base::codegen_place(fx, place), )); } } - InlineAsmOperand::InOut { reg, late: _, ref in_value, out_place } => { - let reg = asm_gen.registers[i].unwrap(); - clobbered_regs.push((reg, asm_gen.stack_slots_clobber[i].unwrap())); + InlineAsmOperand::InOut { reg: _, late: _, ref in_value, out_place } => { inputs.push(( - reg, asm_gen.stack_slots_input[i].unwrap(), crate::base::codegen_operand(fx, in_value).load_scalar(fx), )); if let Some(out_place) = out_place { outputs.push(( - reg, asm_gen.stack_slots_output[i].unwrap(), crate::base::codegen_place(fx, out_place), )); @@ -167,13 +163,6 @@ pub(crate) fn codegen_inline_asm<'tcx>( } } - let inline_asm_index = fx.inline_asm_index; - fx.inline_asm_index += 1; - let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index); - - let generated_asm = asm_gen.generate_asm_wrapper(&asm_name, clobbered_regs, &inputs, &outputs); - fx.cx.global_asm.push_str(&generated_asm); - call_inline_asm(fx, &asm_name, asm_gen.stack_slot_size, inputs, outputs); } @@ -364,13 +353,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { self.stack_slot_size = slot_size; } - fn generate_asm_wrapper( - &self, - asm_name: &str, - clobbered_regs: Vec<(InlineAsmReg, Size)>, - inputs: &[(InlineAsmReg, Size, Value)], - outputs: &[(InlineAsmReg, Size, CPlace<'_>)], - ) -> String { + fn generate_asm_wrapper(&self, asm_name: &str) -> String { let mut generated_asm = String::new(); writeln!(generated_asm, ".globl {}", asm_name).unwrap(); writeln!(generated_asm, ".type {},@function", asm_name).unwrap(); @@ -384,14 +367,24 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { // Save clobbered registers if !self.options.contains(InlineAsmOptions::NORETURN) { // FIXME skip registers saved by the calling convention - for &(reg, offset) in &clobbered_regs { - save_register(&mut generated_asm, self.arch, reg, offset); + for (reg, slot) in self + .registers + .iter() + .zip(self.stack_slots_clobber.iter().copied()) + .filter_map(|(r, s)| r.zip(s)) + { + save_register(&mut generated_asm, self.arch, reg, slot); } } // Write input registers - for &(reg, offset, _value) in inputs { - restore_register(&mut generated_asm, self.arch, reg, offset); + for (reg, slot) in self + .registers + .iter() + .zip(self.stack_slots_input.iter().copied()) + .filter_map(|(r, s)| r.zip(s)) + { + restore_register(&mut generated_asm, self.arch, reg, slot); } if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { @@ -414,19 +407,29 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { } generated_asm.push('\n'); - if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { + if is_x86 && self.options.contains(InlineAsmOptions::ATT_SYNTAX) { generated_asm.push_str(".intel_syntax noprefix\n"); } if !self.options.contains(InlineAsmOptions::NORETURN) { // Read output registers - for &(reg, offset, _place) in outputs { - save_register(&mut generated_asm, self.arch, reg, offset); + for (reg, slot) in self + .registers + .iter() + .zip(self.stack_slots_output.iter().copied()) + .filter_map(|(r, s)| r.zip(s)) + { + save_register(&mut generated_asm, self.arch, reg, slot); } // Restore clobbered registers - for &(reg, offset) in clobbered_regs.iter().rev() { - restore_register(&mut generated_asm, self.arch, reg, offset); + for (reg, slot) in self + .registers + .iter() + .zip(self.stack_slots_clobber.iter().copied()) + .filter_map(|(r, s)| r.zip(s)) + { + restore_register(&mut generated_asm, self.arch, reg, slot); } generated_asm.push_str(" pop rbp\n"); @@ -448,8 +451,8 @@ fn call_inline_asm<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, asm_name: &str, slot_size: Size, - inputs: Vec<(InlineAsmReg, Size, Value)>, - outputs: Vec<(InlineAsmReg, Size, CPlace<'tcx>)>, + inputs: Vec<(Size, Value)>, + outputs: Vec<(Size, CPlace<'tcx>)>, ) { let stack_slot = fx.bcx.func.create_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, @@ -476,14 +479,14 @@ fn call_inline_asm<'tcx>( fx.add_comment(inline_asm_func, asm_name); } - for (_reg, offset, value) in inputs { + for (offset, value) in inputs { fx.bcx.ins().stack_store(value, stack_slot, i32::try_from(offset.bytes()).unwrap()); } let stack_slot_addr = fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0); fx.bcx.ins().call(inline_asm_func, &[stack_slot_addr]); - for (_reg, offset, place) in outputs { + for (offset, place) in outputs { let ty = fx.clif_type(place.layout().ty).unwrap(); let value = fx.bcx.ins().stack_load(ty, stack_slot, i32::try_from(offset.bytes()).unwrap()); place.write_cvalue(fx, CValue::by_val(value, place.layout())); From 7cf2c85fbed34310e30da17bdfce76b0ae48f9d2 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:38:50 +0000 Subject: [PATCH 43/91] Skip registers saved by calling convention --- src/inline_asm.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 8b999f3c55a..8f9deeec718 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -320,21 +320,44 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { offset }; + // Allocate stack slots for saving clobbered registers + let abi_clobber = + InlineAsmClobberAbi::parse(self.arch, &self.tcx.sess.target, Symbol::intern("C")) + .unwrap() + .clobbered_regs(); + for (i, reg) in self.registers.iter().enumerate().filter_map(|(i, r)| r.map(|r| (i, r))) { + let mut need_save = true; + // If the register overlaps with a register clobbered by function call, then + // we don't need to save it. + for r in abi_clobber { + r.overlapping_regs(|r| { + if r == reg { + need_save = false; + } + }); + + if !need_save { + break; + } + } + + if need_save { + slots_clobber[i] = Some(new_slot(reg.reg_class())); + } + } + // FIXME overlap input and output slots to save stack space for (i, operand) in self.operands.iter().enumerate() { match *operand { InlineAsmOperand::In { reg, .. } => { - slots_clobber[i] = Some(new_slot(reg.reg_class())); slots_input[i] = Some(new_slot(reg.reg_class())); } InlineAsmOperand::Out { reg, place, .. } => { - slots_clobber[i] = Some(new_slot(reg.reg_class())); if place.is_some() { slots_output[i] = Some(new_slot(reg.reg_class())); } } InlineAsmOperand::InOut { reg, out_place, .. } => { - slots_clobber[i] = Some(new_slot(reg.reg_class())); let slot = new_slot(reg.reg_class()); slots_input[i] = Some(slot); if out_place.is_some() { @@ -366,7 +389,6 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { // Save clobbered registers if !self.options.contains(InlineAsmOptions::NORETURN) { - // FIXME skip registers saved by the calling convention for (reg, slot) in self .registers .iter() From f9e4b793a7ea2f227e7f640bf7422f4087d6e7be Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:50:09 +0000 Subject: [PATCH 44/91] Overlap input and output stack slots --- src/inline_asm.rs | 61 +++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 8f9deeec718..9c4de3932d1 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -128,7 +128,6 @@ pub(crate) fn codegen_inline_asm<'tcx>( let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); fx.cx.global_asm.push_str(&generated_asm); - // FIXME overlap input and output slots to save stack space for (i, operand) in operands.iter().enumerate() { match *operand { InlineAsmOperand::In { reg: _, ref value } => { @@ -306,7 +305,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { let mut slots_input = vec![None; self.operands.len()]; let mut slots_output = vec![None; self.operands.len()]; - let mut new_slot = |reg_class: InlineAsmRegClass| { + let new_slot_fn = |slot_size: &mut Size, reg_class: InlineAsmRegClass| { let reg_size = reg_class .supported_types(InlineAsmArch::X86_64) .iter() @@ -314,11 +313,11 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .max() .unwrap(); let align = rustc_target::abi::Align::from_bytes(reg_size.bytes()).unwrap(); - slot_size = slot_size.align_to(align); - let offset = slot_size; - slot_size += reg_size; + let offset = slot_size.align_to(align); + *slot_size = offset + reg_size; offset }; + let mut new_slot = |x| new_slot_fn(&mut slot_size, x); // Allocate stack slots for saving clobbered registers let abi_clobber = @@ -346,30 +345,50 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { } } - // FIXME overlap input and output slots to save stack space + // Allocate stack slots for inout for (i, operand) in self.operands.iter().enumerate() { match *operand { - InlineAsmOperand::In { reg, .. } => { - slots_input[i] = Some(new_slot(reg.reg_class())); - } - InlineAsmOperand::Out { reg, place, .. } => { - if place.is_some() { - slots_output[i] = Some(new_slot(reg.reg_class())); - } - } - InlineAsmOperand::InOut { reg, out_place, .. } => { + InlineAsmOperand::InOut { reg, out_place: Some(_), .. } => { let slot = new_slot(reg.reg_class()); slots_input[i] = Some(slot); - if out_place.is_some() { - slots_output[i] = Some(slot); - } + slots_output[i] = Some(slot); } - InlineAsmOperand::Const { value: _ } => (), - InlineAsmOperand::SymFn { value: _ } => (), - InlineAsmOperand::SymStatic { def_id: _ } => (), + _ => (), } } + let slot_size_before_input = slot_size; + let mut new_slot = |x| new_slot_fn(&mut slot_size, x); + + // Allocate stack slots for input + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::In { reg, .. } + | InlineAsmOperand::InOut { reg, out_place: None, .. } => { + slots_input[i] = Some(new_slot(reg.reg_class())); + } + _ => (), + } + } + + // Reset slot size to before input so that input and output operands can overlap + // and save some memory. + let slot_size_after_input = slot_size; + slot_size = slot_size_before_input; + let mut new_slot = |x| new_slot_fn(&mut slot_size, x); + + // Allocate stack slots for output + for (i, operand) in self.operands.iter().enumerate() { + match *operand { + InlineAsmOperand::Out { reg, place: Some(_), .. } => { + slots_output[i] = Some(new_slot(reg.reg_class())); + } + _ => (), + } + } + + slot_size = slot_size.max(slot_size_after_input); + self.stack_slots_clobber = slots_clobber; self.stack_slots_input = slots_input; self.stack_slots_output = slots_output; From 5ca067acdb11609480a167c90b026d810d84ae9f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:56:56 +0000 Subject: [PATCH 45/91] Skeleton for multiple arch support --- src/inline_asm.rs | 116 ++++++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 39 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 9c4de3932d1..19c3a9b82d1 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -402,9 +402,12 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { writeln!(generated_asm, ".section .text.{},\"ax\",@progbits", asm_name).unwrap(); writeln!(generated_asm, "{}:", asm_name).unwrap(); - generated_asm.push_str(".intel_syntax noprefix\n"); - generated_asm.push_str(" push rbp\n"); - generated_asm.push_str(" mov rbp,rdi\n"); + let is_x86 = matches!(self.arch, InlineAsmArch::X86 | InlineAsmArch::X86_64); + + if is_x86 { + generated_asm.push_str(".intel_syntax noprefix\n"); + } + Self::prologue(&mut generated_asm, self.arch); // Save clobbered registers if !self.options.contains(InlineAsmOptions::NORETURN) { @@ -414,7 +417,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .zip(self.stack_slots_clobber.iter().copied()) .filter_map(|(r, s)| r.zip(s)) { - save_register(&mut generated_asm, self.arch, reg, slot); + Self::save_register(&mut generated_asm, self.arch, reg, slot); } } @@ -425,10 +428,10 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .zip(self.stack_slots_input.iter().copied()) .filter_map(|(r, s)| r.zip(s)) { - restore_register(&mut generated_asm, self.arch, reg, slot); + Self::restore_register(&mut generated_asm, self.arch, reg, slot); } - if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { + if is_x86 && self.options.contains(InlineAsmOptions::ATT_SYNTAX) { generated_asm.push_str(".att_syntax\n"); } @@ -460,7 +463,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .zip(self.stack_slots_output.iter().copied()) .filter_map(|(r, s)| r.zip(s)) { - save_register(&mut generated_asm, self.arch, reg, slot); + Self::save_register(&mut generated_asm, self.arch, reg, slot); } // Restore clobbered registers @@ -470,22 +473,84 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { .zip(self.stack_slots_clobber.iter().copied()) .filter_map(|(r, s)| r.zip(s)) { - restore_register(&mut generated_asm, self.arch, reg, slot); + Self::restore_register(&mut generated_asm, self.arch, reg, slot); } - generated_asm.push_str(" pop rbp\n"); - generated_asm.push_str(" ret\n"); + Self::epilogue(&mut generated_asm, self.arch); } else { - generated_asm.push_str(" ud2\n"); + Self::epilogue_noreturn(&mut generated_asm, self.arch); } - generated_asm.push_str(".att_syntax\n"); + if is_x86 { + generated_asm.push_str(".att_syntax\n"); + } writeln!(generated_asm, ".size {name}, .-{name}", name = asm_name).unwrap(); generated_asm.push_str(".text\n"); generated_asm.push_str("\n\n"); generated_asm } + + fn prologue(generated_asm: &mut String, arch: InlineAsmArch) { + match arch { + InlineAsmArch::X86_64 => { + generated_asm.push_str(" push rbp\n"); + generated_asm.push_str(" mov rbp,rdi\n"); + } + _ => unimplemented!("prologue for {:?}", arch), + } + } + + fn epilogue(generated_asm: &mut String, arch: InlineAsmArch) { + match arch { + InlineAsmArch::X86_64 => { + generated_asm.push_str(" pop rbp\n"); + generated_asm.push_str(" ret\n"); + } + _ => unimplemented!("epilogue for {:?}", arch), + } + } + + fn epilogue_noreturn(generated_asm: &mut String, arch: InlineAsmArch) { + match arch { + InlineAsmArch::X86_64 => { + generated_asm.push_str(" ud2\n"); + } + _ => unimplemented!("epilogue_noreturn for {:?}", arch), + } + } + + fn save_register( + generated_asm: &mut String, + arch: InlineAsmArch, + reg: InlineAsmReg, + offset: Size, + ) { + match arch { + InlineAsmArch::X86_64 => { + write!(generated_asm, " mov [rbp+0x{:x}], ", offset.bytes()).unwrap(); + reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); + generated_asm.push('\n'); + } + _ => unimplemented!("save_register for {:?}", arch), + } + } + + fn restore_register( + generated_asm: &mut String, + arch: InlineAsmArch, + reg: InlineAsmReg, + offset: Size, + ) { + match arch { + InlineAsmArch::X86_64 => { + generated_asm.push_str(" mov "); + reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); + writeln!(generated_asm, ", [rbp+0x{:x}]", offset.bytes()).unwrap(); + } + _ => unimplemented!("restore_register for {:?}", arch), + } + } } fn call_inline_asm<'tcx>( @@ -533,30 +598,3 @@ fn call_inline_asm<'tcx>( place.write_cvalue(fx, CValue::by_val(value, place.layout())); } } - -fn save_register(generated_asm: &mut String, arch: InlineAsmArch, reg: InlineAsmReg, offset: Size) { - match arch { - InlineAsmArch::X86_64 => { - write!(generated_asm, " mov [rbp+0x{:x}], ", offset.bytes()).unwrap(); - reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); - generated_asm.push('\n'); - } - _ => unimplemented!("save_register for {:?}", arch), - } -} - -fn restore_register( - generated_asm: &mut String, - arch: InlineAsmArch, - reg: InlineAsmReg, - offset: Size, -) { - match arch { - InlineAsmArch::X86_64 => { - generated_asm.push_str(" mov "); - reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); - writeln!(generated_asm, ", [rbp+0x{:x}]", offset.bytes()).unwrap(); - } - _ => unimplemented!("restore_register for {:?}", arch), - } -} From 7a44f93643bdc29bf8e2e08da42f93a1e1a451a3 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 02:58:53 +0000 Subject: [PATCH 46/91] x86 inline asm support --- src/inline_asm.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 19c3a9b82d1..35876e57f35 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -493,6 +493,10 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { fn prologue(generated_asm: &mut String, arch: InlineAsmArch) { match arch { + InlineAsmArch::X86 => { + generated_asm.push_str(" push ebp\n"); + generated_asm.push_str(" mov ebp,[esp+8]\n"); + } InlineAsmArch::X86_64 => { generated_asm.push_str(" push rbp\n"); generated_asm.push_str(" mov rbp,rdi\n"); @@ -503,6 +507,10 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { fn epilogue(generated_asm: &mut String, arch: InlineAsmArch) { match arch { + InlineAsmArch::X86 => { + generated_asm.push_str(" pop ebp\n"); + generated_asm.push_str(" ret\n"); + } InlineAsmArch::X86_64 => { generated_asm.push_str(" pop rbp\n"); generated_asm.push_str(" ret\n"); @@ -513,7 +521,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { fn epilogue_noreturn(generated_asm: &mut String, arch: InlineAsmArch) { match arch { - InlineAsmArch::X86_64 => { + InlineAsmArch::X86 | InlineAsmArch::X86_64 => { generated_asm.push_str(" ud2\n"); } _ => unimplemented!("epilogue_noreturn for {:?}", arch), @@ -527,6 +535,11 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { offset: Size, ) { match arch { + InlineAsmArch::X86 => { + write!(generated_asm, " mov [ebp+0x{:x}], ", offset.bytes()).unwrap(); + reg.emit(generated_asm, InlineAsmArch::X86, None).unwrap(); + generated_asm.push('\n'); + } InlineAsmArch::X86_64 => { write!(generated_asm, " mov [rbp+0x{:x}], ", offset.bytes()).unwrap(); reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); @@ -543,6 +556,11 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { offset: Size, ) { match arch { + InlineAsmArch::X86 => { + generated_asm.push_str(" mov "); + reg.emit(generated_asm, InlineAsmArch::X86, None).unwrap(); + writeln!(generated_asm, ", [ebp+0x{:x}]", offset.bytes()).unwrap(); + } InlineAsmArch::X86_64 => { generated_asm.push_str(" mov "); reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); From 7fae577bc55335e1b9cbff917c04f101fe0f389e Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 03:01:42 +0000 Subject: [PATCH 47/91] Dispatch inline asm to the correct arch --- src/inline_asm.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 35876e57f35..688fda753b6 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -108,7 +108,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( let mut asm_gen = InlineAssemblyGenerator { tcx: fx.tcx, - arch: InlineAsmArch::X86_64, + arch: fx.tcx.sess.asm_arch.unwrap(), template, operands, options, @@ -306,12 +306,8 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { let mut slots_output = vec![None; self.operands.len()]; let new_slot_fn = |slot_size: &mut Size, reg_class: InlineAsmRegClass| { - let reg_size = reg_class - .supported_types(InlineAsmArch::X86_64) - .iter() - .map(|(ty, _)| ty.size()) - .max() - .unwrap(); + let reg_size = + reg_class.supported_types(self.arch).iter().map(|(ty, _)| ty.size()).max().unwrap(); let align = rustc_target::abi::Align::from_bytes(reg_size.bytes()).unwrap(); let offset = slot_size.align_to(align); *slot_size = offset + reg_size; From de69de796d7e6480e785bd82f86eb890c603f7ac Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 03:15:02 +0000 Subject: [PATCH 48/91] Add RISC-V inline asm support --- src/inline_asm.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 688fda753b6..71fbcedd1b9 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -497,6 +497,18 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { generated_asm.push_str(" push rbp\n"); generated_asm.push_str(" mov rbp,rdi\n"); } + InlineAsmArch::RiscV32 => { + generated_asm.push_str(" addi sp, sp, -8\n"); + generated_asm.push_str(" sw ra, 4(sp)\n"); + generated_asm.push_str(" sw s0, 0(sp)\n"); + generated_asm.push_str(" mv s0, a0\n"); + } + InlineAsmArch::RiscV64 => { + generated_asm.push_str(" addi sp, sp, -16\n"); + generated_asm.push_str(" sd ra, 8(sp)\n"); + generated_asm.push_str(" sd s0, 0(sp)\n"); + generated_asm.push_str(" mv s0, a0\n"); + } _ => unimplemented!("prologue for {:?}", arch), } } @@ -511,6 +523,18 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { generated_asm.push_str(" pop rbp\n"); generated_asm.push_str(" ret\n"); } + InlineAsmArch::RiscV32 => { + generated_asm.push_str(" lw s0, 0(sp)\n"); + generated_asm.push_str(" lw ra, 4(sp)\n"); + generated_asm.push_str(" addi sp, sp, 8\n"); + generated_asm.push_str(" ret\n"); + } + InlineAsmArch::RiscV64 => { + generated_asm.push_str(" ld s0, 0(sp)\n"); + generated_asm.push_str(" ld ra, 8(sp)\n"); + generated_asm.push_str(" addi sp, sp, 16\n"); + generated_asm.push_str(" ret\n"); + } _ => unimplemented!("epilogue for {:?}", arch), } } @@ -520,6 +544,9 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { InlineAsmArch::X86 | InlineAsmArch::X86_64 => { generated_asm.push_str(" ud2\n"); } + InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => { + generated_asm.push_str(" ebreak\n"); + } _ => unimplemented!("epilogue_noreturn for {:?}", arch), } } @@ -541,6 +568,16 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); generated_asm.push('\n'); } + InlineAsmArch::RiscV32 => { + generated_asm.push_str(" sw "); + reg.emit(generated_asm, InlineAsmArch::RiscV32, None).unwrap(); + writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap(); + } + InlineAsmArch::RiscV64 => { + generated_asm.push_str(" sd "); + reg.emit(generated_asm, InlineAsmArch::RiscV64, None).unwrap(); + writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap(); + } _ => unimplemented!("save_register for {:?}", arch), } } @@ -562,6 +599,16 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap(); writeln!(generated_asm, ", [rbp+0x{:x}]", offset.bytes()).unwrap(); } + InlineAsmArch::RiscV32 => { + generated_asm.push_str(" lw "); + reg.emit(generated_asm, InlineAsmArch::RiscV32, None).unwrap(); + writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap(); + } + InlineAsmArch::RiscV64 => { + generated_asm.push_str(" ld "); + reg.emit(generated_asm, InlineAsmArch::RiscV64, None).unwrap(); + writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap(); + } _ => unimplemented!("restore_register for {:?}", arch), } } From 0c5a321797273a4a12bad8dea6a8633ad23e5a66 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 22 Nov 2021 17:01:43 +0000 Subject: [PATCH 49/91] Fix allocated reg in AT&T style asm --- src/inline_asm.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 71fbcedd1b9..706d9cdc166 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -438,6 +438,9 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { generated_asm.push_str(s); } InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span: _ } => { + if self.options.contains(InlineAsmOptions::ATT_SYNTAX) { + generated_asm.push('%'); + } self.registers[*operand_idx] .unwrap() .emit(&mut generated_asm, self.arch, *modifier) From bcca3a7ac8d4f04e341e53f72ff55c1f2a624760 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 23 Nov 2021 14:25:28 +0100 Subject: [PATCH 50/91] Version the prebuilt libstd again __CARGO_DEFAULT_LIB_METADATA got lost in the rewrite of the build system from bash to rust --- build_system/build_sysroot.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 9a5430a606b..1c78e7b5171 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -193,6 +193,7 @@ fn build_clif_sysroot_for_triple( "RUSTC", env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"), ); + build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); spawn_and_wait(build_cmd); // Copy all relevant files to the sysroot From 56eb0d77328310ae8166811030d4fb00f6c38598 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 24 Nov 2021 19:18:22 +0100 Subject: [PATCH 51/91] Use cgu name instead of function name as base for inline asm wrapper name This fixes using #[inline] functions containing inline assembly from multiple cgus --- src/base.rs | 2 -- src/common.rs | 2 -- src/driver/aot.rs | 1 + src/driver/jit.rs | 17 +++++++++++++++-- src/inline_asm.rs | 7 ++++--- src/lib.rs | 7 +++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/base.rs b/src/base.rs index b16b43cc4f8..a1d06851277 100644 --- a/src/base.rs +++ b/src/base.rs @@ -71,8 +71,6 @@ pub(crate) fn codegen_fn<'tcx>( clif_comments, source_info_set: indexmap::IndexSet::new(), next_ssa_var: 0, - - inline_asm_index: 0, }; let arg_uninhabited = fx diff --git a/src/common.rs b/src/common.rs index 0e84681d9ad..2ed497a6f94 100644 --- a/src/common.rs +++ b/src/common.rs @@ -255,8 +255,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { /// This should only be accessed by `CPlace::new_var`. pub(crate) next_ssa_var: u32, - - pub(crate) inline_asm_index: u32, } impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 0a8d6122aa7..8317f40c7ea 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -123,6 +123,7 @@ fn module_codegen( backend_config.clone(), module.isa(), tcx.sess.opts.debuginfo != DebugInfo::None, + cgu_name, ); super::predefine_mono_items(tcx, &mut module, &mono_items); for (mono_item, _) in mono_items { diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 31f335bbd7d..8c93a151349 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -11,6 +11,7 @@ use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_codegen_ssa::CrateInfo; use rustc_middle::mir::mono::MonoItem; use rustc_session::Session; +use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; @@ -75,7 +76,13 @@ fn create_jit_module<'tcx>( jit_builder.symbols(imported_symbols); let mut jit_module = JITModule::new(jit_builder); - let mut cx = crate::CodegenCx::new(tcx, backend_config.clone(), jit_module.isa(), false); + let mut cx = crate::CodegenCx::new( + tcx, + backend_config.clone(), + jit_module.isa(), + false, + Symbol::intern("dummy_cgu_name"), + ); crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context); crate::main_shim::maybe_create_entry_wrapper( @@ -245,7 +252,13 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> jit_module.prepare_for_function_redefine(func_id).unwrap(); - let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module.isa(), false); + let mut cx = crate::CodegenCx::new( + tcx, + backend_config, + jit_module.isa(), + false, + Symbol::intern("dummy_cgu_name"), + ); tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, jit_module, instance)); assert!(cx.global_asm.is_empty()); diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 706d9cdc166..1a670c475c7 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -121,9 +121,10 @@ pub(crate) fn codegen_inline_asm<'tcx>( asm_gen.allocate_registers(); asm_gen.allocate_stack_slots(); - let inline_asm_index = fx.inline_asm_index; - fx.inline_asm_index += 1; - let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index); + let inline_asm_index = fx.cx.inline_asm_index.get(); + fx.cx.inline_asm_index.set(inline_asm_index + 1); + let asm_name = + format!("{}__inline_asm_{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index); let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); fx.cx.global_asm.push_str(&generated_asm); diff --git a/src/lib.rs b/src/lib.rs index c392069cbe0..d752dc9e4f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ extern crate rustc_target; extern crate rustc_driver; use std::any::Any; +use std::cell::Cell; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; @@ -34,6 +35,7 @@ use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_session::config::OutputFilenames; use rustc_session::Session; +use rustc_span::Symbol; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings::{self, Configurable}; @@ -123,9 +125,11 @@ impl String> Drop for PrintOnPanic { struct CodegenCx<'tcx> { tcx: TyCtxt<'tcx>, global_asm: String, + inline_asm_index: Cell, cached_context: Context, debug_context: Option>, unwind_context: UnwindContext, + cgu_name: Symbol, } impl<'tcx> CodegenCx<'tcx> { @@ -134,6 +138,7 @@ impl<'tcx> CodegenCx<'tcx> { backend_config: BackendConfig, isa: &dyn TargetIsa, debug_info: bool, + cgu_name: Symbol, ) -> Self { assert_eq!(pointer_ty(tcx), isa.pointer_type()); @@ -143,9 +148,11 @@ impl<'tcx> CodegenCx<'tcx> { CodegenCx { tcx, global_asm: String::new(), + inline_asm_index: Cell::new(0), cached_context: Context::new(), debug_context, unwind_context, + cgu_name, } } } From c36a33dc7cfe604c10a58a186934043071673604 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 24 Nov 2021 20:35:57 +0100 Subject: [PATCH 52/91] Include NOTYPE symbols in the archive symbol table This is necessary for blog os --- src/archive.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 14f1f9d61df..1eac85c7564 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -149,12 +149,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { object .symbols() .filter_map(|symbol| { - if symbol.is_undefined() - || symbol.is_local() - || symbol.kind() != SymbolKind::Data - && symbol.kind() != SymbolKind::Text - && symbol.kind() != SymbolKind::Tls - { + if symbol.is_undefined() || symbol.is_local() { None } else { symbol.name().map(|name| name.as_bytes().to_vec()).ok() From dfdb396297fc705112f2f0b965e1ea9f12a0b349 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 25 Nov 2021 11:43:18 +0100 Subject: [PATCH 53/91] Ensure inline asm wrapper name never starts with a digit This could previously happen if the cgu name starts with a digit --- src/inline_asm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 1a670c475c7..ba2699316da 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -124,7 +124,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( let inline_asm_index = fx.cx.inline_asm_index.get(); fx.cx.inline_asm_index.set(inline_asm_index + 1); let asm_name = - format!("{}__inline_asm_{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index); + format!("__inline_asm_{}_n{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index); let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); fx.cx.global_asm.push_str(&generated_asm); From 30136f95f67c46ea418be172126c777e42bc9fb4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 26 Nov 2021 15:33:56 +0100 Subject: [PATCH 54/91] Enable unstable-features feature of cg_clif for rust-analyzer --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index f62e59cefc2..74fde9c27c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "rust-analyzer.assist.importEnforceGranularity": true, "rust-analyzer.assist.importPrefix": "crate", "rust-analyzer.cargo.runBuildScripts": true, + "rust-analyzer.cargo.features": ["unstable-features"] "rust-analyzer.linkedProjects": [ "./Cargo.toml", //"./build_sysroot/sysroot_src/src/libstd/Cargo.toml", From a4fe96d07017169b7ff2041ffbe9bbc106911304 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 26 Nov 2021 16:21:01 +0100 Subject: [PATCH 55/91] Rustup to rustc 1.58.0-nightly (3c88e1ccd 2021-11-25) --- build_sysroot/Cargo.lock | 6 +++--- build_system/prepare.rs | 2 +- rust-toolchain | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 2937f362161..309ed59fbd8 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.50" +version = "0.1.53" dependencies = [ "rustc-std-workspace-core", ] @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.107" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b3ee56753be..66e783edf23 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -92,7 +92,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.50", + "0.1.53", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/rust-toolchain b/rust-toolchain index 5333b32e9b6..ed2d97aa023 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-11-17" +channel = "nightly-2021-11-26" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 4c9b7caee2940fe835687448034af51de43ba077 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 26 Nov 2021 16:21:19 +0100 Subject: [PATCH 56/91] Fix warning --- src/archive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 1eac85c7564..b0eb3864d80 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -9,7 +9,7 @@ use rustc_codegen_ssa::back::archive::ArchiveBuilder; use rustc_session::Session; use object::read::archive::ArchiveFile; -use object::{Object, ObjectSymbol, ReadCache, SymbolKind}; +use object::{Object, ObjectSymbol, ReadCache}; #[derive(Debug)] enum ArchiveEntry { From a5227b9a6377971b378acd135d197e41af965a88 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 26 Nov 2021 17:05:25 +0100 Subject: [PATCH 57/91] Fix rustc tests --- scripts/setup_rust_fork.sh | 3 ++- scripts/test_rustc_tests.sh | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index ca83e7096b8..80bf40dd874 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -33,7 +33,7 @@ index d95b5b7f17f..00b6f0e3635 100644 [dependencies] core = { path = "../core" } -compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] } -+compiler_builtins = { version = "0.1.46", features = ['rustc-dep-of-std', 'no-asm'] } ++compiler_builtins = { version = "0.1.53", features = ['rustc-dep-of-std', 'no-asm'] } [dev-dependencies] rand = "0.7" @@ -53,5 +53,6 @@ local-rebuild = true [rust] codegen-backends = ["cranelift"] deny-warnings = false +verbose-tests = false EOF popd diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 86bafcffef7..43e090c63c5 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -10,7 +10,7 @@ pushd rust cargo install ripgrep -rm -r src/test/ui/{extern/,panics/,unsized-locals/,thinlto/,simd*,*lto*.rs,linkage*,unwind-*.rs} || true +rm -r src/test/ui/{extern/,panics/,unsized-locals/,lto/,simd*,linkage*,unwind-*.rs} || true for test in $(rg --files-with-matches "asm!|catch_unwind|should_panic|lto|// needs-asm-support" src/test/ui); do rm $test done @@ -30,19 +30,20 @@ rm src/test/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs rm src/test/ui/issues/issue-26655.rs rm src/test/ui/issues/issue-29485.rs rm src/test/ui/issues/issue-30018-panic.rs -rm src/test/ui/multi-panic.rs +rm src/test/ui/process/multi-panic.rs rm src/test/ui/sepcomp/sepcomp-unwind.rs rm src/test/ui/structs-enums/unit-like-struct-drop-run.rs -rm src/test/ui/terminate-in-initializer.rs +rm src/test/ui/drop/terminate-in-initializer.rs rm src/test/ui/threads-sendsync/task-stderr.rs rm src/test/ui/numbers-arithmetic/int-abs-overflow.rs rm src/test/ui/drop/drop-trait-enum.rs rm src/test/ui/numbers-arithmetic/issue-8460.rs -rm src/test/ui/rt-explody-panic-payloads.rs +rm src/test/ui/runtime/rt-explody-panic-payloads.rs rm src/test/incremental/change_crate_dep_kind.rs +rm src/test/ui/threads-sendsync/unwind-resource.rs rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations -rm src/test/ui/init-large-type.rs # same +rm src/test/ui/codegen/init-large-type.rs # same rm src/test/ui/sse2.rs # cpuid not supported, so sse2 not detected rm src/test/ui/issues/issue-33992.rs # unsupported linkages rm src/test/ui/issues/issue-51947.rs # same @@ -65,7 +66,7 @@ rm src/test/incremental/lto.rs # requires lto rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same -rm -r src/test/run-make/rustdoc-scrape-examples-multiple # same +rm -r src/test/run-make/rustdoc-scrape-* # same rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/pretty/asm.rs # inline asm @@ -75,7 +76,10 @@ rm -r src/test/run-pass-valgrind/unsized-locals rm src/test/ui/json-bom-plus-crlf-multifile.rs # differing warning rm src/test/ui/json-bom-plus-crlf.rs # same +rm src/test/ui/intrinsics/const-eval-select-x86_64.rs # same rm src/test/ui/match/issue-82392.rs # differing error +rm src/test/ui/consts/min_const_fn/address_of_const.rs # same +rm src/test/ui/consts/issue-miri-1910.rs # same rm src/test/ui/type-alias-impl-trait/cross_crate_ice*.rs # requires removed aux dep rm src/test/ui/allocator/no_std-alloc-error-handler-default.rs # missing rust_oom definition @@ -91,6 +95,8 @@ rm src/test/ui/abi/variadic-ffi.rs # requires callee side vararg support rm src/test/ui/command/command-current-dir.rs # can't find libstd.so +rm src/test/ui/abi/stack-protector.rs # requires stack protector support + echo "[TEST] rustc test suite" RUST_TEST_NOCAPTURE=1 COMPILETEST_FORCE_STAGE0=1 ./x.py test --stage 0 src/test/{codegen-units,run-make,run-pass-valgrind,ui} popd From 8978b10b15c0a09cd1bf3d29be8c597ff6b00328 Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Wed, 1 Dec 2021 10:03:45 +0100 Subject: [PATCH 58/91] fix sparc64 ABI for aggregates with floating point members --- src/abi/pass_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 2144e7ed67a..45d49062593 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -71,7 +71,7 @@ fn cast_target_to_abi_params(cast: CastTarget) -> SmallVec<[AbiParam; 2]> { .prefix .iter() .flatten() - .map(|&kind| reg_to_abi_param(Reg { kind, size: cast.prefix_chunk_size })) + .map(|®| reg_to_abi_param(reg)) .chain((0..rest_count).map(|_| reg_to_abi_param(cast.rest.unit))) .collect::>(); From 075d54ae15d8d1af4337898748f848c590997f8d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 1 Dec 2021 18:34:19 +0100 Subject: [PATCH 59/91] Update object --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 141509bcffa..4478517ff04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,9 +222,9 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "object" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c821014c18301591b89b843809ef953af9e3df0496c232d5c0611b0a52aac363" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" dependencies = [ "crc32fast", "indexmap", From 3b71e1449882f7457662b0d9cfcb979d4df4aa6c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 1 Dec 2021 18:36:19 +0100 Subject: [PATCH 60/91] Update dependencies --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4478517ff04..3050dce50d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" [[package]] name = "ar" @@ -148,9 +148,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" dependencies = [ "cfg-if", ] @@ -182,9 +182,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.103" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" [[package]] name = "libloading" From 32d4efa8396f70fae0ceaba090a0b39abb74493d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 2 Dec 2021 13:31:47 +0100 Subject: [PATCH 61/91] Enable artifact uploads for windows builds Fixes #1210 --- .github/workflows/main.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f524b42c5ee..4d2b4b99b6d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -152,11 +152,12 @@ jobs: ./y.exe build - #- name: Package prebuilt cg_clif - # run: tar cvfJ cg_clif.tar.xz build + - name: Package prebuilt cg_clif + # don't use compression as xzip isn't supported by tar on windows and bzip2 hangs + run: tar cvf cg_clif.tar build - #- name: Upload prebuilt cg_clif - # uses: actions/upload-artifact@v2 - # with: - # name: cg_clif-${{ runner.os }} - # path: cg_clif.tar.xz + - name: Upload prebuilt cg_clif + uses: actions/upload-artifact@v2 + with: + name: cg_clif-${{ runner.os }} + path: cg_clif.tar From fa30ef8957b783ba7e20e20344cfa09063866a4f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 2 Dec 2021 16:49:27 +0100 Subject: [PATCH 62/91] Rustup to rustc 1.59.0-nightly (4129bdeab 2021-12-01) --- build_sysroot/Cargo.lock | 2 +- build_system/prepare.rs | 2 +- rust-toolchain | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 309ed59fbd8..35d2902fde5 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.53" +version = "0.1.55" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 66e783edf23..0e39320a93c 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -92,7 +92,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.53", + "0.1.55", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/rust-toolchain b/rust-toolchain index ed2d97aa023..f4f8fafa5be 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-11-26" +channel = "nightly-2021-12-02" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From e6665a9eda4d047cb4b3b0472392aa767cbcfe71 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 3 Dec 2021 12:13:41 +0100 Subject: [PATCH 63/91] Fix vector types containing an array field with mir opts enabled --- src/value_and_place.rs | 51 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index b13dc54653b..d5c7e2cc297 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -510,6 +510,26 @@ impl<'tcx> CPlace<'tcx> { let dst_layout = self.layout(); let to_ptr = match self.inner { CPlaceInner::Var(_local, var) => { + if let ty::Array(element, len) = dst_layout.ty.kind() { + // Can only happen for vector types + let len = + u16::try_from(len.eval_usize(fx.tcx, ParamEnv::reveal_all())).unwrap(); + let vector_ty = fx.clif_type(element).unwrap().by(len).unwrap(); + + let data = match from.0 { + CValueInner::ByRef(ptr, None) => { + let mut flags = MemFlags::new(); + flags.set_notrap(); + ptr.load(fx, vector_ty, flags) + } + CValueInner::ByVal(_) + | CValueInner::ByValPair(_, _) + | CValueInner::ByRef(_, Some(_)) => bug!("array should be ByRef"), + }; + + fx.bcx.def_var(var, data); + return; + } let data = CValue(from.0, dst_layout).load_scalar(fx); let dst_ty = fx.clif_type(self.layout().ty).unwrap(); transmute_value(fx, var, data, dst_ty); @@ -603,14 +623,39 @@ impl<'tcx> CPlace<'tcx> { let layout = self.layout(); match self.inner { - CPlaceInner::Var(local, var) => { - if let Abi::Vector { .. } = layout.abi { + CPlaceInner::Var(local, var) => match layout.ty.kind() { + ty::Array(_, _) => { + // Can only happen for vector types return CPlace { inner: CPlaceInner::VarLane(local, var, field.as_u32().try_into().unwrap()), layout: layout.field(fx, field.as_u32().try_into().unwrap()), }; } - } + ty::Adt(adt_def, substs) if layout.ty.is_simd() => { + let f0_ty = adt_def.non_enum_variant().fields[0].ty(fx.tcx, substs); + + match f0_ty.kind() { + ty::Array(_, _) => { + assert_eq!(field.as_u32(), 0); + return CPlace { + inner: CPlaceInner::Var(local, var), + layout: layout.field(fx, field.as_u32().try_into().unwrap()), + }; + } + _ => { + return CPlace { + inner: CPlaceInner::VarLane( + local, + var, + field.as_u32().try_into().unwrap(), + ), + layout: layout.field(fx, field.as_u32().try_into().unwrap()), + }; + } + } + } + _ => {} + }, CPlaceInner::VarPair(local, var1, var2) => { let layout = layout.field(&*fx, field.index()); From 5bbe685b2637e25573c57736c378f5f353239dd8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 3 Dec 2021 12:20:42 +0100 Subject: [PATCH 64/91] Disable long running libcore tests --- ...8-sysroot-Disable-long-running-tests.patch | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 patches/0028-sysroot-Disable-long-running-tests.patch diff --git a/patches/0028-sysroot-Disable-long-running-tests.patch b/patches/0028-sysroot-Disable-long-running-tests.patch new file mode 100644 index 00000000000..f09d4b47e43 --- /dev/null +++ b/patches/0028-sysroot-Disable-long-running-tests.patch @@ -0,0 +1,30 @@ +From 0ffdd8eda8df364391c8ac6e1ce92c73ba9254d4 Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Fri, 3 Dec 2021 12:16:30 +0100 +Subject: [PATCH] Disable long running tests + +--- + library/core/tests/slice.rs | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs +index 2c8f00a..44847ee 100644 +--- a/library/core/tests/slice.rs ++++ b/library/core/tests/slice.rs +@@ -2332,6 +2332,8 @@ macro_rules! empty_max_mut { + }; + } + ++// These tests take way too long without optimizations ++/* + take_tests! { + slice: &[(); usize::MAX], method: take, + (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), +@@ -2345,3 +2347,4 @@ take_tests! { + (take_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()), + (take_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()), + } ++*/ +-- +2.26.2.7.g19db9cfb68 + From 737708e547714e4d61c77080ac9aaa0877aba1d9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 3 Dec 2021 13:16:34 +0100 Subject: [PATCH 65/91] Test on CI with unstable cg_clif features disabled Part of #1084 --- .github/workflows/main.yml | 6 ++++++ build_system/build_backend.rs | 12 ++++++++++-- y.rs | 9 +++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d2b4b99b6d..7b73d3c00e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,6 +65,12 @@ jobs: git config --global user.name "User" ./y.rs prepare + - name: Build without unstable features + env: + TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} + # This is the config rust-lang/rust uses for builds + run: ./y.rs build --no-unstable-features + - name: Build run: ./y.rs build --sysroot none diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 150b6d01a6b..ccc50ee4a59 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -2,9 +2,17 @@ use std::env; use std::path::{Path, PathBuf}; use std::process::Command; -pub(crate) fn build_backend(channel: &str, host_triple: &str) -> PathBuf { +pub(crate) fn build_backend( + channel: &str, + host_triple: &str, + use_unstable_features: bool, +) -> PathBuf { let mut cmd = Command::new("cargo"); - cmd.arg("build").arg("--target").arg(host_triple).arg("--features").arg("unstable-features"); + cmd.arg("build").arg("--target").arg(host_triple); + + if use_unstable_features { + cmd.arg("--features").arg("unstable-features"); + } match channel { "debug" => {} diff --git a/y.rs b/y.rs index 26605003c42..98b114de910 100755 --- a/y.rs +++ b/y.rs @@ -43,7 +43,9 @@ mod utils; fn usage() { eprintln!("Usage:"); eprintln!(" ./y.rs prepare"); - eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]"); + eprintln!( + " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + ); } macro_rules! arg_error { @@ -92,6 +94,7 @@ fn main() { let mut target_dir = PathBuf::from("build"); let mut channel = "release"; let mut sysroot_kind = SysrootKind::Clif; + let mut use_unstable_features = true; while let Some(arg) = args.next().as_deref() { match arg { "--target-dir" => { @@ -109,6 +112,7 @@ fn main() { None => arg_error!("--sysroot requires argument"), } } + "--no-unstable-features" => use_unstable_features = false, flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), arg => arg_error!("Unexpected argument {}", arg), } @@ -141,7 +145,8 @@ fn main() { process::exit(1); } - let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple); + let cg_clif_build_dir = + build_backend::build_backend(channel, &host_triple, use_unstable_features); build_sysroot::build_sysroot( channel, sysroot_kind, From 0fb1a56479d2c5f9cc327a038ec9d85fd8a9eb94 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 4 Sep 2021 19:25:09 +0200 Subject: [PATCH 66/91] LLVM codgen support for unwinding inline assembly --- src/base.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/base.rs b/src/base.rs index 1b30edd2938..5cf6d95412b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -239,7 +239,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { fx.add_comment(inst, terminator_head); } - fx.set_debug_loc(bb_data.terminator().source_info); + let source_info = bb_data.terminator().source_info; + fx.set_debug_loc(source_info); match &bb_data.terminator().kind { TerminatorKind::Goto { target } => { @@ -295,19 +296,19 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { let len = codegen_operand(fx, len).load_scalar(fx); let index = codegen_operand(fx, index).load_scalar(fx); let location = fx - .get_caller_location(bb_data.terminator().source_info.span) + .get_caller_location(source_info.span) .load_scalar(fx); codegen_panic_inner( fx, rustc_hir::LangItem::PanicBoundsCheck, &[index, len, location], - bb_data.terminator().source_info.span, + source_info.span, ); } _ => { let msg_str = msg.description(); - codegen_panic(fx, msg_str, bb_data.terminator().source_info.span); + codegen_panic(fx, msg_str, source_info.span); } } } @@ -378,10 +379,18 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { options, destination, line_spans: _, + cleanup, } => { + if cleanup.is_some() { + fx.tcx.sess.span_fatal( + source_info.span, + "cranelift doesn't support unwinding from inline assembly.", + ); + } + crate::inline_asm::codegen_inline_asm( fx, - bb_data.terminator().source_info.span, + source_info.span, template, operands, *options, @@ -415,7 +424,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { } TerminatorKind::Drop { place, target, unwind: _ } => { let drop_place = codegen_place(fx, *place); - crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place); + crate::abi::codegen_drop(fx, source_info.span, drop_place); let target_block = fx.get_block(*target); fx.bcx.ins().jump(target_block, &[]); From eeb71f6a84467c55703969c88fb46af5345725ec Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 4 Sep 2021 22:14:09 +0200 Subject: [PATCH 67/91] cg_cranelift: check may_unwind flag instead of cleanup --- src/base.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index 5cf6d95412b..371c71de62f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1,6 +1,7 @@ //! Codegen of a single function use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; +use rustc_ast::InlineAsmOptions; use rustc_index::vec::IndexVec; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::FnAbiOf; @@ -379,9 +380,9 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { options, destination, line_spans: _, - cleanup, + cleanup: _, } => { - if cleanup.is_some() { + if options.contains(InlineAsmOptions::MAY_UNWIND) { fx.tcx.sess.span_fatal( source_info.span, "cranelift doesn't support unwinding from inline assembly.", From 66604300eba99475ca3e128982f1284b5071476e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 4 Dec 2021 15:03:50 +0100 Subject: [PATCH 68/91] Remove black box inline asm fallback It isn't used anymore since the introduction of the black_box intrinsic --- src/inline_asm.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index ba2699316da..595e767cf71 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -18,10 +18,7 @@ pub(crate) fn codegen_inline_asm<'tcx>( ) { // FIXME add .eh_frame unwind info directives - if template.is_empty() { - // Black box - return; - } else if template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string()) { + if template[0] == InlineAsmTemplatePiece::String("int $$0x29".to_string()) { let true_ = fx.bcx.ins().iconst(types::I32, 1); fx.bcx.ins().trapnz(true_, TrapCode::User(1)); return; From cb5d15cf6c0e778c244cc2945d6d8a43e6fcf2a1 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 3 Sep 2021 12:36:33 +0200 Subject: [PATCH 69/91] Use IntoIterator for array impl everywhere. --- scripts/cargo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cargo.rs b/scripts/cargo.rs index 89ec8da77d3..41d82b581cd 100644 --- a/scripts/cargo.rs +++ b/scripts/cargo.rs @@ -42,7 +42,7 @@ fn main() { "RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", ); - std::array::IntoIter::new(["rustc".to_string()]) + IntoIterator::into_iter(["rustc".to_string()]) .chain(env::args().skip(2)) .chain([ "--".to_string(), @@ -56,7 +56,7 @@ fn main() { "RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", ); - std::array::IntoIter::new(["rustc".to_string()]) + IntoIterator::into_iter(["rustc".to_string()]) .chain(env::args().skip(2)) .chain([ "--".to_string(), From cddc5c7cfd6f60bd0e17db0adef7df9c501f2363 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 7 Dec 2021 18:22:44 +0100 Subject: [PATCH 70/91] Rustup to rustc 1.59.0-nightly (041a4cb87 2021-12-06) --- patches/0028-sysroot-Disable-long-running-tests.patch | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/patches/0028-sysroot-Disable-long-running-tests.patch b/patches/0028-sysroot-Disable-long-running-tests.patch index f09d4b47e43..bf74a74c7c4 100644 --- a/patches/0028-sysroot-Disable-long-running-tests.patch +++ b/patches/0028-sysroot-Disable-long-running-tests.patch @@ -11,12 +11,12 @@ diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 2c8f00a..44847ee 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs -@@ -2332,6 +2332,8 @@ macro_rules! empty_max_mut { +@@ -2332,7 +2332,8 @@ macro_rules! empty_max_mut { }; } -+// These tests take way too long without optimizations +/* + #[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) take_tests! { slice: &[(); usize::MAX], method: take, (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), diff --git a/rust-toolchain b/rust-toolchain index f4f8fafa5be..d85e5a0cbfa 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-12-02" +channel = "nightly-2021-12-07" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 53f0af2b04308c1185f9159dce09f3b3f2c0118c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 7 Dec 2021 18:25:27 +0100 Subject: [PATCH 71/91] Use const thread_local! --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 8c93a151349..309d27090b5 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -24,7 +24,7 @@ struct JitState { } thread_local! { - static LAZY_JIT_STATE: RefCell> = RefCell::new(None); + static LAZY_JIT_STATE: RefCell> = const { RefCell::new(None) }; } /// The Sender owned by the rustc thread From d6976f903ac42593b53acce62ffed4a034da9f7c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Dec 2021 13:23:10 +0100 Subject: [PATCH 72/91] Rustup to rustc 1.59.0-nightly (ebd2c2b0c 2021-12-08) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 35d2902fde5..5c7168e62f2 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.108" +version = "0.2.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" +checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index d85e5a0cbfa..d396e526e38 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-12-07" +channel = "nightly-2021-12-09" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From d50df41e4b47ecdd60b7a6d874695892e11e20f6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Dec 2021 13:36:33 +0100 Subject: [PATCH 73/91] Use cg_ssa for creating the dylib metadata file The new api was introduced in rust-lang/rust#91604 --- src/driver/aot.rs | 4 ++- src/lib.rs | 1 - src/metadata.rs | 76 ----------------------------------------------- 3 files changed, 3 insertions(+), 78 deletions(-) delete mode 100644 src/metadata.rs diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 8317f40c7ea..607d76c150b 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; +use rustc_codegen_ssa::back::metadata::create_compressed_metadata_file; use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_metadata::EncodedMetadata; @@ -278,7 +279,8 @@ pub(crate) fn run_aot( let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); - let obj = crate::metadata::new_metadata_object(tcx, &metadata_cgu_name, &metadata); + let symbol_name = rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx); + let obj = create_compressed_metadata_file(tcx.sess, &metadata, &symbol_name); if let Err(err) = std::fs::write(&tmp_file, obj) { tcx.sess.fatal(&format!("error writing metadata object file: {}", err)); diff --git a/src/lib.rs b/src/lib.rs index d752dc9e4f7..fee2ea97a57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,6 @@ mod inline_asm; mod intrinsics; mod linkage; mod main_shim; -mod metadata; mod num; mod optimize; mod pointer; diff --git a/src/metadata.rs b/src/metadata.rs deleted file mode 100644 index 1c8fd0b01d9..00000000000 --- a/src/metadata.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! Writing of the rustc metadata for dylibs - -use object::write::{Object, StandardSegment, Symbol, SymbolSection}; -use object::{SectionKind, SymbolFlags, SymbolKind, SymbolScope}; - -use rustc_metadata::EncodedMetadata; -use rustc_middle::ty::TyCtxt; - -// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 -pub(crate) fn new_metadata_object( - tcx: TyCtxt<'_>, - cgu_name: &str, - metadata: &EncodedMetadata, -) -> Vec { - use snap::write::FrameEncoder; - use std::io::Write; - - let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); - FrameEncoder::new(&mut compressed).write_all(metadata.raw_data()).unwrap(); - - let triple = crate::target_triple(tcx.sess); - - let binary_format = match triple.binary_format { - target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf, - target_lexicon::BinaryFormat::Coff => object::BinaryFormat::Coff, - target_lexicon::BinaryFormat::Macho => object::BinaryFormat::MachO, - binary_format => tcx.sess.fatal(&format!("binary format {} is unsupported", binary_format)), - }; - let architecture = match triple.architecture { - target_lexicon::Architecture::Aarch64(_) => object::Architecture::Aarch64, - target_lexicon::Architecture::Arm(_) => object::Architecture::Arm, - target_lexicon::Architecture::Avr => object::Architecture::Avr, - target_lexicon::Architecture::Hexagon => object::Architecture::Hexagon, - target_lexicon::Architecture::Mips32(_) => object::Architecture::Mips, - target_lexicon::Architecture::Mips64(_) => object::Architecture::Mips64, - target_lexicon::Architecture::Msp430 => object::Architecture::Msp430, - target_lexicon::Architecture::Powerpc => object::Architecture::PowerPc, - target_lexicon::Architecture::Powerpc64 => object::Architecture::PowerPc64, - target_lexicon::Architecture::Powerpc64le => todo!(), - target_lexicon::Architecture::Riscv32(_) => object::Architecture::Riscv32, - target_lexicon::Architecture::Riscv64(_) => object::Architecture::Riscv64, - target_lexicon::Architecture::S390x => object::Architecture::S390x, - target_lexicon::Architecture::Sparc64 => object::Architecture::Sparc64, - target_lexicon::Architecture::Sparcv9 => object::Architecture::Sparc64, - target_lexicon::Architecture::X86_32(_) => object::Architecture::I386, - target_lexicon::Architecture::X86_64 => object::Architecture::X86_64, - architecture => { - tcx.sess.fatal(&format!("target architecture {:?} is unsupported", architecture,)) - } - }; - let endian = match triple.endianness().unwrap() { - target_lexicon::Endianness::Little => object::Endianness::Little, - target_lexicon::Endianness::Big => object::Endianness::Big, - }; - - let mut object = Object::new(binary_format, architecture, endian); - object.add_file_symbol(cgu_name.as_bytes().to_vec()); - - let segment = object.segment_name(StandardSegment::Data).to_vec(); - let section_id = object.add_section(segment, b".rustc".to_vec(), SectionKind::Data); - let offset = object.append_section_data(section_id, &compressed, 1); - // For MachO and probably PE this is necessary to prevent the linker from throwing away the - // .rustc section. For ELF this isn't necessary, but it also doesn't harm. - object.add_symbol(Symbol { - name: rustc_middle::middle::exported_symbols::metadata_symbol_name(tcx).into_bytes(), - value: offset, - size: compressed.len() as u64, - kind: SymbolKind::Data, - scope: SymbolScope::Dynamic, - weak: false, - section: SymbolSection::Section(section_id), - flags: SymbolFlags::None, - }); - - object.write().unwrap() -} From c0e0090caef4291bf0bb05b320abf52dd0771b57 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Dec 2021 13:43:32 +0100 Subject: [PATCH 74/91] Rustfmt --- src/base.rs | 4 +--- src/inline_asm.rs | 7 +++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index f3dd2bf6a3c..2bc2b4a7032 100644 --- a/src/base.rs +++ b/src/base.rs @@ -293,9 +293,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { AssertKind::BoundsCheck { ref len, ref index } => { let len = codegen_operand(fx, len).load_scalar(fx); let index = codegen_operand(fx, index).load_scalar(fx); - let location = fx - .get_caller_location(source_info.span) - .load_scalar(fx); + let location = fx.get_caller_location(source_info.span).load_scalar(fx); codegen_panic_inner( fx, diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 595e767cf71..7c800a46d1b 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -120,8 +120,11 @@ pub(crate) fn codegen_inline_asm<'tcx>( let inline_asm_index = fx.cx.inline_asm_index.get(); fx.cx.inline_asm_index.set(inline_asm_index + 1); - let asm_name = - format!("__inline_asm_{}_n{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index); + let asm_name = format!( + "__inline_asm_{}_n{}", + fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), + inline_asm_index + ); let generated_asm = asm_gen.generate_asm_wrapper(&asm_name); fx.cx.global_asm.push_str(&generated_asm); From d4ba36157ae8c6aa574a8342196c71d69a99c430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 13 Dec 2021 00:00:00 +0000 Subject: [PATCH 75/91] Use `OutputFilenames` to generate output file for `-Zllvm-time-trace` The resulting profile will include the crate name and will be stored in the `--out-dir` directory. This implementation makes it convenient to use LLVM time trace together with cargo, in the contrast to the previous implementation which would overwrite profiles or store them in `.cargo/registry/..`. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index beb97edf09e..fcdf6b50764 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,6 +205,7 @@ impl CodegenBackend for CraneliftCodegenBackend { &self, ongoing_codegen: Box, _sess: &Session, + _outputs: &OutputFilenames, ) -> Result<(CodegenResults, FxHashMap), ErrorReported> { Ok(*ongoing_codegen .downcast::<(CodegenResults, FxHashMap)>() From c9d37d0f07deb786998c28767b2448a6b8ed18a3 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Mon, 13 Dec 2021 20:40:17 +0000 Subject: [PATCH 76/91] Remove invalid doc links. --- src/inline_asm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 09c5e6031c7..f5c9b0b5480 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -1,4 +1,4 @@ -//! Codegen of [`asm!`] invocations. +//! Codegen of `asm!` invocations. use crate::prelude::*; From b86edf752c8c62191bc4d660c3bc0527bdaa567e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 08:32:21 +1100 Subject: [PATCH 77/91] Remove `SymbolStr`. By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`! --- src/constant.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 5c4991f1fb6..9a6c45ae98d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -369,7 +369,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant TodoItem::Static(def_id) => { //println!("static {:?}", def_id); - let section_name = tcx.codegen_fn_attrs(def_id).link_section.map(|s| s.as_str()); + let section_name = tcx.codegen_fn_attrs(def_id).link_section; let alloc = tcx.eval_static_initializer(def_id).unwrap(); @@ -388,6 +388,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant if let Some(section_name) = section_name { let (segment_name, section_name) = if tcx.sess.target.is_like_osx { + let section_name = section_name.as_str(); if let Some(names) = section_name.split_once(',') { names } else { @@ -397,7 +398,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant )); } } else { - ("", &*section_name) + ("", section_name.as_str()) }; data_ctx.set_segment_section(segment_name, section_name); } From b72a1ee7ca8b23405fda0e9542809d6966d34f66 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 14:39:23 +1100 Subject: [PATCH 78/91] Remove unnecessary sigils around `Symbol::as_str()` calls. --- src/driver/aot.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 0a8d6122aa7..c09be5f7597 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -84,7 +84,7 @@ fn reuse_workproduct_for_cgu( let work_product = cgu.work_product(tcx); if let Some(saved_file) = &work_product.saved_file { let obj_out = - tcx.output_filenames(()).temp_path(OutputType::Object, Some(&cgu.name().as_str())); + tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str())); object = Some(obj_out.clone()); let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file); if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { @@ -176,7 +176,7 @@ fn module_codegen( ) }); - codegen_global_asm(tcx, &cgu.name().as_str(), &cx.global_asm); + codegen_global_asm(tcx, cgu.name().as_str(), &cx.global_asm); codegen_result } @@ -207,7 +207,7 @@ pub(crate) fn run_aot( cgus.iter() .map(|cgu| { let cgu_reuse = determine_cgu_reuse(tcx, cgu); - tcx.sess.cgu_reuse_tracker.set_actual_reuse(&cgu.name().as_str(), cgu_reuse); + tcx.sess.cgu_reuse_tracker.set_actual_reuse(cgu.name().as_str(), cgu_reuse); match cgu_reuse { _ if backend_config.disable_incr_cache => {} From e475cb5c42082458156a0377210e75da6a95d8dd Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 15 Dec 2021 16:53:35 +0100 Subject: [PATCH 79/91] Fix crash when struct argument size is not a multiple of the pointer size Fixes #1200 --- src/abi/pass_mode.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index c01ed249904..9f0bd31e95f 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -117,7 +117,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { PassMode::Cast(cast) => cast_target_to_abi_params(cast), PassMode::Indirect { attrs, extra_attrs: None, on_stack } => { if on_stack { - let size = u32::try_from(self.layout.size.bytes()).unwrap(); + // Abi requires aligning struct size to pointer size + let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi); + let size = u32::try_from(size.bytes()).unwrap(); smallvec![apply_arg_attrs_to_abi_param( AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructArgument(size),), attrs From f45521830b5af57f0e576da464d5ee8e9c412063 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 16 Dec 2021 13:51:18 +0100 Subject: [PATCH 80/91] Fix unused crate warning --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fee2ea97a57..adaf5d858c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ #![warn(unused_lifetimes)] #![warn(unreachable_pub)] -extern crate snap; #[macro_use] extern crate rustc_middle; extern crate rustc_ast; From 1f703df7d48fbdf833f54d3bd318fd97473208b3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 16 Dec 2021 14:10:51 +0100 Subject: [PATCH 81/91] Rustup to rustc 1.59.0-nightly (786a18690 2021-12-15) --- build_sysroot/Cargo.lock | 6 +++--- build_system/prepare.rs | 2 +- rust-toolchain | 2 +- scripts/setup_rust_fork.sh | 2 +- src/inline_asm.rs | 12 ++++++++---- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 5c7168e62f2..dd096562480 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.55" +version = "0.1.66" dependencies = [ "rustc-std-workspace-core", ] @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.109" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 0e39320a93c..561e2ed7b00 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -92,7 +92,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.55", + "0.1.66", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/rust-toolchain b/rust-toolchain index d396e526e38..c1d856702a9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-12-09" +channel = "nightly-2021-12-16" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 80bf40dd874..46c3b5b7f11 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -33,7 +33,7 @@ index d95b5b7f17f..00b6f0e3635 100644 [dependencies] core = { path = "../core" } -compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] } -+compiler_builtins = { version = "0.1.53", features = ['rustc-dep-of-std', 'no-asm'] } ++compiler_builtins = { version = "0.1.66", features = ['rustc-dep-of-std', 'no-asm'] } [dev-dependencies] rand = "0.7" diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 30ab7bc4980..93384bc5511 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -317,10 +317,14 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> { let mut new_slot = |x| new_slot_fn(&mut slot_size, x); // Allocate stack slots for saving clobbered registers - let abi_clobber = - InlineAsmClobberAbi::parse(self.arch, &self.tcx.sess.target, Symbol::intern("C")) - .unwrap() - .clobbered_regs(); + let abi_clobber = InlineAsmClobberAbi::parse( + self.arch, + |feature| self.tcx.sess.target_features.contains(&Symbol::intern(feature)), + &self.tcx.sess.target, + Symbol::intern("C"), + ) + .unwrap() + .clobbered_regs(); for (i, reg) in self.registers.iter().enumerate().filter_map(|(i, r)| r.map(|r| (i, r))) { let mut need_save = true; // If the register overlaps with a register clobbered by function call, then From fbbfeb50e153f6bd24516e252cd4688b2501c6fa Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 16 Dec 2021 14:36:02 +0100 Subject: [PATCH 82/91] Rustc tests: ignore a couple more rustdoc tests --- scripts/test_rustc_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 43e090c63c5..99fddf5361e 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -66,7 +66,7 @@ rm src/test/incremental/lto.rs # requires lto rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same -rm -r src/test/run-make/rustdoc-scrape-* # same +rm -r src/test/run-make/rustdoc-* # same rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/pretty/asm.rs # inline asm From 55e51ff7824ce66250f9bf618a6cbc515f22599d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 16 Dec 2021 14:46:43 +0100 Subject: [PATCH 83/91] Update libc --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3050dce50d0..65e142a00f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,9 +182,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.108" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "libloading" From 93c3757915275091adfe68325201dfdd5a017d3a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 16 Dec 2021 18:57:25 +0100 Subject: [PATCH 84/91] Update Cranelift to 0.79.0 --- Cargo.lock | 126 ++++++++++++++++++++++++++++++++++++++++------------- Cargo.toml | 14 +++--- 2 files changed, 103 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65e142a00f8..63052ecf76e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -32,19 +41,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "cranelift-bforest" -version = "0.78.0" +name = "cpufeatures" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc0cb7df82c8cf8f2e6a8dd394a0932a71369c160cc9b027dca414fced242513" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +dependencies = [ + "libc", +] + +[[package]] +name = "cranelift-bforest" +version = "0.79.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0fb5e025141af5b9cbfff4351dc393596d017725f126c954bf472ce78dbba6b" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4463c15fa42eee909e61e5eac4866b7c6d22d0d8c621e57a0c5380753bfa8c" +checksum = "a278c67cc48d0e8ff2275fb6fc31527def4be8f3d81640ecc8cd005a3aa45ded" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -53,37 +71,37 @@ dependencies = [ "gimli", "log", "regalloc", + "sha2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793f6a94a053a55404ea16e1700202a88101672b8cd6b4df63e13cde950852bf" +checksum = "28274c1916c931c5603d94c5479d2ddacaaa574d298814ac1c99964ce92cbe85" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44aa1846df275bce5eb30379d65964c7afc63c05a117076e62a119c25fe174be" +checksum = "5411cf49ab440b749d4da5129dfc45caf6e5fb7b2742b1fe1a421964fda2ee88" [[package]] name = "cranelift-entity" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a45d8d6318bf8fc518154d9298eab2a8154ec068a8885ff113f6db8d69bb3a" +checksum = "64dde596f98462a37b029d81c8567c23cc68b8356b017f12945c545ac0a83203" [[package]] name = "cranelift-frontend" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e07339bd461766deb7605169de039e01954768ff730fa1254e149001884a8525" +checksum = "544605d400710bd9c89924050b30c2e0222a387a5a8b5f04da9a9fdcbd8656a5" dependencies = [ "cranelift-codegen", "log", @@ -93,9 +111,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e8f0d60fb5d67f7a1e5c49db38ba96d1c846921faef02085fc5590b74781747" +checksum = "f05a1b2f9383776eb82c56a331631ab76588d1a184706ec8633db2d58196dc82" dependencies = [ "anyhow", "cranelift-codegen", @@ -111,21 +129,19 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825ac7e0959cbe7ddc9cc21209f0319e611a57f9fcb2b723861fe7ef2017e651" +checksum = "decb7d353b972b60c617ea5b4d09b9574ffc61daef7cd534c060ca728dadc10c" dependencies = [ "anyhow", "cranelift-codegen", - "cranelift-entity", - "log", ] [[package]] name = "cranelift-native" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e2fca76ff57e0532936a71e3fc267eae6a19a86656716479c66e7f912e3d7b" +checksum = "b7f8839befb64f7a39cb855241ae2c8eb74cea27c97fff2a007075fdb8a7f7d4" dependencies = [ "cranelift-codegen", "libc", @@ -134,9 +150,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.78.0" +version = "0.79.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55500d0fc9bb05c0944fc4506649249d28f55bd4fe95b87f0e55bf41058f0e6d" +checksum = "9fe4d91d7e85ad84e3e1b9cf0bba1bb117d35de867e72e4740cb7423d5351792" dependencies = [ "anyhow", "cranelift-codegen", @@ -156,10 +172,29 @@ dependencies = [ ] [[package]] -name = "gimli" -version = "0.25.0" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" dependencies = [ "indexmap", ] @@ -232,10 +267,16 @@ dependencies = [ ] [[package]] -name = "regalloc" -version = "0.0.32" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6304468554ed921da3d32c355ea107b8d13d7b8996c3adfb7aab48d3bc321f4" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "regalloc" +version = "0.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d808cff91dfca7b239d40b972ba628add94892b1d9e19a842aedc5cfae8ab1a" dependencies = [ "log", "rustc-hash", @@ -279,6 +320,19 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "sha2" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + [[package]] name = "smallvec" version = "1.7.0" @@ -291,6 +345,18 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" +[[package]] +name = "typenum" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 87173f26e26..6cf0e81fc59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,14 +8,14 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.78.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.78.0" -cranelift-module = "0.78.0" -cranelift-native = "0.78.0" -cranelift-jit = { version = "0.78.0", optional = true } -cranelift-object = "0.78.0" +cranelift-codegen = { version = "0.79.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.79.0" +cranelift-module = "0.79.0" +cranelift-native = "0.79.0" +cranelift-jit = { version = "0.79.0", optional = true } +cranelift-object = "0.79.0" target-lexicon = "0.12.0" -gimli = { version = "0.25.0", default-features = false, features = ["write"]} +gimli = { version = "0.26.1", default-features = false, features = ["write"] } object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } From e34cd662c027e01efeaf038376b4d2b3ccaee6aa Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 17 Dec 2021 10:58:04 +0100 Subject: [PATCH 85/91] Update cranelift patch section --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6cf0e81fc59..ab79a69e034 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,8 @@ indexmap = "1.0.2" libloading = { version = "0.6.0", optional = true } smallvec = "1.6.1" +[patch.crates-io] # Uncomment to use local checkout of cranelift -#[patch."https://github.com/bytecodealliance/wasmtime.git"] #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } #cranelift-frontend = { path = "../wasmtime/cranelift/frontend" } #cranelift-module = { path = "../wasmtime/cranelift/module" } @@ -32,7 +32,6 @@ smallvec = "1.6.1" #cranelift-jit = { path = "../wasmtime/cranelift/jit" } #cranelift-object = { path = "../wasmtime/cranelift/object" } -#[patch.crates-io] #gimli = { path = "../" } [features] From d99f1a34d8c185f3738f3475208e55a71c539557 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 17 Dec 2021 23:23:17 +0100 Subject: [PATCH 86/91] Revert "Update Cranelift to 0.79.0" This reverts commit 93c3757915275091adfe68325201dfdd5a017d3a. There are two regressions in Cranelift with respect to small integer operations. Both have already been fixed on thebmain branch, but we will have to wait for a new Cranelift release. They have been fixed by bytecodealliance/wasmtime#3610 and bytecodealliance/wasmtime#3617. --- Cargo.lock | 120 ++++++++++++----------------------------------------- Cargo.toml | 14 +++---- 2 files changed, 34 insertions(+), 100 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63052ecf76e..65e142a00f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,44 +25,26 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cpufeatures" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" -dependencies = [ - "libc", -] - [[package]] name = "cranelift-bforest" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0fb5e025141af5b9cbfff4351dc393596d017725f126c954bf472ce78dbba6b" +checksum = "cc0cb7df82c8cf8f2e6a8dd394a0932a71369c160cc9b027dca414fced242513" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a278c67cc48d0e8ff2275fb6fc31527def4be8f3d81640ecc8cd005a3aa45ded" +checksum = "fe4463c15fa42eee909e61e5eac4866b7c6d22d0d8c621e57a0c5380753bfa8c" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -71,37 +53,37 @@ dependencies = [ "gimli", "log", "regalloc", - "sha2", "smallvec", "target-lexicon", ] [[package]] name = "cranelift-codegen-meta" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28274c1916c931c5603d94c5479d2ddacaaa574d298814ac1c99964ce92cbe85" +checksum = "793f6a94a053a55404ea16e1700202a88101672b8cd6b4df63e13cde950852bf" dependencies = [ "cranelift-codegen-shared", + "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5411cf49ab440b749d4da5129dfc45caf6e5fb7b2742b1fe1a421964fda2ee88" +checksum = "44aa1846df275bce5eb30379d65964c7afc63c05a117076e62a119c25fe174be" [[package]] name = "cranelift-entity" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64dde596f98462a37b029d81c8567c23cc68b8356b017f12945c545ac0a83203" +checksum = "a3a45d8d6318bf8fc518154d9298eab2a8154ec068a8885ff113f6db8d69bb3a" [[package]] name = "cranelift-frontend" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "544605d400710bd9c89924050b30c2e0222a387a5a8b5f04da9a9fdcbd8656a5" +checksum = "e07339bd461766deb7605169de039e01954768ff730fa1254e149001884a8525" dependencies = [ "cranelift-codegen", "log", @@ -111,9 +93,9 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05a1b2f9383776eb82c56a331631ab76588d1a184706ec8633db2d58196dc82" +checksum = "0e8f0d60fb5d67f7a1e5c49db38ba96d1c846921faef02085fc5590b74781747" dependencies = [ "anyhow", "cranelift-codegen", @@ -129,19 +111,21 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "decb7d353b972b60c617ea5b4d09b9574ffc61daef7cd534c060ca728dadc10c" +checksum = "825ac7e0959cbe7ddc9cc21209f0319e611a57f9fcb2b723861fe7ef2017e651" dependencies = [ "anyhow", "cranelift-codegen", + "cranelift-entity", + "log", ] [[package]] name = "cranelift-native" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f8839befb64f7a39cb855241ae2c8eb74cea27c97fff2a007075fdb8a7f7d4" +checksum = "03e2fca76ff57e0532936a71e3fc267eae6a19a86656716479c66e7f912e3d7b" dependencies = [ "cranelift-codegen", "libc", @@ -150,9 +134,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.79.0" +version = "0.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fe4d91d7e85ad84e3e1b9cf0bba1bb117d35de867e72e4740cb7423d5351792" +checksum = "55500d0fc9bb05c0944fc4506649249d28f55bd4fe95b87f0e55bf41058f0e6d" dependencies = [ "anyhow", "cranelift-codegen", @@ -171,30 +155,11 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "generic-array" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "gimli" -version = "0.26.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" +checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" dependencies = [ "indexmap", ] @@ -266,17 +231,11 @@ dependencies = [ "memchr", ] -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "regalloc" -version = "0.0.33" +version = "0.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d808cff91dfca7b239d40b972ba628add94892b1d9e19a842aedc5cfae8ab1a" +checksum = "a6304468554ed921da3d32c355ea107b8d13d7b8996c3adfb7aab48d3bc321f4" dependencies = [ "log", "rustc-hash", @@ -320,19 +279,6 @@ dependencies = [ "target-lexicon", ] -[[package]] -name = "sha2" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" -dependencies = [ - "block-buffer", - "cfg-if", - "cpufeatures", - "digest", - "opaque-debug", -] - [[package]] name = "smallvec" version = "1.7.0" @@ -345,18 +291,6 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9bffcddbc2458fa3e6058414599e3c838a022abae82e5c67b4f7f80298d5bff" -[[package]] -name = "typenum" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" - -[[package]] -name = "version_check" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index ab79a69e034..900411286b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,14 +8,14 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.79.0", features = ["unwind", "all-arch"] } -cranelift-frontend = "0.79.0" -cranelift-module = "0.79.0" -cranelift-native = "0.79.0" -cranelift-jit = { version = "0.79.0", optional = true } -cranelift-object = "0.79.0" +cranelift-codegen = { version = "0.78.0", features = ["unwind", "all-arch"] } +cranelift-frontend = "0.78.0" +cranelift-module = "0.78.0" +cranelift-native = "0.78.0" +cranelift-jit = { version = "0.78.0", optional = true } +cranelift-object = "0.78.0" target-lexicon = "0.12.0" -gimli = { version = "0.26.1", default-features = false, features = ["write"] } +gimli = { version = "0.25.0", default-features = false, features = ["write"]} object = { version = "0.27.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } From b96b02d410badb30f79ae648858d879fee6d4112 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 18 Dec 2021 15:33:31 +0100 Subject: [PATCH 87/91] Slightly reduce the amount of fx.module references --- src/base.rs | 8 +++++--- src/common.rs | 2 ++ src/intrinsics/mod.rs | 10 +++++----- src/value_and_place.rs | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/base.rs b/src/base.rs index 2bc2b4a7032..fc2f04f146e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -49,13 +49,15 @@ pub(crate) fn codegen_fn<'tcx>( (0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect(); // Make FunctionCx - let pointer_type = module.target_config().pointer_type(); + let target_config = module.target_config(); + let pointer_type = target_config.pointer_type(); let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance); let mut fx = FunctionCx { cx, module, tcx, + target_config, pointer_type, constants_cx: ConstantCx::new(), @@ -676,7 +678,7 @@ fn codegen_stmt<'tcx>( // FIXME use emit_small_memset where possible let addr = lval.to_ptr().get_addr(fx); let val = operand.load_scalar(fx); - fx.bcx.call_memset(fx.module.target_config(), addr, val, times); + fx.bcx.call_memset(fx.target_config, addr, val, times); } else { let loop_block = fx.bcx.create_block(); let loop_block2 = fx.bcx.create_block(); @@ -797,7 +799,7 @@ fn codegen_stmt<'tcx>( let elem_size: u64 = pointee.size.bytes(); let bytes = if elem_size != 1 { fx.bcx.ins().imul_imm(count, elem_size as i64) } else { count }; - fx.bcx.call_memcpy(fx.module.target_config(), dst, src, bytes); + fx.bcx.call_memcpy(fx.target_config, dst, src, bytes); } } } diff --git a/src/common.rs b/src/common.rs index 2ed497a6f94..1df53151002 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,3 +1,4 @@ +use cranelift_codegen::isa::TargetFrontendConfig; use rustc_index::vec::IndexVec; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, @@ -235,6 +236,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) cx: &'clif mut crate::CodegenCx<'tcx>, pub(crate) module: &'m mut dyn Module, pub(crate) tcx: TyCtxt<'tcx>, + pub(crate) target_config: TargetFrontendConfig, // Cached from module pub(crate) pointer_type: Type, // Cached from module pub(crate) constants_cx: ConstantCx, diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 313b62c5770..8eb07bffe9e 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -503,10 +503,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( if intrinsic == sym::copy_nonoverlapping { // FIXME emit_small_memcpy - fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount); + fx.bcx.call_memcpy(fx.target_config, dst, src, byte_amount); } else { // FIXME emit_small_memmove - fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount); + fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount); } }; // NOTE: the volatile variants have src and dst swapped @@ -522,10 +522,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( // FIXME make the copy actually volatile when using emit_small_mem{cpy,move} if intrinsic == sym::volatile_copy_nonoverlapping_memory { // FIXME emit_small_memcpy - fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount); + fx.bcx.call_memcpy(fx.target_config, dst, src, byte_amount); } else { // FIXME emit_small_memmove - fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount); + fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount); } }; size_of_val, (c ptr) { @@ -673,7 +673,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( let dst_ptr = dst.load_scalar(fx); // FIXME make the memset actually volatile when switching to emit_small_memset // FIXME use emit_small_memset - fx.bcx.call_memset(fx.module.target_config(), dst_ptr, val, count); + fx.bcx.call_memset(fx.target_config, dst_ptr, val, count); }; ctlz | ctlz_nonzero, (v arg) { // FIXME trap on `ctlz_nonzero` with zero arg. diff --git a/src/value_and_place.rs b/src/value_and_place.rs index d5c7e2cc297..52541d5b496 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -601,7 +601,7 @@ impl<'tcx> CPlace<'tcx> { let src_align = src_layout.align.abi.bytes() as u8; let dst_align = dst_layout.align.abi.bytes() as u8; fx.bcx.emit_small_memory_copy( - fx.module.target_config(), + fx.target_config, to_addr, from_addr, size, From b408f182efd4e6c8bc07671dc83a6233670ce7a6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 18 Dec 2021 15:46:30 +0100 Subject: [PATCH 88/91] Remove triple method from FunctionCx Instead use the default_call_conv field on TargetFrontendConfig to get the default CallConv. --- src/abi/mod.rs | 14 +++++++------- src/common.rs | 4 ---- src/intrinsics/mod.rs | 2 +- src/trap.rs | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 78fdf9c02d0..72ebc84c1a3 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -18,11 +18,11 @@ pub(crate) use self::returning::codegen_return; fn clif_sig_from_fn_abi<'tcx>( tcx: TyCtxt<'tcx>, - triple: &target_lexicon::Triple, + default_call_conv: CallConv, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> Signature { let call_conv = match fn_abi.conv { - Conv::Rust | Conv::C => CallConv::triple_default(triple), + Conv::Rust | Conv::C => default_call_conv, Conv::X86_64SysV => CallConv::SystemV, Conv::X86_64Win64 => CallConv::WindowsFastcall, Conv::ArmAapcs @@ -55,7 +55,7 @@ pub(crate) fn get_function_sig<'tcx>( assert!(!inst.substs.needs_infer()); clif_sig_from_fn_abi( tcx, - triple, + CallConv::triple_default(triple), &RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()), ) } @@ -91,7 +91,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { returns: Vec, args: &[Value], ) -> &[Value] { - let sig = Signature { params, returns, call_conv: CallConv::triple_default(self.triple()) }; + let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv }; let func_id = self.module.declare_function(name, Linkage::Import, &sig).unwrap(); let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func); let call_inst = self.bcx.ins().call(func_ref, args); @@ -420,7 +420,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0].value, idx); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); (CallTarget::Indirect(sig, method), Some(ptr)) @@ -440,7 +440,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } let func = codegen_operand(fx, func).load_scalar(fx); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); (CallTarget::Indirect(sig, func), None) @@ -531,7 +531,7 @@ pub(crate) fn codegen_drop<'tcx>( let fn_abi = RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty()); - let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi); + let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); let sig = fx.bcx.import_signature(sig); fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); } diff --git a/src/common.rs b/src/common.rs index 1df53151002..644204d10b8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -359,10 +359,6 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty()) } - pub(crate) fn triple(&self) -> &target_lexicon::Triple { - self.module.isa().triple() - } - pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { let mut data_ctx = DataContext::new(); data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice()); diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 8eb07bffe9e..f4703b22ecb 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1067,7 +1067,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( kw.Try, (v f, v data, v _catch_fn) { // FIXME once unwinding is supported, change this to actually catch panics let f_sig = fx.bcx.func.import_signature(Signature { - call_conv: CallConv::triple_default(fx.triple()), + call_conv: fx.target_config.default_call_conv, params: vec![AbiParam::new(fx.bcx.func.dfg.value_type(data))], returns: vec![], }); diff --git a/src/trap.rs b/src/trap.rs index fe8d20fa39f..99b5366e349 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -9,7 +9,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { "puts", Linkage::Import, &Signature { - call_conv: CallConv::triple_default(fx.triple()), + call_conv: fx.target_config.default_call_conv, params: vec![AbiParam::new(fx.pointer_type)], returns: vec![AbiParam::new(types::I32)], }, From 1d57b812cce6713554894f401277458fd6f79544 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 18 Dec 2021 18:55:33 +0100 Subject: [PATCH 89/91] Add cron job to test against latest cranelift version every day Fixes #1212 --- .github/workflows/nightly-cranelift.yml | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/nightly-cranelift.yml diff --git a/.github/workflows/nightly-cranelift.yml b/.github/workflows/nightly-cranelift.yml new file mode 100644 index 00000000000..c5b96a47828 --- /dev/null +++ b/.github/workflows/nightly-cranelift.yml @@ -0,0 +1,59 @@ +name: Test nightly Cranelift + +on: + push: + schedule: + - cron: '1 17 * * *' # At 01:17 UTC every day. + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + + steps: + - uses: actions/checkout@v2 + + - name: Cache cargo installed crates + uses: actions/cache@v2 + with: + path: ~/.cargo/bin + key: ubuntu-latest-cargo-installed-crates + + - name: Prepare dependencies + run: | + git config --global user.email "user@example.com" + git config --global user.name "User" + ./y.rs prepare + + - name: Patch Cranelift + run: | + sed -i 's/cranelift-codegen = { version = "\w*.\w*.\w*", features = \["unwind", "all-arch"\] }/cranelift-codegen = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git", features = ["unwind", "all-arch"] }/' Cargo.toml + sed -i 's/cranelift-frontend = "\w*.\w*.\w*"/cranelift-frontend = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml + sed -i 's/cranelift-module = "\w*.\w*.\w*"/cranelift-module = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml + sed -i 's/cranelift-native = "\w*.\w*.\w*"/cranelift-native = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml + sed -i 's/cranelift-jit = { version = "\w*.\w*.\w*", optional = true }/cranelift-jit = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git", optional = true }/' Cargo.toml + sed -i 's/cranelift-object = "\w*.\w*.\w*"/cranelift-object = { git = "https:\/\/github.com\/bytecodealliance\/wasmtime.git" }/' Cargo.toml + + sed -i 's/gimli = { version = "0.25.0", default-features = false, features = \["write"\]}/gimli = { version = "0.26.1", default-features = false, features = ["write"] }/' Cargo.toml + + cat Cargo.toml + + - name: Build without unstable features + # This is the config rust-lang/rust uses for builds + run: ./y.rs build --no-unstable-features + + - name: Build + run: ./y.rs build --sysroot none + - name: Test + run: | + # Enable backtraces for easier debugging + export RUST_BACKTRACE=1 + + # Reduce amount of benchmark runs as they are slow + export COMPILE_RUNS=2 + export RUN_RUNS=2 + + # Enable extra checks + export CG_CLIF_ENABLE_VERIFIER=1 + + ./test.sh From 5f9fbd93355dad47c79518b46f2f44fa26af63d3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 20 Dec 2021 18:21:55 +0100 Subject: [PATCH 90/91] Rustup to rustc 1.59.0-nightly (efdb576da 2021-12-19) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index c1d856702a9..7b5db307a2d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-12-16" +channel = "nightly-2021-12-20" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From b2fb4a20baf301ad823d67c4665faf4ac7bf69c9 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 20 Dec 2021 18:49:43 +0100 Subject: [PATCH 91/91] Fix taking address of truly unsized type field of unsized adt --- example/issue-91827-extern-types.rs | 60 +++++++++++++++++++++++++++++ scripts/tests.sh | 4 ++ src/value_and_place.rs | 7 +++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 example/issue-91827-extern-types.rs diff --git a/example/issue-91827-extern-types.rs b/example/issue-91827-extern-types.rs new file mode 100644 index 00000000000..cf8fada5320 --- /dev/null +++ b/example/issue-91827-extern-types.rs @@ -0,0 +1,60 @@ +// Copied from rustc ui test suite + +// run-pass +// +// Test that we can handle unsized types with an extern type tail part. +// Regression test for issue #91827. + +#![feature(const_ptr_offset_from)] +#![feature(const_slice_from_raw_parts)] +#![feature(extern_types)] + +use std::ptr::addr_of; + +extern "C" { + type Opaque; +} + +unsafe impl Sync for Opaque {} + +#[repr(C)] +pub struct List { + len: usize, + data: [T; 0], + tail: Opaque, +} + +#[repr(C)] +pub struct ListImpl { + len: usize, + data: [T; N], +} + +impl List { + const fn as_slice(&self) -> &[T] { + unsafe { std::slice::from_raw_parts(self.data.as_ptr(), self.len) } + } +} + +impl ListImpl { + const fn as_list(&self) -> &List { + unsafe { std::mem::transmute(self) } + } +} + +pub static A: ListImpl = ListImpl { + len: 3, + data: [5, 6, 7], +}; +pub static A_REF: &'static List = A.as_list(); +pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list()); + +const fn tail_offset(list: &List) -> isize { + unsafe { (addr_of!(list.tail) as *const u8).offset_from(list as *const List as *const u8) } +} + +fn main() { + assert_eq!(A_REF.as_slice(), &[5, 6, 7]); + // Check that interpreter and code generation agree about the position of the tail field. + assert_eq!(A_TAIL_OFFSET, tail_offset(A_REF)); +} diff --git a/scripts/tests.sh b/scripts/tests.sh index 28a7980d661..fd2b3761ff0 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -35,6 +35,10 @@ function base_sysroot_tests() { $MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target "$TARGET_TRIPLE" $RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers + echo "[AOT] issue_91827_extern_types" + $MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE" + $RUN_WRAPPER ./target/out/issue_91827_extern_types + echo "[AOT] alloc_system" $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE" diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 52541d5b496..f29d13ccabd 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -672,7 +672,12 @@ impl<'tcx> CPlace<'tcx> { let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field); if field_layout.is_unsized() { - CPlace::for_ptr_with_extra(field_ptr, extra.unwrap(), field_layout) + if let ty::Foreign(_) = field_layout.ty.kind() { + assert!(extra.is_none()); + CPlace::for_ptr(field_ptr, field_layout) + } else { + CPlace::for_ptr_with_extra(field_ptr, extra.unwrap(), field_layout) + } } else { CPlace::for_ptr(field_ptr, field_layout) }