Skip to content

Commit a90422e

Browse files
committed
Auto merge of rust-lang#134760 - jieyouxu:enable-branch-protection-check-IBT, r=<try>
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 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-msvc try-job: x86_64-apple-1 try-job: x86_64-apple-2
2 parents a0a5c42 + 5871cee commit a90422e

File tree

5 files changed

+64
-53
lines changed

5 files changed

+64
-53
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/incr-add-rust-src-component/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,12 @@
1-
fn main() {
2-
println!("hello world");
1+
#![no_std]
2+
#![no_main]
3+
4+
#[panic_handler]
5+
fn panic(_info: &core::panic::PanicInfo) -> ! {
6+
loop {}
7+
}
8+
9+
#[no_mangle]
10+
pub extern "C" fn main(argc: i32, argv: *const *const u8) -> i32 {
11+
0
312
}
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+
// 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

Comments
 (0)