File: rmake.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (48 lines) | stat: -rw-r--r-- 1,690 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
// This test checks that compilation and execution is successful when this feature is activated,
// with some of its possible extra arguments (bti, pac-ret, leaf) when doing LTO.
// See https://github.com/rust-lang/rust/pull/88354

//@ needs-force-clang-based-tests
//@ only-aarch64
// Reason: branch protection is not supported on other architectures
//@ ignore-cross-compile
// Reason: the compiled binary is executed

use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, run, rustc, static_lib_name};

static PAUTH_A_KEY_PATTERN: &'static str = "paciasp";
static PAUTH_B_KEY_PATTERN: &'static str = "pacibsp";

fn main() {
    clang()
        .arg("-v")
        .lto("thin")
        .arg("-mbranch-protection=bti+pac-ret+b-key+leaf")
        .arg("-c")
        .out_exe("test.o")
        .input("test.c")
        .run();
    llvm_ar().obj_to_ar().output_input(static_lib_name("test"), "test.o").run();
    rustc()
        .linker_plugin_lto("on")
        .opt_level("2")
        .linker(&env_var("CLANG"))
        .link_arg("-fuse-ld=lld")
        .arg("-Zbranch-protection=bti,pac-ret,leaf")
        .input("test.rs")
        .output("test.bin")
        .run();

    // Check that both a-key and b-key pac-ret survived LTO
    llvm_objdump()
        .disassemble()
        .input("test.bin")
        .run()
        .assert_stdout_contains_regex(PAUTH_A_KEY_PATTERN)
        .assert_stdout_contains_regex(PAUTH_B_KEY_PATTERN);

    // Check that the binary actually runs
    run("test.bin");
}