From 528c4f9158ead3df8cecb51663db50e711fec377 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sun, 19 Dec 2021 00:43:46 +0100 Subject: [PATCH 01/20] Add PanicInfo::can_unwind which indicates whether a panic handler is allowed to trigger unwinding. --- library/core/src/panic/panic_info.rs | 16 +++++++++++++++- library/core/src/panicking.rs | 2 +- library/std/src/lib.rs | 1 + library/std/src/panicking.rs | 22 ++++++++++++++-------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index d8e421df5de5d..405224f8fb0b0 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -31,6 +31,7 @@ pub struct PanicInfo<'a> { payload: &'a (dyn Any + Send), message: Option<&'a fmt::Arguments<'a>>, location: &'a Location<'a>, + can_unwind: bool, } impl<'a> PanicInfo<'a> { @@ -44,9 +45,10 @@ impl<'a> PanicInfo<'a> { pub fn internal_constructor( message: Option<&'a fmt::Arguments<'a>>, location: &'a Location<'a>, + can_unwind: bool, ) -> Self { struct NoPayload; - PanicInfo { location, message, payload: &NoPayload } + PanicInfo { location, message, payload: &NoPayload, can_unwind } } #[unstable( @@ -127,6 +129,18 @@ impl<'a> PanicInfo<'a> { // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. Some(&self.location) } + + /// Returns whether the panic handler is allowed to unwind the stack from + /// the point where the panic occurred. + /// + /// This is true for most kinds of panics with the exception of panics + /// caused by trying to unwind out of a `Drop` implementation or a function + /// whose ABI does not support unwinding. + #[must_use] + #[unstable(feature = "panic_can_unwind", issue = "92988")] + pub fn can_unwind(&self) -> bool { + self.can_unwind + } } #[stable(feature = "panic_hook_display", since = "1.26.0")] diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index ccb82cda54ef7..f260f19127b0b 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -104,7 +104,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { fn panic_impl(pi: &PanicInfo<'_>) -> !; } - let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller()); + let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), true); // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. unsafe { panic_impl(&pi) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 1721e16f3a686..0b2a864b7f746 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -312,6 +312,7 @@ #![feature(once_cell)] #![feature(panic_info_message)] #![feature(panic_internals)] +#![feature(panic_can_unwind)] #![feature(panic_unwind)] #![feature(pin_static_ref)] #![feature(portable_simd)] diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 44f573297eed1..c08d693f81a5f 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -576,9 +576,14 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { let msg = info.message().unwrap(); // The current implementation always returns Some crate::sys_common::backtrace::__rust_end_short_backtrace(move || { if let Some(msg) = msg.as_str() { - rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc); + rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc, info.can_unwind()); } else { - rust_panic_with_hook(&mut PanicPayload::new(msg), info.message(), loc); + rust_panic_with_hook( + &mut PanicPayload::new(msg), + info.message(), + loc, + info.can_unwind(), + ); } }) } @@ -602,7 +607,7 @@ pub const fn begin_panic(msg: M) -> ! { let loc = Location::caller(); return crate::sys_common::backtrace::__rust_end_short_backtrace(move || { - rust_panic_with_hook(&mut PanicPayload::new(msg), None, loc) + rust_panic_with_hook(&mut PanicPayload::new(msg), None, loc, true) }); struct PanicPayload { @@ -647,6 +652,7 @@ fn rust_panic_with_hook( payload: &mut dyn BoxMeUp, message: Option<&fmt::Arguments<'_>>, location: &Location<'_>, + can_unwind: bool, ) -> ! { let (must_abort, panics) = panic_count::increase(); @@ -663,14 +669,14 @@ fn rust_panic_with_hook( } else { // Unfortunately, this does not print a backtrace, because creating // a `Backtrace` will allocate, which we must to avoid here. - let panicinfo = PanicInfo::internal_constructor(message, location); + let panicinfo = PanicInfo::internal_constructor(message, location, can_unwind); rtprintpanic!("{}\npanicked after panic::always_abort(), aborting.\n", panicinfo); } - intrinsics::abort() + crate::sys::abort_internal(); } unsafe { - let mut info = PanicInfo::internal_constructor(message, location); + let mut info = PanicInfo::internal_constructor(message, location, can_unwind); let _guard = HOOK_LOCK.read(); match HOOK { // Some platforms (like wasm) know that printing to stderr won't ever actually @@ -691,13 +697,13 @@ fn rust_panic_with_hook( }; } - if panics > 1 { + if panics > 1 || !can_unwind { // If a thread panics while it's already unwinding then we // have limited options. Currently our preference is to // just abort. In the future we may consider resuming // unwinding or otherwise exiting the thread cleanly. rtprintpanic!("thread panicked while panicking. aborting.\n"); - intrinsics::abort() + crate::sys::abort_internal(); } rust_panic(payload) From fe9dc6e62a312bc2fe01bb5ea65ea5d027ce878d Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 12 Jan 2022 20:45:31 +0000 Subject: [PATCH 02/20] Change TerminatorKind::Abort to call the panic handler instead of aborting immediately. The panic handler is called with a special flag which forces it to abort after calling the panic hook. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 27 +++++++++++++++++--- compiler/rustc_hir/src/lang_items.rs | 1 + compiler/rustc_monomorphize/src/collector.rs | 10 +++++++- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/panicking.rs | 25 ++++++++++++++++++ src/test/codegen/unwind-and-panic-abort.rs | 2 +- 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 5ce4e606fd20b..b1a76b80002db 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -477,6 +477,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { helper.do_call(self, &mut bx, fn_abi, llfn, &args, None, cleanup); } + fn codegen_abort_terminator( + &mut self, + helper: TerminatorCodegenHelper<'tcx>, + mut bx: Bx, + terminator: &mir::Terminator<'tcx>, + ) { + let span = terminator.source_info.span; + self.set_debug_loc(&mut bx, terminator.source_info); + + // Get the location information. + let location = self.get_caller_location(&mut bx, terminator.source_info).immediate(); + + // Obtain the panic entry point. + let def_id = common::langcall(bx.tcx(), Some(span), "", LangItem::PanicNoUnwind); + let instance = ty::Instance::mono(bx.tcx(), def_id); + let fn_abi = bx.fn_abi_of_instance(instance, ty::List::empty()); + let llfn = bx.get_fn_addr(instance); + + // Codegen the actual panic invoke/call. + helper.do_call(self, &mut bx, fn_abi, llfn, &[location], None, None); + } + /// Returns `true` if this is indeed a panic intrinsic and codegen is done. fn codegen_panic_intrinsic( &mut self, @@ -1014,10 +1036,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::TerminatorKind::Resume => self.codegen_resume_terminator(helper, bx), mir::TerminatorKind::Abort => { - bx.abort(); - // `abort` does not terminate the block, so we still need to generate - // an `unreachable` terminator after it. - bx.unreachable(); + self.codegen_abort_terminator(helper, bx, terminator); } mir::TerminatorKind::Goto { target } => { diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index def0c1d06871b..be4849d0b846e 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -283,6 +283,7 @@ language_item_table! { PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None; PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None; PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None; + PanicNoUnwind, sym::panic_no_unwind, panic_no_unwind, Target::Fn, GenericRequirement::Exact(0); /// libstd panic entry point. Necessary for const eval to be able to catch it BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 7e7f693870656..7f13da5d38f87 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -807,10 +807,18 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { self.output.push(create_fn_mono_item(tcx, instance, source)); } } + mir::TerminatorKind::Abort { .. } => { + let instance = Instance::mono( + tcx, + tcx.require_lang_item(LangItem::PanicNoUnwind, Some(source)), + ); + if should_codegen_locally(tcx, &instance) { + self.output.push(create_fn_mono_item(tcx, instance, source)); + } + } mir::TerminatorKind::Goto { .. } | mir::TerminatorKind::SwitchInt { .. } | mir::TerminatorKind::Resume - | mir::TerminatorKind::Abort | mir::TerminatorKind::Return | mir::TerminatorKind::Unreachable => {} mir::TerminatorKind::GeneratorDrop diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 14ac286476ca9..1e9c8eab2a98a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -983,6 +983,7 @@ symbols! { panic_implementation, panic_info, panic_location, + panic_no_unwind, panic_runtime, panic_str, panic_unwind, diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index f260f19127b0b..5078eea07a15c 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -77,6 +77,31 @@ fn panic_bounds_check(index: usize, len: usize) -> ! { panic!("index out of bounds: the len is {} but the index is {}", len, index) } +#[cfg(not(bootstrap))] +#[cold] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))] +#[track_caller] +#[lang = "panic_no_unwind"] // needed by codegen for panic in nounwind function +fn panic_no_unwind() -> ! { + if cfg!(feature = "panic_immediate_abort") { + super::intrinsics::abort() + } + + // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call + // that gets resolved to the `#[panic_handler]` function. + extern "Rust" { + #[lang = "panic_impl"] + fn panic_impl(pi: &PanicInfo<'_>) -> !; + } + + // PanicInfo with the `can_unwind` flag set to false forces an abort. + let fmt = format_args!("panic in a function that cannot unwind"); + let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller(), false); + + // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. + unsafe { panic_impl(&pi) } +} + /// The entry point for panicking with a formatted message. /// /// This is designed to reduce the amount of code required at the call diff --git a/src/test/codegen/unwind-and-panic-abort.rs b/src/test/codegen/unwind-and-panic-abort.rs index 05d97f3256aca..f238741e599f6 100644 --- a/src/test/codegen/unwind-and-panic-abort.rs +++ b/src/test/codegen/unwind-and-panic-abort.rs @@ -9,7 +9,7 @@ extern "C-unwind" { // CHECK: Function Attrs:{{.*}}nounwind // CHECK-NEXT: define{{.*}}void @foo -// CHECK: call void @llvm.trap() +// CHECK: call void @_ZN4core9panicking15panic_no_unwind #[no_mangle] pub unsafe extern "C" fn foo() { bar(); From ecd39aae0ea07271181978494391c19e26bcb29b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 17 Jan 2022 20:58:42 +0100 Subject: [PATCH 03/20] Update pulldown-cmark version to fix markdown list issue --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18b85103202e3..bb130bd4ef3fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,7 +686,7 @@ dependencies = [ "clippy_utils", "if_chain", "itertools 0.10.1", - "pulldown-cmark 0.9.0", + "pulldown-cmark 0.9.1", "quine-mc_cluskey", "regex-syntax", "rustc-semver", @@ -2885,9 +2885,9 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd16514d1af5f7a71f909a44ef253cdb712a376d7ebc8ae4a471a9be9743548" +checksum = "34f197a544b0c9ab3ae46c359a7ec9cbbb5c7bf97054266fecb7ead794a181d6" dependencies = [ "bitflags", "memchr", @@ -4447,7 +4447,7 @@ dependencies = [ "expect-test", "itertools 0.9.0", "minifier", - "pulldown-cmark 0.9.0", + "pulldown-cmark 0.9.1", "rayon", "regex", "rustdoc-json-types", From 80b26bd4016898ebbcee7287faf75d71dab6e541 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 19 Jan 2022 11:02:24 +0100 Subject: [PATCH 04/20] Update dependencies --- Cargo.lock | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb130bd4ef3fb..8eae11b98a93e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,7 +686,7 @@ dependencies = [ "clippy_utils", "if_chain", "itertools 0.10.1", - "pulldown-cmark 0.9.1", + "pulldown-cmark", "quine-mc_cluskey", "regex-syntax", "rustc-semver", @@ -2183,9 +2183,9 @@ dependencies = [ [[package]] name = "mdbook" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e77253c46a90eb7e96b2807201dab941a4db5ea05eca5aaaf7027395f352b3" +checksum = "241f10687eb3b4e0634b3b4e423f97c5f1efbd69dc9522e24a8b94583eeec3c6" dependencies = [ "ammonia", "anyhow", @@ -2198,7 +2198,7 @@ dependencies = [ "log", "memchr", "opener", - "pulldown-cmark 0.8.0", + "pulldown-cmark", "regex", "serde", "serde_derive", @@ -2871,18 +2871,6 @@ dependencies = [ "cc", ] -[[package]] -name = "pulldown-cmark" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8" -dependencies = [ - "bitflags", - "getopts", - "memchr", - "unicase", -] - [[package]] name = "pulldown-cmark" version = "0.9.1" @@ -2890,6 +2878,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34f197a544b0c9ab3ae46c359a7ec9cbbb5c7bf97054266fecb7ead794a181d6" dependencies = [ "bitflags", + "getopts", "memchr", "unicase", ] @@ -4447,7 +4436,7 @@ dependencies = [ "expect-test", "itertools 0.9.0", "minifier", - "pulldown-cmark 0.9.1", + "pulldown-cmark", "rayon", "regex", "rustdoc-json-types", From 8d0d023964002f41be1b1e4fda7549024bf68285 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 20 Jan 2022 15:41:00 +0100 Subject: [PATCH 05/20] Simplify use of `map_or` --- compiler/rustc_mir_transform/src/coverage/graph.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index a25402a1ff9f5..f7cd95785ea8d 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -418,7 +418,7 @@ impl BasicCoverageBlockData { pub fn take_edge_counters( &mut self, ) -> Option> { - self.edge_from_bcbs.take().map_or(None, |m| Some(m.into_iter())) + self.edge_from_bcbs.take().map(|m| m.into_iter()) } pub fn id(&self) -> String { From 1521b53c532ccd90c504b0c860cd5662172cc05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 20 Jan 2022 22:14:02 +0100 Subject: [PATCH 06/20] Increase the format version of rustdoc-json-types --- src/rustdoc-json-types/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 618c8aab86a19..600833664be5e 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -8,6 +8,9 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; +/// rustdoc format-version. +pub const FORMAT_VERSION: u32 = 10; + /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow /// tools to find or link to them. @@ -517,8 +520,5 @@ pub struct Static { pub expr: String, } -/// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 9; - #[cfg(test)] mod tests; From c55819ae606046e2a7b6b92c3f0821bd171f34b0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 21 Jan 2022 10:14:18 +1100 Subject: [PATCH 07/20] Make stability interning follow the usual pattern. --- compiler/rustc_middle/src/ty/context.rs | 32 ++++++++++--------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index e7b99995ca4ae..de435b8f58c72 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -113,6 +113,12 @@ pub struct CtxtInterners<'tcx> { bound_variable_kinds: InternedSet<'tcx, List>, layout: InternedSet<'tcx, Layout>, adt_def: InternedSet<'tcx, AdtDef>, + + /// `#[stable]` and `#[unstable]` attributes + stability: InternedSet<'tcx, attr::Stability>, + + /// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes + const_stability: InternedSet<'tcx, attr::ConstStability>, } impl<'tcx> CtxtInterners<'tcx> { @@ -134,6 +140,8 @@ impl<'tcx> CtxtInterners<'tcx> { bound_variable_kinds: Default::default(), layout: Default::default(), adt_def: Default::default(), + stability: Default::default(), + const_stability: Default::default(), } } @@ -1035,12 +1043,6 @@ pub struct GlobalCtxt<'tcx> { /// Data layout specification for the current target. pub data_layout: TargetDataLayout, - /// `#[stable]` and `#[unstable]` attributes - stability_interner: ShardedHashMap<&'tcx attr::Stability, ()>, - - /// `#[rustc_const_stable]` and `#[rustc_const_unstable]` attributes - const_stability_interner: ShardedHashMap<&'tcx attr::ConstStability, ()>, - /// Stores memory for globals (statics/consts). pub(crate) alloc_map: Lock>, @@ -1092,16 +1094,6 @@ impl<'tcx> TyCtxt<'tcx> { self.create_memory_alloc(alloc) } - // FIXME(eddyb) move to `direct_interners!`. - pub fn intern_stability(self, stab: attr::Stability) -> &'tcx attr::Stability { - self.stability_interner.intern(stab, |stab| self.arena.alloc(stab)) - } - - // FIXME(eddyb) move to `direct_interners!`. - pub fn intern_const_stability(self, stab: attr::ConstStability) -> &'tcx attr::ConstStability { - self.const_stability_interner.intern(stab, |stab| self.arena.alloc(stab)) - } - /// Returns a range of the start/end indices specified with the /// `rustc_layout_scalar_valid_range` attribute. // FIXME(eddyb) this is an awkward spot for this method, maybe move it? @@ -1185,8 +1177,6 @@ impl<'tcx> TyCtxt<'tcx> { evaluation_cache: Default::default(), crate_name: Symbol::intern(crate_name), data_layout, - stability_interner: Default::default(), - const_stability_interner: Default::default(), alloc_map: Lock::new(interpret::AllocMap::new()), output_filenames: Arc::new(output_filenames), } @@ -1935,11 +1925,11 @@ impl<'tcx> TyCtxt<'tcx> { writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?; writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?; - writeln!(fmt, "Stability interner: #{}", self.0.stability_interner.len())?; + writeln!(fmt, "Stability interner: #{}", self.0.interners.stability.len())?; writeln!( fmt, "Const Stability interner: #{}", - self.0.const_stability_interner.len() + self.0.interners.const_stability.len() )?; writeln!( fmt, @@ -2072,6 +2062,8 @@ direct_interners! { const_allocation: intern_const_alloc(Allocation), layout: intern_layout(Layout), adt_def: intern_adt_def(AdtDef), + stability: intern_stability(attr::Stability), + const_stability: intern_const_stability(attr::ConstStability), } macro_rules! slice_interners { From 888332fee42bfccd2a1d1c3d249431c0b741d8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 21 Jan 2022 00:00:00 +0000 Subject: [PATCH 08/20] Reject unsupported naked functions Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 #79653. Change into an error fixes a soundness issue described in #32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 #87652. --- compiler/rustc_error_codes/src/error_codes.rs | 1 + .../src/error_codes/E0787.md | 28 +++ compiler/rustc_lint/src/lib.rs | 5 + compiler/rustc_lint_defs/src/builtin.rs | 47 ----- compiler/rustc_passes/src/naked_functions.rs | 91 ++++----- src/test/codegen/naked-functions.rs | 40 ++-- src/test/codegen/naked-noinline.rs | 1 - src/test/ui/asm/naked-functions.rs | 63 +++---- src/test/ui/asm/naked-functions.stderr | 177 ++++++------------ 9 files changed, 170 insertions(+), 283 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0787.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 79d9c55b5470b..d4b12d00f1ff6 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -486,6 +486,7 @@ E0783: include_str!("./error_codes/E0783.md"), E0784: include_str!("./error_codes/E0784.md"), E0785: include_str!("./error_codes/E0785.md"), E0786: include_str!("./error_codes/E0786.md"), +E0787: include_str!("./error_codes/E0787.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/compiler/rustc_error_codes/src/error_codes/E0787.md b/compiler/rustc_error_codes/src/error_codes/E0787.md new file mode 100644 index 0000000000000..cee5082927026 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0787.md @@ -0,0 +1,28 @@ +An unsupported naked function definition. + +Erroneous code example: + +```compile_fail,E0787 +#![feature(naked_functions)] + +#[naked] +pub extern "C" fn f() -> u32 { + 42 +} +``` + +The naked functions must be defined using a single inline assembly +block. + +The execution must never fall through past the end of the assembly +code so the block must use `noreturn` option. The asm block can also +use `att_syntax` and `raw` options, but others options are not allowed. + +The asm block must not contain any operands other than `const` and +`sym`. + +### Additional information + +For more information, please see [RFC 2972]. + +[RFC 2972]: https://github.com/rust-lang/rfcs/blob/master/text/2972-constrained-naked.md diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 4aa8505c9408d..dde47c1e4c43b 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -481,6 +481,11 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { for more information", ); store.register_removed("plugin_as_library", "plugins have been deprecated and retired"); + store.register_removed( + "unsupported_naked_functions", + "converted into hard error, see RFC 2972 \ + for more information", + ); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index c2f6118227a4a..4096815c6a426 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -2759,52 +2759,6 @@ declare_lint! { "undefined naked function ABI" } -declare_lint! { - /// The `unsupported_naked_functions` lint detects naked function - /// definitions that are unsupported but were previously accepted. - /// - /// ### Example - /// - /// ```rust - /// #![feature(naked_functions)] - /// - /// #[naked] - /// pub extern "C" fn f() -> u32 { - /// 42 - /// } - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// The naked functions must be defined using a single inline assembly - /// block. - /// - /// The execution must never fall through past the end of the assembly - /// code so the block must use `noreturn` option. The asm block can also - /// use `att_syntax` option, but other options are not allowed. - /// - /// The asm block must not contain any operands other than `const` and - /// `sym`. Additionally, naked function should specify a non-Rust ABI. - /// - /// Naked functions cannot be inlined. All forms of the `inline` attribute - /// are prohibited. - /// - /// While other definitions of naked functions were previously accepted, - /// they are unsupported and might not work reliably. This is a - /// [future-incompatible] lint that will transition into hard error in - /// the future. - /// - /// [future-incompatible]: ../index.md#future-incompatible-lints - pub UNSUPPORTED_NAKED_FUNCTIONS, - Warn, - "unsupported naked function definitions", - @future_incompatible = FutureIncompatibleInfo { - reference: "issue #32408 ", - }; -} - declare_lint! { /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used. /// @@ -3070,7 +3024,6 @@ declare_lint_pass! { UNINHABITED_STATIC, FUNCTION_ITEM_REFERENCES, USELESS_DEPRECATED, - UNSUPPORTED_NAKED_FUNCTIONS, MISSING_ABI, INVALID_DOC_ATTRIBUTES, SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index 0228196d1a1a1..e4feb8f136c6f 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -1,6 +1,7 @@ //! Checks validity of naked functions. use rustc_ast::{Attribute, InlineAsmOptions}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{FnKind, Visitor}; @@ -8,7 +9,6 @@ use rustc_hir::{ExprKind, HirId, InlineAsmOperand, StmtKind}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI; -use rustc_session::lint::builtin::UNSUPPORTED_NAKED_FUNCTIONS; use rustc_span::symbol::sym; use rustc_span::Span; use rustc_target::spec::abi::Abi; @@ -64,18 +64,16 @@ impl<'tcx> Visitor<'tcx> for CheckNakedFunctions<'tcx> { check_abi(self.tcx, hir_id, fn_header.abi, ident_span); check_no_patterns(self.tcx, body.params); check_no_parameters_use(self.tcx, body); - check_asm(self.tcx, hir_id, body, span); - check_inline(self.tcx, hir_id, attrs); + check_asm(self.tcx, body, span); + check_inline(self.tcx, attrs); } } } /// Check that the function isn't inlined. -fn check_inline(tcx: TyCtxt<'_>, hir_id: HirId, attrs: &[Attribute]) { +fn check_inline(tcx: TyCtxt<'_>, attrs: &[Attribute]) { for attr in attrs.iter().filter(|attr| attr.has_name(sym::inline)) { - tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, attr.span, |lint| { - lint.build("naked functions cannot be inlined").emit(); - }); + tcx.sess.struct_span_err(attr.span, "naked functions cannot be inlined").emit(); } } @@ -146,31 +144,31 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> { } /// Checks that function body contains a single inline assembly block. -fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, hir_id: HirId, body: &'tcx hir::Body<'tcx>, fn_span: Span) { +fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>, fn_span: Span) { let mut this = CheckInlineAssembly { tcx, items: Vec::new() }; this.visit_body(body); if let [(ItemKind::Asm, _)] = this.items[..] { // Ok. } else { - tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, fn_span, |lint| { - let mut diag = lint.build("naked functions must contain a single asm block"); - let mut has_asm = false; - for &(kind, span) in &this.items { - match kind { - ItemKind::Asm if has_asm => { - diag.span_label( - span, - "multiple asm blocks are unsupported in naked functions", - ); - } - ItemKind::Asm => has_asm = true, - ItemKind::NonAsm => { - diag.span_label(span, "non-asm is unsupported in naked functions"); - } + let mut diag = struct_span_err!( + tcx.sess, + fn_span, + E0787, + "naked functions must contain a single asm block" + ); + let mut has_asm = false; + for &(kind, span) in &this.items { + match kind { + ItemKind::Asm if has_asm => { + diag.span_label(span, "multiple asm blocks are unsupported in naked functions"); + } + ItemKind::Asm => has_asm = true, + ItemKind::NonAsm => { + diag.span_label(span, "non-asm is unsupported in naked functions"); } } - diag.emit(); - }); + } + diag.emit(); } } @@ -221,7 +219,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { ExprKind::InlineAsm(ref asm) => { self.items.push((ItemKind::Asm, span)); - self.check_inline_asm(expr.hir_id, asm, span); + self.check_inline_asm(asm, span); } ExprKind::DropTemps(..) | ExprKind::Block(..) | ExprKind::Err => { @@ -230,7 +228,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { } } - fn check_inline_asm(&self, hir_id: HirId, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) { + fn check_inline_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) { let unsupported_operands: Vec = asm .operands .iter() @@ -243,15 +241,13 @@ impl<'tcx> CheckInlineAssembly<'tcx> { }) .collect(); if !unsupported_operands.is_empty() { - self.tcx.struct_span_lint_hir( - UNSUPPORTED_NAKED_FUNCTIONS, - hir_id, + struct_span_err!( + self.tcx.sess, unsupported_operands, - |lint| { - lint.build("only `const` and `sym` operands are supported in naked functions") - .emit(); - }, - ); + E0787, + "only `const` and `sym` operands are supported in naked functions", + ) + .emit(); } let unsupported_options: Vec<&'static str> = [ @@ -266,19 +262,24 @@ impl<'tcx> CheckInlineAssembly<'tcx> { .collect(); if !unsupported_options.is_empty() { - self.tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, span, |lint| { - lint.build(&format!( - "asm options unsupported in naked functions: {}", - unsupported_options.join(", ") - )) - .emit(); - }); + struct_span_err!( + self.tcx.sess, + span, + E0787, + "asm options unsupported in naked functions: {}", + unsupported_options.join(", ") + ) + .emit(); } if !asm.options.contains(InlineAsmOptions::NORETURN) { - self.tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, span, |lint| { - lint.build("asm in naked functions must use `noreturn` option").emit(); - }); + struct_span_err!( + self.tcx.sess, + span, + E0787, + "asm in naked functions must use `noreturn` option" + ) + .emit(); } } } diff --git a/src/test/codegen/naked-functions.rs b/src/test/codegen/naked-functions.rs index c8cd69232821e..51c7a0c615d00 100644 --- a/src/test/codegen/naked-functions.rs +++ b/src/test/codegen/naked-functions.rs @@ -1,42 +1,32 @@ // compile-flags: -C no-prepopulate-passes +// needs-asm-support +// only-x86_64 #![crate_type = "lib"] #![feature(naked_functions)] +use std::arch::asm; // CHECK: Function Attrs: naked // CHECK-NEXT: define{{.*}}void @naked_empty() #[no_mangle] #[naked] -pub fn naked_empty() { +pub unsafe extern "C" fn naked_empty() { // CHECK-NEXT: {{.+}}: - // CHECK-NEXT: ret void + // CHECK-NEXT: call void asm + // CHECK-NEXT: unreachable + asm!("ret", + options(noreturn)); } // CHECK: Function Attrs: naked +// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %a, i64 %b) #[no_mangle] #[naked] -// CHECK-NEXT: define{{.*}}void @naked_with_args(i{{[0-9]+( %a)?}}) -pub fn naked_with_args(a: isize) { +pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize { // CHECK-NEXT: {{.+}}: - // CHECK: ret void -} - -// CHECK: Function Attrs: naked -// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_return() -#[no_mangle] -#[naked] -pub fn naked_with_return() -> isize { - // CHECK-NEXT: {{.+}}: - // CHECK-NEXT: ret i{{[0-9]+}} 0 - 0 -} - -// CHECK: Function Attrs: naked -// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+( %a)?}}) -#[no_mangle] -#[naked] -pub fn naked_with_args_and_return(a: isize) -> isize { - // CHECK-NEXT: {{.+}}: - // CHECK: ret i{{[0-9]+}} 0 - 0 + // CHECK-NEXT: call void asm + // CHECK-NEXT: unreachable + asm!("lea rax, [rdi + rsi]", + "ret", + options(noreturn)); } diff --git a/src/test/codegen/naked-noinline.rs b/src/test/codegen/naked-noinline.rs index e34ccf5c5fe99..13bc139ecd05a 100644 --- a/src/test/codegen/naked-noinline.rs +++ b/src/test/codegen/naked-noinline.rs @@ -7,7 +7,6 @@ use std::arch::asm; -#[inline(always)] #[naked] #[no_mangle] pub unsafe extern "C" fn f() { diff --git a/src/test/ui/asm/naked-functions.rs b/src/test/ui/asm/naked-functions.rs index 32431d9e7c6fe..26397a65cf99a 100644 --- a/src/test/ui/asm/naked-functions.rs +++ b/src/test/ui/asm/naked-functions.rs @@ -32,8 +32,7 @@ pub unsafe extern "C" fn patterns( #[naked] pub unsafe extern "C" fn inc(a: u32) -> u32 { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block a + 1 //~^ ERROR referencing function parameters is not allowed in naked functions } @@ -42,21 +41,18 @@ pub unsafe extern "C" fn inc(a: u32) -> u32 { pub unsafe extern "C" fn inc_asm(a: u32) -> u32 { asm!("/* {0} */", in(reg) a, options(noreturn)); //~^ ERROR referencing function parameters is not allowed in naked functions - //~| WARN only `const` and `sym` operands are supported in naked functions - //~| WARN this was previously accepted + //~| ERROR only `const` and `sym` operands are supported in naked functions } #[naked] pub unsafe extern "C" fn inc_closure(a: u32) -> u32 { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block (|| a + 1)() } #[naked] pub unsafe extern "C" fn unsupported_operands() { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block let mut a = 0usize; let mut b = 0usize; let mut c = 0usize; @@ -65,11 +61,9 @@ pub unsafe extern "C" fn unsupported_operands() { const F: usize = 0usize; static G: usize = 0usize; asm!("/* {0} {1} {2} {3} {4} {5} {6} */", - //~^ WARN asm in naked functions must use `noreturn` option - //~| WARN this was previously accepted + //~^ ERROR asm in naked functions must use `noreturn` option in(reg) a, - //~^ WARN only `const` and `sym` operands are supported in naked functions - //~| WARN this was previously accepted + //~^ ERROR only `const` and `sym` operands are supported in naked functions inlateout(reg) b, inout(reg) c, lateout(reg) d, @@ -81,31 +75,25 @@ pub unsafe extern "C" fn unsupported_operands() { #[naked] pub extern "C" fn missing_assembly() { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block } #[naked] pub extern "C" fn too_many_asm_blocks() { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block asm!(""); - //~^ WARN asm in naked functions must use `noreturn` option - //~| WARN this was previously accepted + //~^ ERROR asm in naked functions must use `noreturn` option asm!(""); - //~^ WARN asm in naked functions must use `noreturn` option - //~| WARN this was previously accepted + //~^ ERROR asm in naked functions must use `noreturn` option asm!(""); - //~^ WARN asm in naked functions must use `noreturn` option - //~| WARN this was previously accepted + //~^ ERROR asm in naked functions must use `noreturn` option asm!("", options(noreturn)); } pub fn outer(x: u32) -> extern "C" fn(usize) -> usize { #[naked] pub extern "C" fn inner(y: usize) -> usize { - //~^ WARN naked functions must contain a single asm block - //~| WARN this was previously accepted + //~^ ERROR naked functions must contain a single asm block *&y //~^ ERROR referencing function parameters is not allowed in naked functions } @@ -115,18 +103,15 @@ pub fn outer(x: u32) -> extern "C" fn(usize) -> usize { #[naked] unsafe extern "C" fn invalid_options() { asm!("", options(nomem, preserves_flags, noreturn)); - //~^ WARN asm options unsupported in naked functions: `nomem`, `preserves_flags` - //~| WARN this was previously accepted + //~^ ERROR asm options unsupported in naked functions: `nomem`, `preserves_flags` } #[naked] unsafe extern "C" fn invalid_options_continued() { asm!("", options(readonly, nostack), options(pure)); //~^ ERROR asm with the `pure` option must have at least one output - //~| WARN asm options unsupported in naked functions: `nostack`, `pure`, `readonly` - //~| WARN this was previously accepted - //~| WARN asm in naked functions must use `noreturn` option - //~| WARN this was previously accepted + //~| ERROR asm options unsupported in naked functions: `nostack`, `pure`, `readonly` + //~| ERROR asm in naked functions must use `noreturn` option } #[naked] @@ -177,38 +162,32 @@ pub unsafe extern "C" fn inline_none() { #[naked] #[inline] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined pub unsafe extern "C" fn inline_hint() { asm!("", options(noreturn)); } #[naked] #[inline(always)] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined pub unsafe extern "C" fn inline_always() { asm!("", options(noreturn)); } #[naked] #[inline(never)] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined pub unsafe extern "C" fn inline_never() { asm!("", options(noreturn)); } #[naked] #[inline] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined #[inline(always)] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined #[inline(never)] -//~^ WARN naked functions cannot be inlined -//~| WARN this was previously accepted +//~^ ERROR naked functions cannot be inlined pub unsafe extern "C" fn inline_all() { asm!("", options(noreturn)); } diff --git a/src/test/ui/asm/naked-functions.stderr b/src/test/ui/asm/naked-functions.stderr index c2dfe443d6038..153858fd982e1 100644 --- a/src/test/ui/asm/naked-functions.stderr +++ b/src/test/ui/asm/naked-functions.stderr @@ -1,5 +1,5 @@ error: asm with the `pure` option must have at least one output - --> $DIR/naked-functions.rs:124:14 + --> $DIR/naked-functions.rs:111:14 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ @@ -29,66 +29,54 @@ LL | P { x, y }: P, | ^^^^^^^^^^ error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:37:5 + --> $DIR/naked-functions.rs:36:5 | LL | a + 1 | ^ | = help: follow the calling convention in asm block to use parameters -warning: naked functions must contain a single asm block +error[E0787]: naked functions must contain a single asm block --> $DIR/naked-functions.rs:34:1 | LL | / pub unsafe extern "C" fn inc(a: u32) -> u32 { LL | | -LL | | LL | | a + 1 | | ----- non-asm is unsupported in naked functions LL | | LL | | } | |_^ - | - = note: `#[warn(unsupported_naked_functions)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:43:31 + --> $DIR/naked-functions.rs:42:31 | LL | asm!("/* {0} */", in(reg) a, options(noreturn)); | ^ | = help: follow the calling convention in asm block to use parameters -warning: only `const` and `sym` operands are supported in naked functions - --> $DIR/naked-functions.rs:43:23 +error[E0787]: only `const` and `sym` operands are supported in naked functions + --> $DIR/naked-functions.rs:42:23 | LL | asm!("/* {0} */", in(reg) a, options(noreturn)); | ^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:50:1 +error[E0787]: naked functions must contain a single asm block + --> $DIR/naked-functions.rs:48:1 | LL | / pub unsafe extern "C" fn inc_closure(a: u32) -> u32 { LL | | -LL | | LL | | (|| a + 1)() | | ------------ non-asm is unsupported in naked functions LL | | } | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: only `const` and `sym` operands are supported in naked functions - --> $DIR/naked-functions.rs:70:10 +error[E0787]: only `const` and `sym` operands are supported in naked functions + --> $DIR/naked-functions.rs:65:10 | LL | in(reg) a, | ^^^^^^^^^ -... +LL | LL | inlateout(reg) b, | ^^^^^^^^^^^^^^^^ LL | inout(reg) c, @@ -97,31 +85,24 @@ LL | lateout(reg) d, | ^^^^^^^^^^^^^^ LL | out(reg) e, | ^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:67:5 +error[E0787]: asm in naked functions must use `noreturn` option + --> $DIR/naked-functions.rs:63:5 | LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */", LL | | -LL | | LL | | in(reg) a, +LL | | ... | LL | | sym G, LL | | ); | |_____^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:57:1 +error[E0787]: naked functions must contain a single asm block + --> $DIR/naked-functions.rs:54:1 | LL | / pub unsafe extern "C" fn unsupported_operands() { LL | | -LL | | LL | | let mut a = 0usize; | | ------------------- non-asm is unsupported in naked functions LL | | let mut b = 0usize; @@ -136,123 +117,90 @@ LL | | let mut e = 0usize; LL | | ); LL | | } | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:83:1 +error[E0787]: naked functions must contain a single asm block + --> $DIR/naked-functions.rs:77:1 | LL | / pub extern "C" fn missing_assembly() { LL | | -LL | | LL | | } | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:92:5 +error[E0787]: asm in naked functions must use `noreturn` option + --> $DIR/naked-functions.rs:84:5 | LL | asm!(""); | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:95:5 +error[E0787]: asm in naked functions must use `noreturn` option + --> $DIR/naked-functions.rs:86:5 | LL | asm!(""); | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:98:5 +error[E0787]: asm in naked functions must use `noreturn` option + --> $DIR/naked-functions.rs:88:5 | LL | asm!(""); | ^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:89:1 +error[E0787]: naked functions must contain a single asm block + --> $DIR/naked-functions.rs:82:1 | LL | / pub extern "C" fn too_many_asm_blocks() { LL | | -LL | | LL | | asm!(""); -... | +LL | | LL | | asm!(""); | | -------- multiple asm blocks are unsupported in naked functions -... | +LL | | LL | | asm!(""); | | -------- multiple asm blocks are unsupported in naked functions -... | +LL | | LL | | asm!("", options(noreturn)); | | --------------------------- multiple asm blocks are unsupported in naked functions LL | | } | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 error: referencing function parameters is not allowed in naked functions - --> $DIR/naked-functions.rs:109:11 + --> $DIR/naked-functions.rs:97:11 | LL | *&y | ^ | = help: follow the calling convention in asm block to use parameters -warning: naked functions must contain a single asm block - --> $DIR/naked-functions.rs:106:5 +error[E0787]: naked functions must contain a single asm block + --> $DIR/naked-functions.rs:95:5 | LL | / pub extern "C" fn inner(y: usize) -> usize { LL | | -LL | | LL | | *&y | | --- non-asm is unsupported in naked functions LL | | LL | | } | |_____^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm options unsupported in naked functions: `nomem`, `preserves_flags` - --> $DIR/naked-functions.rs:117:5 +error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_flags` + --> $DIR/naked-functions.rs:105:5 | LL | asm!("", options(nomem, preserves_flags, noreturn)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm options unsupported in naked functions: `nostack`, `pure`, `readonly` - --> $DIR/naked-functions.rs:124:5 +error[E0787]: asm options unsupported in naked functions: `nostack`, `pure`, `readonly` + --> $DIR/naked-functions.rs:111:5 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: asm in naked functions must use `noreturn` option - --> $DIR/naked-functions.rs:124:5 +error[E0787]: asm in naked functions must use `noreturn` option + --> $DIR/naked-functions.rs:111:5 | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:133:15 + --> $DIR/naked-functions.rs:118:15 | LL | pub unsafe fn default_abi() { | ^^^^^^^^^^^ @@ -260,64 +208,47 @@ LL | pub unsafe fn default_abi() { = note: `#[warn(undefined_naked_function_abi)]` on by default warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:139:15 + --> $DIR/naked-functions.rs:124:15 | LL | pub unsafe fn rust_abi() { | ^^^^^^^^ -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:179:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:164:1 | LL | #[inline] | ^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:187:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:171:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:195:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:178:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:203:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:185:1 | LL | #[inline] | ^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:206:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:187:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -warning: naked functions cannot be inlined - --> $DIR/naked-functions.rs:209:1 +error: naked functions cannot be inlined + --> $DIR/naked-functions.rs:189:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #32408 -error: aborting due to 8 previous errors; 23 warnings emitted +error: aborting due to 29 previous errors; 2 warnings emitted +For more information about this error, try `rustc --explain E0787`. From beeba4bcea8151cb43b2e5e45d083700cec4a26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 21 Jan 2022 00:00:00 +0000 Subject: [PATCH 09/20] Reject may_unwind option in naked functions --- compiler/rustc_passes/src/naked_functions.rs | 1 + src/test/ui/asm/naked-functions.rs | 8 ++++++- src/test/ui/asm/naked-functions.stderr | 24 ++++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index e4feb8f136c6f..00a93ccc9aa09 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -251,6 +251,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { } let unsupported_options: Vec<&'static str> = [ + (InlineAsmOptions::MAY_UNWIND, "`may_unwind`"), (InlineAsmOptions::NOMEM, "`nomem`"), (InlineAsmOptions::NOSTACK, "`nostack`"), (InlineAsmOptions::PRESERVES_FLAGS, "`preserves_flags`"), diff --git a/src/test/ui/asm/naked-functions.rs b/src/test/ui/asm/naked-functions.rs index 26397a65cf99a..5b4293972ea21 100644 --- a/src/test/ui/asm/naked-functions.rs +++ b/src/test/ui/asm/naked-functions.rs @@ -5,7 +5,7 @@ #![feature(naked_functions)] #![feature(or_patterns)] -#![feature(asm_const, asm_sym)] +#![feature(asm_const, asm_sym, asm_unwind)] #![crate_type = "lib"] use std::arch::asm; @@ -114,6 +114,12 @@ unsafe extern "C" fn invalid_options_continued() { //~| ERROR asm in naked functions must use `noreturn` option } +#[naked] +unsafe extern "C" fn invalid_may_unwind() { + asm!("", options(noreturn, may_unwind)); + //~^ ERROR asm options unsupported in naked functions: `may_unwind` +} + #[naked] pub unsafe fn default_abi() { //~^ WARN Rust ABI is unsupported in naked functions diff --git a/src/test/ui/asm/naked-functions.stderr b/src/test/ui/asm/naked-functions.stderr index 153858fd982e1..c1dcc433db6c6 100644 --- a/src/test/ui/asm/naked-functions.stderr +++ b/src/test/ui/asm/naked-functions.stderr @@ -199,8 +199,14 @@ error[E0787]: asm in naked functions must use `noreturn` option LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error[E0787]: asm options unsupported in naked functions: `may_unwind` + --> $DIR/naked-functions.rs:119:5 + | +LL | asm!("", options(noreturn, may_unwind)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:118:15 + --> $DIR/naked-functions.rs:124:15 | LL | pub unsafe fn default_abi() { | ^^^^^^^^^^^ @@ -208,47 +214,47 @@ LL | pub unsafe fn default_abi() { = note: `#[warn(undefined_naked_function_abi)]` on by default warning: Rust ABI is unsupported in naked functions - --> $DIR/naked-functions.rs:124:15 + --> $DIR/naked-functions.rs:130:15 | LL | pub unsafe fn rust_abi() { | ^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:164:1 + --> $DIR/naked-functions.rs:170:1 | LL | #[inline] | ^^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:171:1 + --> $DIR/naked-functions.rs:177:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:178:1 + --> $DIR/naked-functions.rs:184:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:185:1 + --> $DIR/naked-functions.rs:191:1 | LL | #[inline] | ^^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:187:1 + --> $DIR/naked-functions.rs:193:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ error: naked functions cannot be inlined - --> $DIR/naked-functions.rs:189:1 + --> $DIR/naked-functions.rs:195:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ -error: aborting due to 29 previous errors; 2 warnings emitted +error: aborting due to 30 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0787`. From d46ed5d3333770ac490d587878d708c3be17f137 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 21 Jan 2022 13:25:26 +1100 Subject: [PATCH 10/20] Clarify some code relating to interning and types. I have found this code very confusing at times. This commit clarifies things. In particular, the commit explains the requirements that the `Borrow` impls put on the `Eq` and `Hash` impls, which are non-obvious. And it puts the `Borrow` impls first, since they force `Eq` and `Hash` to have particular forms. The commit also notes `TyS`'s uniqueness requirements. --- compiler/rustc_middle/src/ty/context.rs | 64 +++++++++++++++---------- compiler/rustc_middle/src/ty/mod.rs | 17 +++++++ 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index de435b8f58c72..7b7c5fa2436ae 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1946,7 +1946,10 @@ impl<'tcx> TyCtxt<'tcx> { } } -/// An entry in an interner. +// This type holds a `T` in the interner. The `T` is stored in the arena and +// this type just holds a pointer to it, but it still effectively owns it. It +// impls `Borrow` so that it can be looked up using the original +// (non-arena-memory-owning) types. struct Interned<'tcx, T: ?Sized>(&'tcx T); impl<'tcx, T: 'tcx + ?Sized> Clone for Interned<'tcx, T> { @@ -1954,6 +1957,7 @@ impl<'tcx, T: 'tcx + ?Sized> Clone for Interned<'tcx, T> { Interned(self.0) } } + impl<'tcx, T: 'tcx + ?Sized> Copy for Interned<'tcx, T> {} impl<'tcx, T: 'tcx + ?Sized> IntoPointer for Interned<'tcx, T> { @@ -1961,9 +1965,18 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for Interned<'tcx, T> { self.0 as *const _ as *const () } } -// N.B., an `Interned` compares and hashes as a `TyKind`. + +#[allow(rustc::usage_of_ty_tykind)] +impl<'tcx> Borrow> for Interned<'tcx, TyS<'tcx>> { + fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> { + &self.0.kind() + } +} + impl<'tcx> PartialEq for Interned<'tcx, TyS<'tcx>> { fn eq(&self, other: &Interned<'tcx, TyS<'tcx>>) -> bool { + // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals + // `x == y`. self.0.kind() == other.0.kind() } } @@ -1972,19 +1985,21 @@ impl<'tcx> Eq for Interned<'tcx, TyS<'tcx>> {} impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> { fn hash(&self, s: &mut H) { + // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`. self.0.kind().hash(s) } } -#[allow(rustc::usage_of_ty_tykind)] -impl<'tcx> Borrow> for Interned<'tcx, TyS<'tcx>> { - fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> { - &self.0.kind() +impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { + fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> { + &self.0.kind } } -// N.B., an `Interned` compares and hashes as a `PredicateKind`. + impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> { fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool { + // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals + // `x == y`. self.0.kind == other.0.kind } } @@ -1993,19 +2008,21 @@ impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {} impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> { fn hash(&self, s: &mut H) { + // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`. self.0.kind.hash(s) } } -impl<'tcx> Borrow>> for Interned<'tcx, PredicateInner<'tcx>> { - fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> { - &self.0.kind +impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List> { + fn borrow<'a>(&'a self) -> &'a [T] { + &self.0[..] } } -// N.B., an `Interned>` compares and hashes as its elements. impl<'tcx, T: PartialEq> PartialEq for Interned<'tcx, List> { fn eq(&self, other: &Interned<'tcx, List>) -> bool { + // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals + // `x == y`. self.0[..] == other.0[..] } } @@ -2014,20 +2031,23 @@ impl<'tcx, T: Eq> Eq for Interned<'tcx, List> {} impl<'tcx, T: Hash> Hash for Interned<'tcx, List> { fn hash(&self, s: &mut H) { + // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`. self.0[..].hash(s) } } -impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List> { - fn borrow<'a>(&'a self) -> &'a [T] { - &self.0[..] - } -} - macro_rules! direct_interners { ($($name:ident: $method:ident($ty:ty),)+) => { - $(impl<'tcx> PartialEq for Interned<'tcx, $ty> { + $(impl<'tcx> Borrow<$ty> for Interned<'tcx, $ty> { + fn borrow<'a>(&'a self) -> &'a $ty { + &self.0 + } + } + + impl<'tcx> PartialEq for Interned<'tcx, $ty> { fn eq(&self, other: &Self) -> bool { + // The `Borrow` trait requires that `x.borrow() == y.borrow()` + // equals `x == y`. self.0 == other.0 } } @@ -2036,16 +2056,12 @@ macro_rules! direct_interners { impl<'tcx> Hash for Interned<'tcx, $ty> { fn hash(&self, s: &mut H) { + // The `Borrow` trait requires that `x.borrow().hash(s) == + // x.hash(s)`. self.0.hash(s) } } - impl<'tcx> Borrow<$ty> for Interned<'tcx, $ty> { - fn borrow<'a>(&'a self) -> &'a $ty { - &self.0 - } - } - impl<'tcx> TyCtxt<'tcx> { pub fn $method(self, v: $ty) -> &'tcx $ty { self.interners.$name.intern(v, |v| { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index d6e89e52b95ed..00af16e79842c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -376,15 +376,28 @@ pub struct CReaderCacheKey { pub pos: usize, } +/// Represents a type. +/// +/// IMPORTANT: Every `TyS` is *required* to have unique contents. The type's +/// correctness relies on this, *but it does not enforce it*. Therefore, any +/// code that creates a `TyS` must ensure uniqueness itself. In practice this +/// is achieved by interning. #[allow(rustc::usage_of_ty_tykind)] pub struct TyS<'tcx> { /// This field shouldn't be used directly and may be removed in the future. /// Use `TyS::kind()` instead. kind: TyKind<'tcx>, + + /// This field provides fast access to information that is also contained + /// in `kind`. + /// /// This field shouldn't be used directly and may be removed in the future. /// Use `TyS::flags()` instead. flags: TypeFlags, + /// This field provides fast access to information that is also contained + /// in `kind`. + /// /// This is a kind of confusing thing: it stores the smallest /// binder such that /// @@ -436,6 +449,8 @@ impl<'tcx> PartialOrd for TyS<'tcx> { impl<'tcx> PartialEq for TyS<'tcx> { #[inline] fn eq(&self, other: &TyS<'tcx>) -> bool { + // Pointer equality implies equality (due to the unique contents + // assumption). ptr::eq(self, other) } } @@ -443,6 +458,8 @@ impl<'tcx> Eq for TyS<'tcx> {} impl<'tcx> Hash for TyS<'tcx> { fn hash(&self, s: &mut H) { + // Pointer hashing is sufficient (due to the unique contents + // assumption). (self as *const TyS<'_>).hash(s) } } From d98428711e6fe1b2a7f6d963d4b337beaa3dc285 Mon Sep 17 00:00:00 2001 From: Sebastian Humenda Date: Tue, 3 Apr 2018 14:53:13 +0200 Subject: [PATCH 11/20] Add L4Bender as linker variant --- compiler/rustc_codegen_ssa/src/back/link.rs | 1 + compiler/rustc_codegen_ssa/src/back/linker.rs | 172 +++++++++++++++++- compiler/rustc_target/src/spec/l4re_base.rs | 21 +-- compiler/rustc_target/src/spec/mod.rs | 2 + .../src/spec/x86_64_unknown_l4re_uclibc.rs | 4 + 5 files changed, 183 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index acf65259f61cf..ec9fc22bc4d05 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1159,6 +1159,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { LinkerFlavor::Lld(_) => "lld", LinkerFlavor::PtxLinker => "rust-ptx-linker", LinkerFlavor::BpfLinker => "bpf-linker", + LinkerFlavor::L4Bender => "l4-bender", }), flavor, )), diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 15d16e7d3d61a..e2357eae7c1c0 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -3,6 +3,7 @@ use super::command::Command; use super::symbol_export; use rustc_span::symbol::sym; +use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io::prelude::*; @@ -126,7 +127,6 @@ pub fn get_linker<'a>( // FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction // to the linker args construction. assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp"); - match flavor { LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => { Box::new(MsvcLinker { cmd, sess }) as Box @@ -149,6 +149,10 @@ pub fn get_linker<'a>( LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box, LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess }) as Box, + + LinkerFlavor::L4Bender => { + Box::new(L4Bender::new(cmd, sess)) as Box + }, } } @@ -1355,6 +1359,172 @@ impl<'a> Linker for WasmLd<'a> { } } +/// Linker shepherd script for L4Re (Fiasco) +pub struct L4Bender<'a> { + cmd: Command, + sess: &'a Session, + hinted_static: bool, +} + +impl<'a> Linker for L4Bender<'a> { + fn link_dylib(&mut self, _lib: Symbol) { + panic!("dylibs not supported yet") + } + fn link_staticlib(&mut self, lib: Symbol) { + self.hint_static(); + self.cmd.arg(format!("-PC{}", lib)); + } + fn link_rlib(&mut self, lib: &Path) { + self.hint_static(); + self.cmd.arg(lib); + } + fn include_path(&mut self, path: &Path) { + self.cmd.arg("-L").arg(path); + } + fn framework_path(&mut self, _: &Path) { + bug!("Frameworks are not supported on L4Re!"); + } + fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); } + fn add_object(&mut self, path: &Path) { self.cmd.arg(path); } + // not sure about pie on L4Re + fn position_independent_executable(&mut self) { } + fn no_position_independent_executable(&mut self) { } + fn full_relro(&mut self) { self.cmd.arg("-z,relro,-z,now"); } + fn partial_relro(&mut self) { self.cmd.arg("-z,relro"); } + fn no_relro(&mut self) { self.cmd.arg("-z,norelro"); } + fn build_static_executable(&mut self) { self.cmd.arg("-static"); } + fn cmd(&mut self) -> &mut Command { + &mut self.cmd + } + + fn link_rust_dylib(&mut self, _: Symbol, _: &Path) { + panic!("Rust dylibs not supported"); + } + + fn link_framework(&mut self, _: Symbol) { + bug!("Frameworks not supported on L4Re."); + } + + // Here we explicitly ask that the entire archive is included into the + // result artifact. For more details see #15460, but the gist is that + // the linker will strip away any unused objects in the archive if we + // don't otherwise explicitly reference them. This can occur for + // libraries which are just providing bindings, libraries with generic + // functions, etc. + fn link_whole_staticlib(&mut self, lib: Symbol, _: &[PathBuf]) { + self.hint_static(); + self.cmd.arg("--whole-archive").arg(format!("-l{}", lib)); + self.cmd.arg("--no-whole-archive"); + } + + fn link_whole_rlib(&mut self, lib: &Path) { + self.hint_static(); + self.cmd.arg("--whole-archive").arg(lib).arg("--no-whole-archive"); + } + + fn gc_sections(&mut self, keep_metadata: bool) { + if !keep_metadata { + self.cmd.arg("--gc-sections"); + } + } + + fn optimize(&mut self) { + self.cmd.arg("-O2"); + } + + fn pgo_gen(&mut self) { } + + fn debuginfo(&mut self, strip: Strip) { + match strip { + Strip::None => {} + Strip::Debuginfo => { + self.cmd().arg("--strip-debug"); } + Strip::Symbols => { + self.cmd().arg("--strip-all"); + } + } + } + + fn no_default_libraries(&mut self) { + self.cmd.arg("-nostdlib"); + } + + fn build_dylib(&mut self, _: &Path) { + bug!("not implemented"); + } + + fn export_symbols(&mut self, _: &Path, _: CrateType) { + // ToDo, not implemented, copy from GCC + return; + } + + fn subsystem(&mut self, subsystem: &str) { + self.cmd.arg(&format!("--subsystem,{}", subsystem)); + } + + fn finalize(&mut self) { + self.hint_static(); // Reset to default before returning the composed command line. + } + + fn group_start(&mut self) { self.cmd.arg("--start-group"); } + fn group_end(&mut self) { self.cmd.arg("--end-group"); } + fn linker_plugin_lto(&mut self) { + // do nothing + } + fn control_flow_guard(&mut self) { + self.sess.warn("Windows Control Flow Guard is not supported by this linker."); + } + + fn no_crt_objects(&mut self) { } +} + +impl<'a> L4Bender<'a> { + pub fn new(mut cmd: Command, sess: &'a Session) -> L4Bender<'a> { + if let Ok(l4bender_args) = env::var("L4_BENDER_ARGS") { + L4Bender::split_cmd_args(&mut cmd, &l4bender_args); + } + + cmd.arg("--"); // separate direct l4-bender args from linker args + + L4Bender { + cmd: cmd, + sess: sess, + hinted_static: false, + } + } + + /// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to + /// completely understand shell, but should instead allow passing arguments like + /// `-Dlinker="ld -m x86_64"`, and a copy without quotes, but spaces preserved, is added as an + /// argument to the given Command. This means that constructs as \" are not understood, so + /// quote wisely. + fn split_cmd_args(cmd: &mut Command, shell_args: &str) { + let mut arg = String::new(); + let mut quoted = false; + for character in shell_args.chars() { + match character { + ' ' if !quoted => { + cmd.arg(&arg); + arg.clear(); + }, + '"' | '\'' => quoted = !quoted, + _ => arg.push(character), + }; + } + if arg.len() > 0 { + cmd.arg(&arg); + arg.clear(); + } + } + + fn hint_static(&mut self) { + if !self.hinted_static { + self.cmd.arg("-static"); + self.hinted_static = true; + } + } +} + pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec { if let Some(ref exports) = tcx.sess.target.override_export_symbols { return exports.clone(); diff --git a/compiler/rustc_target/src/spec/l4re_base.rs b/compiler/rustc_target/src/spec/l4re_base.rs index f6e3102f61762..235df91f41466 100644 --- a/compiler/rustc_target/src/spec/l4re_base.rs +++ b/compiler/rustc_target/src/spec/l4re_base.rs @@ -1,16 +1,5 @@ -use crate::spec::{LinkerFlavor, PanicStrategy, TargetOptions}; -//use std::process::Command; - -// Use GCC to locate code for crt* libraries from the host, not from L4Re. Note -// that a few files also come from L4Re, for these, the function shouldn't be -// used. This uses GCC for the location of the file, but GCC is required for L4Re anyway. -//fn get_path_or(filename: &str) -> String { -// let child = Command::new("gcc") -// .arg(format!("-print-file-name={}", filename)).output() -// .expect("Failed to execute GCC"); -// String::from_utf8(child.stdout) -// .expect("Couldn't read path from GCC").trim().into() -//} +use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions}; +use std::default::Default; pub fn opts() -> TargetOptions { TargetOptions { @@ -19,9 +8,9 @@ pub fn opts() -> TargetOptions { linker_flavor: LinkerFlavor::Ld, executables: true, panic_strategy: PanicStrategy::Abort, - linker: Some("ld".to_string()), - linker_is_gnu: false, - families: vec!["unix".to_string()], + linker: Some("l4-bender".to_string()), + pre_link_args: args, + os_family: Some("unix".to_string()), ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 2c149318730ee..4effb8bacf6d6 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -90,6 +90,7 @@ mod windows_uwp_msvc_base; pub enum LinkerFlavor { Em, Gcc, + L4Bender, Ld, Msvc, Lld(LldFlavor), @@ -160,6 +161,7 @@ macro_rules! flavor_mappings { flavor_mappings! { ((LinkerFlavor::Em), "em"), ((LinkerFlavor::Gcc), "gcc"), + ((LinkerFlavor::L4Bender), "l4-bender"), ((LinkerFlavor::Ld), "ld"), ((LinkerFlavor::Msvc), "msvc"), ((LinkerFlavor::PtxLinker), "ptx-linker"), diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs index 1fbd0bb4cec25..6457d7c3efaf1 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs @@ -11,6 +11,10 @@ pub fn target() -> Target { data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" .to_string(), arch: "x86_64".to_string(), + target_os: "l4re".to_string(), + target_env: "uclibc".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::L4Bender, options: base, } } From 24588e6b3af018aaff628b98cd56383595b2d226 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 21 Jan 2022 15:44:57 +0000 Subject: [PATCH 12/20] Old versions of Android generate SIGSEGV from libc::abort --- library/std/src/sys/unix/process/process_unix/tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/process/process_unix/tests.rs b/library/std/src/sys/unix/process/process_unix/tests.rs index 157debf2d257b..560c62155d931 100644 --- a/library/std/src/sys/unix/process/process_unix/tests.rs +++ b/library/std/src/sys/unix/process/process_unix/tests.rs @@ -53,5 +53,10 @@ fn test_command_fork_no_unwind() { let status = got.expect("panic unexpectedly propagated"); dbg!(status); let signal = status.signal().expect("expected child process to die of signal"); - assert!(signal == libc::SIGABRT || signal == libc::SIGILL || signal == libc::SIGTRAP); + assert!( + signal == libc::SIGABRT + || signal == libc::SIGILL + || signal == libc::SIGTRAP + || signal == libc::SIGSEGV + ); } From 660d993c642a2f88b84d5e1f0d8602b8136b9b4e Mon Sep 17 00:00:00 2001 From: Benjamin Lamowski Date: Mon, 31 May 2021 14:34:23 +0200 Subject: [PATCH 13/20] adapt L4Bender implementation - Fix style errors. - L4-bender does not yet support dynamic linking. - Stack unwinding is not yet supported for x86_64-unknown-l4re-uclibc. For now, just abort on panics. - Use GNU-style linker options where possible. As suggested by review: - Use standard GNU-style ld syntax for relro flags. - Use standard GNU-style optimization flags and logic. - Use standard GNU-style ld syntax for --subsystem. - Don't read environment variables in L4Bender linker. Thanks to CARGO_ENCODED_RUSTFLAGS introduced in #9601, l4-bender's arguments can now be passed from the L4Re build system without resorting to custom parsing of environment variables. --- compiler/rustc_codegen_ssa/src/back/linker.rs | 142 ++++++++---------- compiler/rustc_target/src/spec/l4re_base.rs | 8 +- .../src/spec/x86_64_unknown_l4re_uclibc.rs | 9 +- library/panic_unwind/src/lib.rs | 4 + 4 files changed, 74 insertions(+), 89 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index e2357eae7c1c0..3fb56f42b8cca 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -3,7 +3,6 @@ use super::command::Command; use super::symbol_export; use rustc_span::symbol::sym; -use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io::prelude::*; @@ -150,9 +149,7 @@ pub fn get_linker<'a>( LinkerFlavor::BpfLinker => Box::new(BpfLinker { cmd, sess }) as Box, - LinkerFlavor::L4Bender => { - Box::new(L4Bender::new(cmd, sess)) as Box - }, + LinkerFlavor::L4Bender => Box::new(L4Bender::new(cmd, sess)) as Box, } } @@ -1367,10 +1364,10 @@ pub struct L4Bender<'a> { } impl<'a> Linker for L4Bender<'a> { - fn link_dylib(&mut self, _lib: Symbol) { - panic!("dylibs not supported yet") + fn link_dylib(&mut self, _lib: Symbol, _verbatim: bool, _as_needed: bool) { + bug!("dylibs are not supported on L4Re"); } - fn link_staticlib(&mut self, lib: Symbol) { + fn link_staticlib(&mut self, lib: Symbol, _verbatim: bool) { self.hint_static(); self.cmd.arg(format!("-PC{}", lib)); } @@ -1382,36 +1379,44 @@ impl<'a> Linker for L4Bender<'a> { self.cmd.arg("-L").arg(path); } fn framework_path(&mut self, _: &Path) { - bug!("Frameworks are not supported on L4Re!"); - } - fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); } - fn add_object(&mut self, path: &Path) { self.cmd.arg(path); } - // not sure about pie on L4Re - fn position_independent_executable(&mut self) { } - fn no_position_independent_executable(&mut self) { } - fn full_relro(&mut self) { self.cmd.arg("-z,relro,-z,now"); } - fn partial_relro(&mut self) { self.cmd.arg("-z,relro"); } - fn no_relro(&mut self) { self.cmd.arg("-z,norelro"); } - fn build_static_executable(&mut self) { self.cmd.arg("-static"); } + bug!("frameworks are not supported on L4Re"); + } + fn output_filename(&mut self, path: &Path) { + self.cmd.arg("-o").arg(path); + } + + fn add_object(&mut self, path: &Path) { + self.cmd.arg(path); + } + + fn full_relro(&mut self) { + self.cmd.arg("-zrelro"); + self.cmd.arg("-znow"); + } + + fn partial_relro(&mut self) { + self.cmd.arg("-zrelro"); + } + + fn no_relro(&mut self) { + self.cmd.arg("-znorelro"); + } + fn cmd(&mut self) -> &mut Command { &mut self.cmd } + fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} + fn link_rust_dylib(&mut self, _: Symbol, _: &Path) { panic!("Rust dylibs not supported"); } - fn link_framework(&mut self, _: Symbol) { - bug!("Frameworks not supported on L4Re."); + fn link_framework(&mut self, _framework: Symbol, _as_needed: bool) { + bug!("frameworks not supported on L4Re"); } - // Here we explicitly ask that the entire archive is included into the - // result artifact. For more details see #15460, but the gist is that - // the linker will strip away any unused objects in the archive if we - // don't otherwise explicitly reference them. This can occur for - // libraries which are just providing bindings, libraries with generic - // functions, etc. - fn link_whole_staticlib(&mut self, lib: Symbol, _: &[PathBuf]) { + fn link_whole_staticlib(&mut self, lib: Symbol, _verbatim: bool, _search_path: &[PathBuf]) { self.hint_static(); self.cmd.arg("--whole-archive").arg(format!("-l{}", lib)); self.cmd.arg("--no-whole-archive"); @@ -1428,17 +1433,28 @@ impl<'a> Linker for L4Bender<'a> { } } + fn no_gc_sections(&mut self) { + self.cmd.arg("--no-gc-sections"); + } + fn optimize(&mut self) { - self.cmd.arg("-O2"); + // GNU-style linkers support optimization with -O. GNU ld doesn't + // need a numeric argument, but other linkers do. + if self.sess.opts.optimize == config::OptLevel::Default + || self.sess.opts.optimize == config::OptLevel::Aggressive + { + self.cmd.arg("-O1"); + } } - fn pgo_gen(&mut self) { } + fn pgo_gen(&mut self) {} fn debuginfo(&mut self, strip: Strip) { match strip { Strip::None => {} Strip::Debuginfo => { - self.cmd().arg("--strip-debug"); } + self.cmd().arg("--strip-debug"); + } Strip::Symbols => { self.cmd().arg("--strip-all"); } @@ -1449,72 +1465,38 @@ impl<'a> Linker for L4Bender<'a> { self.cmd.arg("-nostdlib"); } - fn build_dylib(&mut self, _: &Path) { - bug!("not implemented"); - } - - fn export_symbols(&mut self, _: &Path, _: CrateType) { + fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) { // ToDo, not implemented, copy from GCC + self.sess.warn("exporting symbols not implemented yet for L4Bender"); return; } fn subsystem(&mut self, subsystem: &str) { - self.cmd.arg(&format!("--subsystem,{}", subsystem)); + self.cmd.arg(&format!("--subsystem {}", subsystem)); } - fn finalize(&mut self) { + fn reset_per_library_state(&mut self) { self.hint_static(); // Reset to default before returning the composed command line. } - fn group_start(&mut self) { self.cmd.arg("--start-group"); } - fn group_end(&mut self) { self.cmd.arg("--end-group"); } - fn linker_plugin_lto(&mut self) { - // do nothing - } - fn control_flow_guard(&mut self) { - self.sess.warn("Windows Control Flow Guard is not supported by this linker."); + fn group_start(&mut self) { + self.cmd.arg("--start-group"); } - fn no_crt_objects(&mut self) { } -} + fn group_end(&mut self) { + self.cmd.arg("--end-group"); + } -impl<'a> L4Bender<'a> { - pub fn new(mut cmd: Command, sess: &'a Session) -> L4Bender<'a> { - if let Ok(l4bender_args) = env::var("L4_BENDER_ARGS") { - L4Bender::split_cmd_args(&mut cmd, &l4bender_args); - } + fn linker_plugin_lto(&mut self) {} - cmd.arg("--"); // separate direct l4-bender args from linker args + fn control_flow_guard(&mut self) {} - L4Bender { - cmd: cmd, - sess: sess, - hinted_static: false, - } - } + fn no_crt_objects(&mut self) {} +} - /// This parses a shell-escaped string and unquotes the arguments. It doesn't attempt to - /// completely understand shell, but should instead allow passing arguments like - /// `-Dlinker="ld -m x86_64"`, and a copy without quotes, but spaces preserved, is added as an - /// argument to the given Command. This means that constructs as \" are not understood, so - /// quote wisely. - fn split_cmd_args(cmd: &mut Command, shell_args: &str) { - let mut arg = String::new(); - let mut quoted = false; - for character in shell_args.chars() { - match character { - ' ' if !quoted => { - cmd.arg(&arg); - arg.clear(); - }, - '"' | '\'' => quoted = !quoted, - _ => arg.push(character), - }; - } - if arg.len() > 0 { - cmd.arg(&arg); - arg.clear(); - } +impl<'a> L4Bender<'a> { + pub fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> { + L4Bender { cmd: cmd, sess: sess, hinted_static: false } } fn hint_static(&mut self) { diff --git a/compiler/rustc_target/src/spec/l4re_base.rs b/compiler/rustc_target/src/spec/l4re_base.rs index 235df91f41466..9e7973f63a970 100644 --- a/compiler/rustc_target/src/spec/l4re_base.rs +++ b/compiler/rustc_target/src/spec/l4re_base.rs @@ -1,16 +1,16 @@ -use crate::spec::{LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions}; +use crate::spec::{LinkerFlavor, PanicStrategy, TargetOptions}; use std::default::Default; pub fn opts() -> TargetOptions { TargetOptions { os: "l4re".to_string(), env: "uclibc".to_string(), - linker_flavor: LinkerFlavor::Ld, + linker_flavor: LinkerFlavor::L4Bender, executables: true, panic_strategy: PanicStrategy::Abort, linker: Some("l4-bender".to_string()), - pre_link_args: args, - os_family: Some("unix".to_string()), + linker_is_gnu: false, + families: vec!["unix".to_string()], ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs index 6457d7c3efaf1..64c7c1c5f6fbe 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs @@ -1,9 +1,12 @@ -use crate::spec::Target; +use crate::spec::{PanicStrategy, Target}; pub fn target() -> Target { let mut base = super::l4re_base::opts(); base.cpu = "x86-64".to_string(); base.max_atomic_width = Some(64); + base.crt_static_allows_dylibs = false; + base.dynamic_linking = false; + base.panic_strategy = PanicStrategy::Abort; Target { llvm_target: "x86_64-unknown-l4re-uclibc".to_string(), @@ -11,10 +14,6 @@ pub fn target() -> Target { data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" .to_string(), arch: "x86_64".to_string(), - target_os: "l4re".to_string(), - target_env: "uclibc".to_string(), - target_vendor: "unknown".to_string(), - linker_flavor: LinkerFlavor::L4Bender, options: base, } } diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index e5753ccae2d4f..7f05c82ac284b 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -39,6 +39,10 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "hermit")] { #[path = "hermit.rs"] mod real_imp; + } else if #[cfg(target_os = "l4re")] { + // L4Re is unix family but does not yet support unwinding. + #[path = "dummy.rs"] + mod real_imp; } else if #[cfg(target_env = "msvc")] { #[path = "seh.rs"] mod real_imp; From 29d623528d4c9385c2762fb826b48e4d19470e89 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 7 Jan 2022 18:03:07 +0800 Subject: [PATCH 14/20] Gate `l4-bender` linker flavor --- compiler/rustc_session/src/config.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 92ad0723f4879..a756de4c0fc45 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::impl_stable_hash_via_hash; use rustc_target::abi::{Align, TargetDataLayout}; -use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple, TargetWarnings}; +use rustc_target::spec::{LinkerFlavor, SplitDebuginfo, Target, TargetTriple, TargetWarnings}; use rustc_serialize::json; @@ -2237,6 +2237,16 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } } + if cg.linker_flavor == Some(LinkerFlavor::L4Bender) + && !nightly_options::is_unstable_enabled(matches) + { + early_error( + error_format, + "`l4-bender` linker flavor is unstable, `-Z unstable-options` \ + flag must also be passed to explicitly use it", + ); + } + let prints = collect_print_requests(&mut cg, &mut debugging_opts, matches, error_format); let cg = cg; From 13090889f5b8cbc72b1a14c2cb038dca5727d55c Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 21 Jan 2022 09:36:24 -0800 Subject: [PATCH 15/20] Disable drop range tracking in generators Generator drop tracking caused an ICE for generators involving the Never type (Issue #93161). Since this breaks miri, we temporarily disable drop tracking so miri is unblocked while we properly fix the issue. --- compiler/rustc_typeck/src/check/generator_interior.rs | 9 ++++++++- src/test/ui/async-await/async-fn-nonsend.rs | 4 ++++ src/test/ui/async-await/unresolved_type_param.rs | 4 ++++ src/test/ui/generator/drop-control-flow.rs | 4 ++++ src/test/ui/generator/issue-57478.rs | 4 ++++ src/test/ui/generator/partial-drop.rs | 4 ++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 56b6dd9a28446..cb6a49bd0c045 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -22,6 +22,10 @@ use tracing::debug; mod drop_ranges; +// FIXME(eholk): This flag is here to give a quick way to disable drop tracking in case we find +// unexpected breakages while it's still new. It should be removed before too long. +const ENABLE_DROP_TRACKING: bool = false; + struct InteriorVisitor<'a, 'tcx> { fcx: &'a FnCtxt<'a, 'tcx>, types: FxIndexSet>, @@ -77,7 +81,10 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> { yield_data.expr_and_pat_count, self.expr_count, source_span ); - if self.drop_ranges.is_dropped_at(hir_id, yield_data.expr_and_pat_count) + if ENABLE_DROP_TRACKING + && self + .drop_ranges + .is_dropped_at(hir_id, yield_data.expr_and_pat_count) { debug!("value is dropped at yield point; not recording"); return false; diff --git a/src/test/ui/async-await/async-fn-nonsend.rs b/src/test/ui/async-await/async-fn-nonsend.rs index c5453b67ef5b6..a1a05c0acba47 100644 --- a/src/test/ui/async-await/async-fn-nonsend.rs +++ b/src/test/ui/async-await/async-fn-nonsend.rs @@ -1,6 +1,10 @@ // edition:2018 // compile-flags: --crate-type lib +// FIXME(eholk): temporarily disabled while drop range tracking is disabled +// (see generator_interior.rs:27) +// ignore-test + use std::{cell::RefCell, fmt::Debug, rc::Rc}; fn non_sync() -> impl Debug { diff --git a/src/test/ui/async-await/unresolved_type_param.rs b/src/test/ui/async-await/unresolved_type_param.rs index d313691b38857..187356ca14021 100644 --- a/src/test/ui/async-await/unresolved_type_param.rs +++ b/src/test/ui/async-await/unresolved_type_param.rs @@ -3,6 +3,10 @@ // (rather than give a general error message) // edition:2018 +// FIXME(eholk): temporarily disabled while drop range tracking is disabled +// (see generator_interior.rs:27) +// ignore-test + async fn bar() -> () {} async fn foo() { diff --git a/src/test/ui/generator/drop-control-flow.rs b/src/test/ui/generator/drop-control-flow.rs index 6319a29f5b7d0..8540f7617acde 100644 --- a/src/test/ui/generator/drop-control-flow.rs +++ b/src/test/ui/generator/drop-control-flow.rs @@ -1,5 +1,9 @@ // build-pass +// FIXME(eholk): temporarily disabled while drop range tracking is disabled +// (see generator_interior.rs:27) +// ignore-test + // A test to ensure generators capture values that were conditionally dropped, // and also that values that are dropped along all paths to a yield do not get // included in the generator type. diff --git a/src/test/ui/generator/issue-57478.rs b/src/test/ui/generator/issue-57478.rs index 39710febdb95c..5c23ecbae3273 100644 --- a/src/test/ui/generator/issue-57478.rs +++ b/src/test/ui/generator/issue-57478.rs @@ -1,5 +1,9 @@ // check-pass +// FIXME(eholk): temporarily disabled while drop range tracking is disabled +// (see generator_interior.rs:27) +// ignore-test + #![feature(negative_impls, generators)] struct Foo; diff --git a/src/test/ui/generator/partial-drop.rs b/src/test/ui/generator/partial-drop.rs index 36f6e78cb3bfe..e89e4b61bbff7 100644 --- a/src/test/ui/generator/partial-drop.rs +++ b/src/test/ui/generator/partial-drop.rs @@ -1,3 +1,7 @@ +// FIXME(eholk): temporarily disabled while drop range tracking is disabled +// (see generator_interior.rs:27) +// ignore-test + #![feature(negative_impls, generators)] struct Foo; From 2c2deff74a84b8590c7339a22d23585a2089c767 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 21 Jan 2022 09:48:39 -0800 Subject: [PATCH 16/20] Add regression test for #93161 --- src/test/ui/generator/issue-93161.rs | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/test/ui/generator/issue-93161.rs diff --git a/src/test/ui/generator/issue-93161.rs b/src/test/ui/generator/issue-93161.rs new file mode 100644 index 0000000000000..9988acbcb73e1 --- /dev/null +++ b/src/test/ui/generator/issue-93161.rs @@ -0,0 +1,93 @@ +// edition:2021 +// run-pass + +#![feature(never_type)] + +use std::future::Future; + +// See if we can run a basic `async fn` +pub async fn foo(x: &u32, y: u32) -> u32 { + let y = &y; + let z = 9; + let z = &z; + let y = async { *y + *z }.await; + let a = 10; + let a = &a; + *x + y + *a +} + +async fn add(x: u32, y: u32) -> u32 { + let a = async { x + y }; + a.await +} + +async fn build_aggregate(a: u32, b: u32, c: u32, d: u32) -> u32 { + let x = (add(a, b).await, add(c, d).await); + x.0 + x.1 +} + +enum Never {} +fn never() -> Never { + panic!() +} + +async fn includes_never(crash: bool, x: u32) -> u32 { + let mut result = async { x * x }.await; + if !crash { + return result; + } + #[allow(unused)] + let bad = never(); + result *= async { x + x }.await; + drop(bad); + result +} + +async fn partial_init(x: u32) -> u32 { + #[allow(unreachable_code)] + let _x: (String, !) = (String::new(), return async { x + x }.await); +} + +async fn read_exact(_from: &mut &[u8], _to: &mut [u8]) -> Option<()> { + Some(()) +} + +async fn hello_world() { + let data = [0u8; 1]; + let mut reader = &data[..]; + + let mut marker = [0u8; 1]; + read_exact(&mut reader, &mut marker).await.unwrap(); +} + +fn run_fut(fut: impl Future) -> T { + use std::sync::Arc; + use std::task::{Context, Poll, Wake, Waker}; + + struct MyWaker; + impl Wake for MyWaker { + fn wake(self: Arc) { + unimplemented!() + } + } + + let waker = Waker::from(Arc::new(MyWaker)); + let mut context = Context::from_waker(&waker); + + let mut pinned = Box::pin(fut); + loop { + match pinned.as_mut().poll(&mut context) { + Poll::Pending => continue, + Poll::Ready(v) => return v, + } + } +} + +fn main() { + let x = 5; + assert_eq!(run_fut(foo(&x, 7)), 31); + assert_eq!(run_fut(build_aggregate(1, 2, 3, 4)), 10); + assert_eq!(run_fut(includes_never(false, 4)), 16); + assert_eq!(run_fut(partial_init(4)), 8); + run_fut(hello_world()); +} From f3cec54ff9eef6e892f9e12126b4bf76151dfceb Mon Sep 17 00:00:00 2001 From: Jonah Petri Date: Fri, 21 Jan 2022 13:08:14 -0500 Subject: [PATCH 17/20] update uclibc instructions for new toolchain, add link from platforms doc --- src/doc/rustc/src/platform-support.md | 2 +- .../src/platform-support/armv7-unknown-linux-uclibceabihf.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index f4f659ffa273e..d0ce5cb994bb1 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -220,7 +220,7 @@ target | std | host | notes `armv6-unknown-netbsd-eabihf` | ? | | `armv6k-nintendo-3ds` | * | | ARMv6K Nintendo 3DS, Horizon (Requires devkitARM toolchain) `armv7-apple-ios` | ✓ | | ARMv7 iOS, Cortex-a8 -`armv7-unknown-linux-uclibceabihf` | ✓ | ? | ARMv7 Linux uClibc +[`armv7-unknown-linux-uclibceabihf`](platform-support/armv7-unknown-linux-uclibceabihf.md) | ✓ | ? | ARMv7 Linux uClibc `armv7-unknown-freebsd` | ✓ | ✓ | ARMv7 FreeBSD `armv7-unknown-netbsd-eabihf` | ✓ | ✓ | `armv7-wrs-vxworks-eabihf` | ? | | diff --git a/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md index b3a4275c6ee92..1f029406367a2 100644 --- a/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md +++ b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md @@ -18,7 +18,7 @@ This target is cross compiled, and requires a cross toolchain. You can find sui Compiling rust for this target has been tested on `x86_64` linux hosts. Other host types have not been tested, but may work, if you can find a suitable cross compilation toolchain for them. -If you don't already have a suitable toolchain, download one [here](https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--uclibc--bleeding-edge-2020.08-1.tar.bz2), and unpack it into a directory. +If you don't already have a suitable toolchain, download one [here](https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--uclibc--bleeding-edge-2021.11-1.tar.bz2), and unpack it into a directory. ### Configure rust From ead84d089567eb46eb942ed377a032db921d2e6b Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 21 Jan 2022 11:06:14 -0800 Subject: [PATCH 18/20] Add reference to breakage this works around --- compiler/rustc_typeck/src/check/generator_interior.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index cb6a49bd0c045..c6b92db88ae8a 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -23,7 +23,8 @@ use tracing::debug; mod drop_ranges; // FIXME(eholk): This flag is here to give a quick way to disable drop tracking in case we find -// unexpected breakages while it's still new. It should be removed before too long. +// unexpected breakages while it's still new. It should be removed before too long. For example, +// see #93161. const ENABLE_DROP_TRACKING: bool = false; struct InteriorVisitor<'a, 'tcx> { From 78cee22fb4c6c4b57a7e96b25e90ca50d67a3c3a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 21 Jan 2022 20:41:47 +0100 Subject: [PATCH 19/20] Add missing GUI test explanations --- src/test/rustdoc-gui/check_info_sign_position.goml | 2 ++ src/test/rustdoc-gui/code-sidebar-toggle.goml | 1 + src/test/rustdoc-gui/escape-key.goml | 2 ++ src/test/rustdoc-gui/font-weight.goml | 2 +- src/test/rustdoc-gui/huge-collection-of-constants.goml | 4 ++-- src/test/rustdoc-gui/list_code_block.goml | 1 + src/test/rustdoc-gui/search-filter.goml | 1 + src/test/rustdoc-gui/search-result-colors.goml | 1 + src/test/rustdoc-gui/search-result-display.goml | 1 + src/test/rustdoc-gui/search-result-keyword.goml | 1 + .../rustdoc-gui/search-tab-selection-if-current-is-empty.goml | 2 ++ src/test/rustdoc-gui/sidebar.goml | 1 + src/test/rustdoc-gui/source-code-page.goml | 1 + src/test/rustdoc-gui/theme-change.goml | 1 + src/test/rustdoc-gui/toggle-docs-mobile.goml | 2 ++ src/test/rustdoc-gui/toggle-docs.goml | 1 + src/test/rustdoc-gui/trait-sidebar-item-order.goml | 1 + 17 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc-gui/check_info_sign_position.goml b/src/test/rustdoc-gui/check_info_sign_position.goml index 94e3fe79c9451..3bed7a0a03ea5 100644 --- a/src/test/rustdoc-gui/check_info_sign_position.goml +++ b/src/test/rustdoc-gui/check_info_sign_position.goml @@ -1,3 +1,5 @@ +// This test checks the position of the information on the code blocks (like +// `compile_fail` or `ignore`). goto: file://|DOC_PATH|/test_docs/index.html goto: ./fn.check_list_code_block.html // If the codeblock is the first element of the docblock, the information tooltip must have diff --git a/src/test/rustdoc-gui/code-sidebar-toggle.goml b/src/test/rustdoc-gui/code-sidebar-toggle.goml index 6fb92e196602e..1818f0dbcdf41 100644 --- a/src/test/rustdoc-gui/code-sidebar-toggle.goml +++ b/src/test/rustdoc-gui/code-sidebar-toggle.goml @@ -1,3 +1,4 @@ +// This test checks that the source code pages sidebar toggle is working as expected. goto: file://|DOC_PATH|/test_docs/index.html click: ".srclink" wait-for: "#sidebar-toggle" diff --git a/src/test/rustdoc-gui/escape-key.goml b/src/test/rustdoc-gui/escape-key.goml index 712920b16a91b..9cff12f3e4131 100644 --- a/src/test/rustdoc-gui/escape-key.goml +++ b/src/test/rustdoc-gui/escape-key.goml @@ -1,3 +1,5 @@ +// This test ensures that the "Escape" shortcut is handled correctly based on the +// current content displayed. goto: file://|DOC_PATH|/test_docs/index.html // First, we check that the search results are hidden when the Escape key is pressed. write: (".search-input", "test") diff --git a/src/test/rustdoc-gui/font-weight.goml b/src/test/rustdoc-gui/font-weight.goml index a64ac8b422fc0..5f29fde6689bf 100644 --- a/src/test/rustdoc-gui/font-weight.goml +++ b/src/test/rustdoc-gui/font-weight.goml @@ -1,5 +1,5 @@ -goto: file://|DOC_PATH|/lib2/struct.Foo.html // This test checks that the font weight is correctly applied. +goto: file://|DOC_PATH|/lib2/struct.Foo.html assert-css: ("//*[@class='docblock item-decl']//a[text()='Alias']", {"font-weight": "400"}) assert-css: ( "//*[@class='structfield small-section-header']//a[text()='Alias']", diff --git a/src/test/rustdoc-gui/huge-collection-of-constants.goml b/src/test/rustdoc-gui/huge-collection-of-constants.goml index 4f7fe7a212c92..4f75b5841ee5e 100644 --- a/src/test/rustdoc-gui/huge-collection-of-constants.goml +++ b/src/test/rustdoc-gui/huge-collection-of-constants.goml @@ -1,7 +1,7 @@ -goto: file://|DOC_PATH|/test_docs/huge_amount_of_consts/index.html - // Make sure that the last two entries are more than 12 pixels apart and not stacked on each other. +goto: file://|DOC_PATH|/test_docs/huge_amount_of_consts/index.html + compare-elements-position-near-false: ( "//*[@class='item-table']//div[last()-1]", "//*[@class='item-table']//div[last()-3]", diff --git a/src/test/rustdoc-gui/list_code_block.goml b/src/test/rustdoc-gui/list_code_block.goml index 7d3490e9d9410..eba1a662b9fa8 100644 --- a/src/test/rustdoc-gui/list_code_block.goml +++ b/src/test/rustdoc-gui/list_code_block.goml @@ -1,3 +1,4 @@ +// This test checks that code blocks in list are supported. goto: file://|DOC_PATH|/test_docs/index.html goto: ./fn.check_list_code_block.html assert: ("pre.rust.fn") diff --git a/src/test/rustdoc-gui/search-filter.goml b/src/test/rustdoc-gui/search-filter.goml index e5cdf3ea7a169..98ca40512ee3c 100644 --- a/src/test/rustdoc-gui/search-filter.goml +++ b/src/test/rustdoc-gui/search-filter.goml @@ -1,3 +1,4 @@ +// Checks that the crate search filtering is handled correctly and changes the results. goto: file://|DOC_PATH|/test_docs/index.html show-text: true write: (".search-input", "test") diff --git a/src/test/rustdoc-gui/search-result-colors.goml b/src/test/rustdoc-gui/search-result-colors.goml index b4eb896af1c7e..872df5fc3f95b 100644 --- a/src/test/rustdoc-gui/search-result-colors.goml +++ b/src/test/rustdoc-gui/search-result-colors.goml @@ -1,3 +1,4 @@ +// Checks that the result colors are as expected. goto: file://|DOC_PATH|/test_docs/index.html // We set the theme so we're sure that the correct values will be used, whatever the computer // this test is running on. diff --git a/src/test/rustdoc-gui/search-result-display.goml b/src/test/rustdoc-gui/search-result-display.goml index 3162a067d2107..823ea67b1b055 100644 --- a/src/test/rustdoc-gui/search-result-display.goml +++ b/src/test/rustdoc-gui/search-result-display.goml @@ -1,3 +1,4 @@ +// Checks that the search results have the expected width. goto: file://|DOC_PATH|/test_docs/index.html size: (900, 1000) write: (".search-input", "test") diff --git a/src/test/rustdoc-gui/search-result-keyword.goml b/src/test/rustdoc-gui/search-result-keyword.goml index 5342d431d992f..8b50c5c5e1a5b 100644 --- a/src/test/rustdoc-gui/search-result-keyword.goml +++ b/src/test/rustdoc-gui/search-result-keyword.goml @@ -1,3 +1,4 @@ +// Checks that the "keyword" results have the expected text alongside them. goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "CookieMonster") // Waiting for the search results to appear... diff --git a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml index a61ec672ae6e6..52b3ceae7b115 100644 --- a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml +++ b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml @@ -1,3 +1,5 @@ +// Checks that the first non-empty search result tab is selected if the default/currently selected +// one is empty. goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "Foo") // Waiting for the search results to appear... diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml index a117552585820..c7abe896be1d1 100644 --- a/src/test/rustdoc-gui/sidebar.goml +++ b/src/test/rustdoc-gui/sidebar.goml @@ -1,3 +1,4 @@ +// Checks multiple things on the sidebar display (width of its elements, colors, etc). goto: file://|DOC_PATH|/test_docs/index.html show-text: true local-storage: {"rustdoc-theme": "light"} diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml index f3682f59d2141..375ff4878e525 100644 --- a/src/test/rustdoc-gui/source-code-page.goml +++ b/src/test/rustdoc-gui/source-code-page.goml @@ -1,3 +1,4 @@ +// Checks that the interactions with the source code pages are workined as expected. goto: file://|DOC_PATH|/src/test_docs/lib.rs.html // Check that we can click on the line number. click: ".line-numbers > span:nth-child(4)" // This is the span for line 4. diff --git a/src/test/rustdoc-gui/theme-change.goml b/src/test/rustdoc-gui/theme-change.goml index 5221cda2f1fb6..60d089ffa3758 100644 --- a/src/test/rustdoc-gui/theme-change.goml +++ b/src/test/rustdoc-gui/theme-change.goml @@ -1,3 +1,4 @@ +// Ensures that the theme change is working as expected. goto: file://|DOC_PATH|/test_docs/index.html click: "#theme-picker" click: "#theme-choices > button:first-child" diff --git a/src/test/rustdoc-gui/toggle-docs-mobile.goml b/src/test/rustdoc-gui/toggle-docs-mobile.goml index e7a75b43c5a02..b502692300113 100644 --- a/src/test/rustdoc-gui/toggle-docs-mobile.goml +++ b/src/test/rustdoc-gui/toggle-docs-mobile.goml @@ -1,3 +1,5 @@ +// Checks that the documentation toggles on mobile have the correct position, style and work +// as expected. goto: file://|DOC_PATH|/test_docs/struct.Foo.html size: (433, 600) assert-attribute: (".top-doc", {"open": ""}) diff --git a/src/test/rustdoc-gui/toggle-docs.goml b/src/test/rustdoc-gui/toggle-docs.goml index e11aae21e3fa6..480d6242ac611 100644 --- a/src/test/rustdoc-gui/toggle-docs.goml +++ b/src/test/rustdoc-gui/toggle-docs.goml @@ -1,3 +1,4 @@ +// Checks that the documentation toggles have the correct position, style and work as expected. goto: file://|DOC_PATH|/test_docs/index.html assert-attribute: ("#main-content > details.top-doc", {"open": ""}) assert-text: ("#toggle-all-docs", "[−]") diff --git a/src/test/rustdoc-gui/trait-sidebar-item-order.goml b/src/test/rustdoc-gui/trait-sidebar-item-order.goml index 739745792c2a1..38942baa0b597 100644 --- a/src/test/rustdoc-gui/trait-sidebar-item-order.goml +++ b/src/test/rustdoc-gui/trait-sidebar-item-order.goml @@ -1,3 +1,4 @@ +// Checks that the elements in the sidebar are alphabetically sorted. goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html assert-text: (".sidebar-links a:nth-of-type(1)", "another") assert-text: (".sidebar-links a:nth-of-type(2)", "func1") From 2eb8bfc643ea488381776c9666538a79d5697a51 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 21 Jan 2022 12:04:59 -0800 Subject: [PATCH 20/20] rustdoc: remove dashed underline under main heading --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index bdd8aa430b2d1..b4ae953660a21 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -150,7 +150,6 @@ h1.fqn { display: flex; flex-wrap: wrap; justify-content: space-between; - border-bottom: 1px dashed #DDDDDD; padding-bottom: 6px; margin-bottom: 15px; }