| 
 | 1 | +// ignore-tidy-linelength  | 
 | 2 | +//! A basic smoke test to check for GNU Property Note to see that for `x86_64` targets when [`-Z  | 
 | 3 | +//! cf-protection=branch`][intel-cet-tracking-issue] is requested, that the  | 
 | 4 | +//!  | 
 | 5 | +//! ```text  | 
 | 6 | +//! NT_GNU_PROPERTY_TYPE_0 Properties: x86 feature: IBT  | 
 | 7 | +//! ```  | 
 | 8 | +//!  | 
 | 9 | +//! Intel Indirect Branch Tracking (IBT) property is emitted. This was generated in  | 
 | 10 | +//! <https://github.com/rust-lang/rust/pull/110304> in order to address  | 
 | 11 | +//! <https://github.com/rust-lang/rust/issues/103001>.  | 
 | 12 | +//!  | 
 | 13 | +//! Note that the precompiled std currently is not compiled with `-Z cf-protection=branch`!  | 
 | 14 | +//!  | 
 | 15 | +//! In particular, it is expected that:  | 
 | 16 | +//!  | 
 | 17 | +//! > IBT to only be enabled for the process if `.note.gnu.property` indicates that the executable  | 
 | 18 | +//! > was compiled with IBT support and the linker to only tell that IBT is supported if all input  | 
 | 19 | +//! > object files indicate that they support IBT, which in turn requires the standard library to be  | 
 | 20 | +//! > compiled with IBT enabled.  | 
 | 21 | +//!  | 
 | 22 | +//! Note that Intel IBT (Indirect Branch Tracking) is not to be confused with Arm's BTI (Branch  | 
 | 23 | +//! Target Identification). See below for link to Intel IBT docs.  | 
 | 24 | +//!  | 
 | 25 | +//! ## Related links  | 
 | 26 | +//!  | 
 | 27 | +//! - [Tracking Issue for Intel Control Enforcement Technology (CET)][intel-cet-tracking-issue]  | 
 | 28 | +//! - Zulip question about this test:  | 
 | 29 | +//! <https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20Branch.20protection.20and.20.60.2Enote.2Egnu.2Eproperty.60>  | 
 | 30 | +//! - Intel IBT docs:  | 
 | 31 | +//!   <https://edc.intel.com/content/www/us/en/design/ipla/software-development-platforms/client/platforms/alder-lake-desktop/12th-generation-intel-core-processors-datasheet-volume-1-of-2/006/indirect-branch-tracking/>  | 
 | 32 | +//!  | 
 | 33 | +//! [intel-cet-tracking-issue]: https://github.com/rust-lang/rust/issues/93754  | 
 | 34 | +
  | 
 | 35 | +// Only checks Intel IBT.  | 
 | 36 | +//@ only-x86_64  | 
 | 37 | +//@ needs-llvm-components: x86  | 
 | 38 | + | 
 | 39 | +use run_make_support::{bare_rustc, llvm_readobj};  | 
 | 40 | + | 
 | 41 | +fn main() {  | 
 | 42 | +    // `main.rs` is `#![no_std]` to not pull in the currently not-compiled-with-IBT precompiled std.  | 
 | 43 | +    bare_rustc()  | 
 | 44 | +        .input("main.rs")  | 
 | 45 | +        .target("x86_64-unknown-linux-gnu")  | 
 | 46 | +        .panic("abort")  | 
 | 47 | +        .arg("-Zcf-protection=branch")  | 
 | 48 | +        .arg("-Clink-args=-nostartfiles")  | 
 | 49 | +        .arg("-Csave-temps")  | 
 | 50 | +        .run();  | 
 | 51 | + | 
 | 52 | +    llvm_readobj().arg("-nW").input("main").run().assert_stdout_contains(".note.gnu.property");  | 
 | 53 | +}  | 
0 commit comments