From cace605f08c924e631380bb6786e2a6c918de63e Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 2 Mar 2022 20:14:17 -0800 Subject: [PATCH 1/3] [beta] Update cargo --- Cargo.lock | 12 ++++++------ src/tools/cargo | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd65ed8d4a2d6..e3ab987b3ab46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,7 @@ dependencies = [ "cargo-test-macro", "cargo-test-support", "cargo-util", - "clap 3.0.13", + "clap 3.1.5", "crates-io", "crossbeam-utils", "curl", @@ -606,9 +606,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.13" +version = "3.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e" +checksum = "ced1892c55c910c1219e98d6fc8d71f6bddba7905866ce740066d8bfea859312" dependencies = [ "atty", "bitflags", @@ -616,7 +616,7 @@ dependencies = [ "os_str_bytes", "strsim 0.10.0", "termcolor", - "textwrap 0.14.2", + "textwrap 0.15.0", ] [[package]] @@ -5032,9 +5032,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" diff --git a/src/tools/cargo b/src/tools/cargo index ea2a21c994ca1..d1fd9fe2c40a1 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit ea2a21c994ca1e4d4c49412827b3cf4dcb158b1d +Subproject commit d1fd9fe2c40a1a56af9132b5c92ab963ac7ae422 From 150cc0c0290e1765b235ef4da40e93f000ae2211 Mon Sep 17 00:00:00 2001 From: Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> Date: Thu, 24 Feb 2022 21:42:17 +0100 Subject: [PATCH 2/3] Rollup merge of #94315 - lcnr:auto-trait-lint-update, r=oli-obk update auto trait lint for `PhantomData` cc https://github.com/rust-lang/rust/issues/93367#issuecomment-1047898410 --- compiler/rustc_typeck/src/coherence/orphan.rs | 1 + .../ui/auto-traits/suspicious-impls-lint.rs | 10 +++++++ .../auto-traits/suspicious-impls-lint.stderr | 29 ++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 9bb3100379655..dfa4120784a2e 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -440,6 +440,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: } match t.kind() { + ty::Adt(def, substs) if def.is_phantom_data() => substs.super_visit_with(self), ty::Adt(def, substs) => { // @lcnr: This is the only place where cycles can happen. We avoid this // by only visiting each `DefId` once. diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.rs b/src/test/ui/auto-traits/suspicious-impls-lint.rs index 1026a35a455ac..1574a7e02e97f 100644 --- a/src/test/ui/auto-traits/suspicious-impls-lint.rs +++ b/src/test/ui/auto-traits/suspicious-impls-lint.rs @@ -1,5 +1,7 @@ #![deny(suspicious_auto_trait_impls)] +use std::marker::PhantomData; + struct MayImplementSendOk(T); unsafe impl Send for MayImplementSendOk {} // ok @@ -31,4 +33,12 @@ unsafe impl Send for TwoParamsSame {} //~^ ERROR //~| WARNING this will change its meaning +pub struct WithPhantomDataNonSend(PhantomData<*const T>, U); +unsafe impl Send for WithPhantomDataNonSend {} // ok + +pub struct WithPhantomDataSend(PhantomData, U); +unsafe impl Send for WithPhantomDataSend<*const T, i8> {} +//~^ ERROR +//~| WARNING this will change its meaning + fn main() {} diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.stderr b/src/test/ui/auto-traits/suspicious-impls-lint.stderr index f91aa862271d3..084bfef49c029 100644 --- a/src/test/ui/auto-traits/suspicious-impls-lint.stderr +++ b/src/test/ui/auto-traits/suspicious-impls-lint.stderr @@ -1,5 +1,5 @@ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:7:1 + --> $DIR/suspicious-impls-lint.rs:9:1 | LL | unsafe impl Send for MayImplementSendErr<&T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,14 +12,14 @@ LL | #![deny(suspicious_auto_trait_impls)] = warning: this will change its meaning in a future release! = note: for more information, see issue #93367 note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:6:1 + --> $DIR/suspicious-impls-lint.rs:8:1 | LL | struct MayImplementSendErr(T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `&T` is not a generic parameter error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:19:1 + --> $DIR/suspicious-impls-lint.rs:21:1 | LL | unsafe impl Send for ContainsVec {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,14 +27,14 @@ LL | unsafe impl Send for ContainsVec {} = warning: this will change its meaning in a future release! = note: for more information, see issue #93367 note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:18:1 + --> $DIR/suspicious-impls-lint.rs:20:1 | LL | struct ContainsVec(Vec); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `i32` is not a generic parameter error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:30:1 + --> $DIR/suspicious-impls-lint.rs:32:1 | LL | unsafe impl Send for TwoParamsSame {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,11 +42,26 @@ LL | unsafe impl Send for TwoParamsSame {} = warning: this will change its meaning in a future release! = note: for more information, see issue #93367 note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:29:1 + --> $DIR/suspicious-impls-lint.rs:31:1 | LL | struct TwoParamsSame(T, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `T` is mentioned multiple times -error: aborting due to 3 previous errors +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:40:1 + | +LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:39:1 + | +LL | pub struct WithPhantomDataSend(PhantomData, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `*const T` is not a generic parameter + +error: aborting due to 4 previous errors From 7eda3298c82d7c1ab573323fc781dd539172ab21 Mon Sep 17 00:00:00 2001 From: bors Date: Sat, 26 Feb 2022 21:53:03 +0000 Subject: [PATCH 3/3] Auto merge of #93516 - nagisa:branch-protection, r=cjgillot No branch protection metadata unless enabled Even if we emit metadata disabling branch protection, this metadata may conflict with other modules (e.g. during LTO) that have different branch protection metadata set. This is an unstable flag and feature, so ideally the flag not being specified should act as if the feature wasn't implemented in the first place. Additionally this PR also ensures we emit an error if `-Zbranch-protection` is set on targets other than the supported aarch64. For now the error is being output from codegen, but ideally it should be moved to earlier in the pipeline before stabilization. --- compiler/rustc_codegen_llvm/src/context.rs | 60 +++++++++---------- compiler/rustc_interface/src/tests.rs | 5 +- compiler/rustc_session/src/lib.rs | 1 + compiler/rustc_session/src/options.rs | 5 +- src/test/codegen/branch-protection.rs | 53 ++++++++-------- ...rotection-missing-pac-ret.BADFLAGS.stderr} | 0 ...rotection-missing-pac-ret.BADTARGET.stderr | 4 ++ .../branch-protection-missing-pac-ret.rs | 15 ++++- 8 files changed, 85 insertions(+), 58 deletions(-) rename src/test/ui/invalid-compile-flags/{branch-protection-missing-pac-ret.stderr => branch-protection-missing-pac-ret.BADFLAGS.stderr} (100%) create mode 100644 src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 90ddf7914502b..ddc8d72e9bf87 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -269,36 +269,36 @@ pub unsafe fn create_module<'ll>( } } - if sess.target.arch == "aarch64" { - let BranchProtection { bti, pac_ret: pac } = sess.opts.debugging_opts.branch_protection; - - llvm::LLVMRustAddModuleFlag( - llmod, - llvm::LLVMModFlagBehavior::Error, - "branch-target-enforcement\0".as_ptr().cast(), - bti.into(), - ); - - llvm::LLVMRustAddModuleFlag( - llmod, - llvm::LLVMModFlagBehavior::Error, - "sign-return-address\0".as_ptr().cast(), - pac.is_some().into(), - ); - let pac_opts = pac.unwrap_or(PacRet { leaf: false, key: PAuthKey::A }); - llvm::LLVMRustAddModuleFlag( - llmod, - llvm::LLVMModFlagBehavior::Error, - "sign-return-address-all\0".as_ptr().cast(), - pac_opts.leaf.into(), - ); - let is_bkey: bool = pac_opts.key != PAuthKey::A; - llvm::LLVMRustAddModuleFlag( - llmod, - llvm::LLVMModFlagBehavior::Error, - "sign-return-address-with-bkey\0".as_ptr().cast(), - is_bkey.into(), - ); + if let Some(BranchProtection { bti, pac_ret }) = sess.opts.debugging_opts.branch_protection { + if sess.target.arch != "aarch64" { + sess.err("-Zbranch-protection is only supported on aarch64"); + } else { + llvm::LLVMRustAddModuleFlag( + llmod, + llvm::LLVMModFlagBehavior::Error, + "branch-target-enforcement\0".as_ptr().cast(), + bti.into(), + ); + llvm::LLVMRustAddModuleFlag( + llmod, + llvm::LLVMModFlagBehavior::Error, + "sign-return-address\0".as_ptr().cast(), + pac_ret.is_some().into(), + ); + let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A }); + llvm::LLVMRustAddModuleFlag( + llmod, + llvm::LLVMModFlagBehavior::Error, + "sign-return-address-all\0".as_ptr().cast(), + pac_opts.leaf.into(), + ); + llvm::LLVMRustAddModuleFlag( + llmod, + llvm::LLVMModFlagBehavior::Error, + "sign-return-address-with-bkey\0".as_ptr().cast(), + u32::from(pac_opts.key == PAuthKey::B), + ); + } } // Pass on the control-flow protection flags to LLVM (equivalent to `-fcf-protection` in Clang). diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 9ab138c1b12a5..f9c39f7f83d4b 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -721,7 +721,10 @@ fn test_debugging_options_tracking_hash() { tracked!(binary_dep_depinfo, true); tracked!( branch_protection, - BranchProtection { bti: true, pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B }) } + Some(BranchProtection { + bti: true, + pac_ret: Some(PacRet { leaf: true, key: PAuthKey::B }) + }) ); tracked!(chalk, true); tracked!(codegen_backend, Some("abc".to_string())); diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 383250cd68f17..c7a6ac1d4ee88 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -2,6 +2,7 @@ #![feature(derive_default_enum)] #![feature(min_specialization)] #![feature(once_cell)] +#![feature(option_get_or_insert_default)] #![recursion_limit = "256"] #![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))] diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 0a4bd23937dec..658b07cced850 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -984,9 +984,10 @@ mod parse { true } - crate fn parse_branch_protection(slot: &mut BranchProtection, v: Option<&str>) -> bool { + crate fn parse_branch_protection(slot: &mut Option, v: Option<&str>) -> bool { match v { Some(s) => { + let slot = slot.get_or_insert_default(); for opt in s.split(',') { match opt { "bti" => slot.bti = true, @@ -1161,7 +1162,7 @@ options! { (default: no)"), borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED], "select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"), - branch_protection: BranchProtection = (BranchProtection::default(), parse_branch_protection, [TRACKED], + branch_protection: Option = (None, parse_branch_protection, [TRACKED], "set options for branch target identification and pointer authentication on AArch64"), cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED], "instrument control-flow architecture protection"), diff --git a/src/test/codegen/branch-protection.rs b/src/test/codegen/branch-protection.rs index 106c9b148ee35..b23073778c0b5 100644 --- a/src/test/codegen/branch-protection.rs +++ b/src/test/codegen/branch-protection.rs @@ -1,12 +1,12 @@ // Test that the correct module flags are emitted with different branch protection flags. -// revisions: bti pac-ret leaf b-key +// revisions: BTI PACRET LEAF BKEY NONE // min-llvm-version: 12.0.0 // needs-llvm-components: aarch64 -// [bti] compile-flags: -Z branch-protection=bti -// [pac-ret] compile-flags: -Z branch-protection=pac-ret -// [leaf] compile-flags: -Z branch-protection=pac-ret,leaf -// [b-key] compile-flags: -Z branch-protection=pac-ret,b-key +// [BTI] compile-flags: -Z branch-protection=bti +// [PACRET] compile-flags: -Z branch-protection=pac-ret +// [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf +// [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key // compile-flags: --target aarch64-unknown-linux-gnu #![crate_type = "lib"] @@ -20,22 +20,27 @@ trait Sized { } pub fn test() { } -// bti: !"branch-target-enforcement", i32 1 -// bti: !"sign-return-address", i32 0 -// bti: !"sign-return-address-all", i32 0 -// bti: !"sign-return-address-with-bkey", i32 0 - -// pac-ret: !"branch-target-enforcement", i32 0 -// pac-ret: !"sign-return-address", i32 1 -// pac-ret: !"sign-return-address-all", i32 0 -// pac-ret: !"sign-return-address-with-bkey", i32 0 - -// leaf: !"branch-target-enforcement", i32 0 -// leaf: !"sign-return-address", i32 1 -// leaf: !"sign-return-address-all", i32 1 -// leaf: !"sign-return-address-with-bkey", i32 0 - -// b-key: !"branch-target-enforcement", i32 0 -// b-key: !"sign-return-address", i32 1 -// b-key: !"sign-return-address-all", i32 0 -// b-key: !"sign-return-address-with-bkey", i32 1 +// BTI: !"branch-target-enforcement", i32 1 +// BTI: !"sign-return-address", i32 0 +// BTI: !"sign-return-address-all", i32 0 +// BTI: !"sign-return-address-with-bkey", i32 0 + +// PACRET: !"branch-target-enforcement", i32 0 +// PACRET: !"sign-return-address", i32 1 +// PACRET: !"sign-return-address-all", i32 0 +// PACRET: !"sign-return-address-with-bkey", i32 0 + +// LEAF: !"branch-target-enforcement", i32 0 +// LEAF: !"sign-return-address", i32 1 +// LEAF: !"sign-return-address-all", i32 1 +// LEAF: !"sign-return-address-with-bkey", i32 0 + +// BKEY: !"branch-target-enforcement", i32 0 +// BKEY: !"sign-return-address", i32 1 +// BKEY: !"sign-return-address-all", i32 0 +// BKEY: !"sign-return-address-with-bkey", i32 1 + +// NONE-NOT: branch-target-enforcement +// NONE-NOT: sign-return-address +// NONE-NOT: sign-return-address-all +// NONE-NOT: sign-return-address-with-bkey diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.stderr b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADFLAGS.stderr similarity index 100% rename from src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.stderr rename to src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADFLAGS.stderr diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr new file mode 100644 index 0000000000000..6bd9c6a0276f8 --- /dev/null +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr @@ -0,0 +1,4 @@ +error: -Zbranch-protection is only supported on aarch64 + +error: aborting due to previous error + diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs index 4f39d223a2e0c..4bc4919bc935b 100644 --- a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs @@ -1 +1,14 @@ -// compile-flags: -Z branch-protection=leaf +// revisions: BADFLAGS BADTARGET +// [BADFLAGS] compile-flags: --target=aarch64-unknown-linux-gnu -Zbranch-protection=leaf +// [BADFLAGS] check-fail +// [BADFLAGS] needs-llvm-components: aarch64 +// [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti +// [BADTARGET] build-fail +// [BADTARGET] needs-llvm-components: x86 + +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized { }