Skip to content

Commit 308e632

Browse files
authored
Unrolled build for rust-lang#134760
Rollup merge of rust-lang#134760 - jieyouxu:enable-branch-protection-check-IBT, r=lqd Migrate `branch-protection-check-IBT` to rmake.rs - The Makefile version *never* ran because of Makefile syntax confusion because `ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86_64)` [compares `x86` to `x86_64`, which always evaluates to false](rust-lang#126720 (comment)). - The test would've always failed because precompiled std is not built with `-Z cf-protection=branch`, but linkers require all input object files to indicate IBT support in order to enable IBT for the executable, which is not the case for std. - Thus, the test input file is instead changed to a `no_std` program. - The test is currently limited to only `x86_64-unknown-linux-gnu` host, there are various other problems when the test is cross-compiled that I didn't want to fix atm, and is left as an exercise for the `-Z cf-protection` implementers. The GNU property note was added by rust-lang#110304 in order to address rust-lang#103001. Partially supersedes rust-lang#129156. The rmake.rs port was initially authored by `@Rejyr` in rust-lang#126720. This PR is co-authored with `@Oneirical` and `@Rejyr.` r? `@bjorn3` or reroll try-job: x86_64-mingw-1 try-job: x86_64-mingw-2 try-job: x86_64-msvc try-job: x86_64-apple-1 try-job: x86_64-apple-2
2 parents 7cb0849 + b32591e commit 308e632

File tree

5 files changed

+58
-54
lines changed

5 files changed

+58
-54
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
run-make/branch-protection-check-IBT/Makefile
21
run-make/cat-and-grep-sanity-check/Makefile
32
run-make/extern-fn-reachable/Makefile
43
run-make/jobserver-error/Makefile

tests/run-make/branch-protection-check-IBT/Makefile

-21
This file was deleted.

tests/run-make/branch-protection-check-IBT/_rmake.rs

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
fn main() {
2-
println!("hello world");
3-
}
1+
#![feature(no_core)]
2+
#![allow(internal_features)]
3+
#![no_core]
4+
#![no_std]
5+
#![no_main]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
//@ needs-llvm-components: x86
36+
37+
// FIXME(#93754): increase the test coverage of this test.
38+
//@ only-x86_64-unknown-linux-gnu
39+
//@ ignore-cross-compile
40+
41+
use run_make_support::{bare_rustc, llvm_readobj};
42+
43+
fn main() {
44+
// `main.rs` is `#![no_std]` to not pull in the currently not-compiled-with-IBT precompiled std.
45+
bare_rustc()
46+
.input("main.rs")
47+
.target("x86_64-unknown-linux-gnu")
48+
.arg("-Zcf-protection=branch")
49+
.arg("-Clink-args=-nostartfiles")
50+
.run();
51+
52+
llvm_readobj().arg("-nW").input("main").run().assert_stdout_contains(".note.gnu.property");
53+
}

0 commit comments

Comments
 (0)