Skip to content

Commit 45089ec

Browse files
committed
Auto merge of #131207 - davidtwco:pac-ret-lto-test, r=Mark-Simulacrum
ci: aarch64-gnu-debug job - Adds a new CI job which checks that the compiler builds with `--enable-debug` and tests that `needs-force-clang-based-tests` pass (where cross-language LTO is tested). - Add a test confirming that `-Zbranch-protection=pac-ret` and cross-language LTO work together. r? `@Mark-Simulacrum` try-job: aarch64-gnu-debug
2 parents 97ae1df + 352b505 commit 45089ec

File tree

6 files changed

+130
-4
lines changed

6 files changed

+130
-4
lines changed
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
FROM ubuntu:22.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
g++ \
6+
make \
7+
ninja-build \
8+
file \
9+
curl \
10+
ca-certificates \
11+
python3 \
12+
python3-dev \
13+
libxml2-dev \
14+
libncurses-dev \
15+
libedit-dev \
16+
swig \
17+
doxygen \
18+
git \
19+
cmake \
20+
sudo \
21+
gdb \
22+
libssl-dev \
23+
pkg-config \
24+
xz-utils \
25+
lld \
26+
clang \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
COPY scripts/sccache.sh /scripts/
30+
RUN sh /scripts/sccache.sh
31+
32+
ENV RUSTBUILD_FORCE_CLANG_BASED_TESTS 1
33+
ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
34+
35+
# llvm.use-linker conflicts with downloading CI LLVM
36+
ENV NO_DOWNLOAD_CI_LLVM 1
37+
38+
ENV RUST_CONFIGURE_ARGS \
39+
--build=aarch64-unknown-linux-gnu \
40+
--enable-debug \
41+
--enable-lld \
42+
--set llvm.use-linker=lld \
43+
--set target.aarch64-unknown-linux-gnu.linker=clang \
44+
--set target.aarch64-unknown-linux-gnu.cc=clang \
45+
--set target.aarch64-unknown-linux-gnu.cxx=clang++
46+
47+
# This job appears to be checking two separate things:
48+
# - That we can build the compiler with `--enable-debug`
49+
# (without necessarily testing the result).
50+
# - That the tests with `//@ needs-force-clang-based-tests` pass, since they
51+
# don't run by default unless RUSTBUILD_FORCE_CLANG_BASED_TESTS is set.
52+
# - FIXME(https://github.com/rust-lang/rust/pull/126155#issuecomment-2156314273):
53+
# Currently we only run the subset of tests with "clang" in their name.
54+
# - See also FIXME(#132034)
55+
56+
ENV SCRIPT \
57+
python3 ../x.py --stage 2 build && \
58+
python3 ../x.py --stage 2 test tests/run-make --test-args clang

Diff for: src/ci/github-actions/jobs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ auto:
123123
- image: aarch64-gnu
124124
<<: *job-aarch64-linux
125125

126+
- image: aarch64-gnu-debug
127+
<<: *job-aarch64-linux
128+
126129
- image: arm-android
127130
<<: *job-linux-4c
128131

Diff for: tests/run-make/cross-lang-lto-clang/rmake.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99

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

12+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
13+
static RUST_ALWAYS_INLINED_PATTERN: &'static str = "bl.*<rust_always_inlined>";
14+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
15+
static RUST_ALWAYS_INLINED_PATTERN: &'static str = "call.*rust_always_inlined";
16+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
17+
static C_ALWAYS_INLINED_PATTERN: &'static str = "bl.*<c_always_inlined>";
18+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
19+
static C_ALWAYS_INLINED_PATTERN: &'static str = "call.*c_always_inlined";
20+
21+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
22+
static RUST_NEVER_INLINED_PATTERN: &'static str = "bl.*<rust_never_inlined>";
23+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
24+
static RUST_NEVER_INLINED_PATTERN: &'static str = "call.*rust_never_inlined";
25+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
26+
static C_NEVER_INLINED_PATTERN: &'static str = "bl.*<c_never_inlined>";
27+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
28+
static C_NEVER_INLINED_PATTERN: &'static str = "call.*c_never_inlined";
29+
1230
fn main() {
1331
rustc()
1432
.linker_plugin_lto("on")
@@ -31,14 +49,14 @@ fn main() {
3149
.disassemble()
3250
.input("cmain")
3351
.run()
34-
.assert_stdout_not_contains_regex("call.*rust_always_inlined");
52+
.assert_stdout_not_contains_regex(RUST_ALWAYS_INLINED_PATTERN);
3553
// As a sanity check, make sure we do find a call instruction to a
3654
// non-inlined function
3755
llvm_objdump()
3856
.disassemble()
3957
.input("cmain")
4058
.run()
41-
.assert_stdout_contains_regex("call.*rust_never_inlined");
59+
.assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
4260
clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
4361
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
4462
rustc()
@@ -53,10 +71,10 @@ fn main() {
5371
.disassemble()
5472
.input("rsmain")
5573
.run()
56-
.assert_stdout_not_contains_regex("call.*c_always_inlined");
74+
.assert_stdout_not_contains_regex(C_ALWAYS_INLINED_PATTERN);
5775
llvm_objdump()
5876
.disassemble()
5977
.input("rsmain")
6078
.run()
61-
.assert_stdout_contains_regex("call.*c_never_inlined");
79+
.assert_stdout_contains_regex(C_NEVER_INLINED_PATTERN);
6280
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
2+
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
3+
// This test checks that compilation and execution is successful when this feature is activated,
4+
// with some of its possible extra arguments (bti, pac-ret, leaf) when doing LTO.
5+
// See https://github.com/rust-lang/rust/pull/88354
6+
7+
//@ needs-force-clang-based-tests
8+
//@ only-aarch64
9+
// Reason: branch protection is not supported on other architectures
10+
//@ ignore-cross-compile
11+
// Reason: the compiled binary is executed
12+
13+
use run_make_support::{clang, env_var, llvm_ar, run, rustc, static_lib_name};
14+
15+
fn main() {
16+
clang()
17+
.arg("-v")
18+
.lto("thin")
19+
.arg("-mbranch-protection=bti+pac-ret+leaf")
20+
.arg("-O2")
21+
.arg("-c")
22+
.out_exe("test.o")
23+
.input("test.c")
24+
.run();
25+
llvm_ar().obj_to_ar().output_input(static_lib_name("test"), "test.o").run();
26+
rustc()
27+
.linker_plugin_lto("on")
28+
.opt_level("2")
29+
.linker(&env_var("CLANG"))
30+
.link_arg("-fuse-ld=lld")
31+
.arg("-Zbranch-protection=bti,pac-ret,leaf")
32+
.input("test.rs")
33+
.output("test.bin")
34+
.run();
35+
run("test.bin");
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[link(name = "test")]
2+
extern "C" {
3+
fn foo() -> i32;
4+
}
5+
6+
fn main() {
7+
unsafe {
8+
foo();
9+
}
10+
}

0 commit comments

Comments
 (0)