about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/cross-lang-lto-clang/rmake.rs26
-rw-r--r--tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs36
-rw-r--r--tests/run-make/pointer-auth-link-with-c-lto-clang/test.c1
-rw-r--r--tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs10
4 files changed, 69 insertions, 4 deletions
diff --git a/tests/run-make/cross-lang-lto-clang/rmake.rs b/tests/run-make/cross-lang-lto-clang/rmake.rs
index 1b15a54aacb..3fed6ea2066 100644
--- a/tests/run-make/cross-lang-lto-clang/rmake.rs
+++ b/tests/run-make/cross-lang-lto-clang/rmake.rs
@@ -9,6 +9,24 @@
 
 use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, rustc, static_lib_name};
 
+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
+static RUST_ALWAYS_INLINED_PATTERN: &'static str = "bl.*<rust_always_inlined>";
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+static RUST_ALWAYS_INLINED_PATTERN: &'static str = "call.*rust_always_inlined";
+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
+static C_ALWAYS_INLINED_PATTERN: &'static str = "bl.*<c_always_inlined>";
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+static C_ALWAYS_INLINED_PATTERN: &'static str = "call.*c_always_inlined";
+
+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
+static RUST_NEVER_INLINED_PATTERN: &'static str = "bl.*<rust_never_inlined>";
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+static RUST_NEVER_INLINED_PATTERN: &'static str = "call.*rust_never_inlined";
+#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
+static C_NEVER_INLINED_PATTERN: &'static str = "bl.*<c_never_inlined>";
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+static C_NEVER_INLINED_PATTERN: &'static str = "call.*c_never_inlined";
+
 fn main() {
     rustc()
         .linker_plugin_lto("on")
@@ -31,14 +49,14 @@ fn main() {
         .disassemble()
         .input("cmain")
         .run()
-        .assert_stdout_not_contains_regex("call.*rust_always_inlined");
+        .assert_stdout_not_contains_regex(RUST_ALWAYS_INLINED_PATTERN);
     // As a sanity check, make sure we do find a call instruction to a
     // non-inlined function
     llvm_objdump()
         .disassemble()
         .input("cmain")
         .run()
-        .assert_stdout_contains_regex("call.*rust_never_inlined");
+        .assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
     clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
     llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
     rustc()
@@ -53,10 +71,10 @@ fn main() {
         .disassemble()
         .input("rsmain")
         .run()
-        .assert_stdout_not_contains_regex("call.*c_always_inlined");
+        .assert_stdout_not_contains_regex(C_ALWAYS_INLINED_PATTERN);
     llvm_objdump()
         .disassemble()
         .input("rsmain")
         .run()
-        .assert_stdout_contains_regex("call.*c_never_inlined");
+        .assert_stdout_contains_regex(C_NEVER_INLINED_PATTERN);
 }
diff --git a/tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs b/tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs
new file mode 100644
index 00000000000..cf6e3d86377
--- /dev/null
+++ b/tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs
@@ -0,0 +1,36 @@
+// `-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, run, rustc, static_lib_name};
+
+fn main() {
+    clang()
+        .arg("-v")
+        .lto("thin")
+        .arg("-mbranch-protection=bti+pac-ret+leaf")
+        .arg("-O2")
+        .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();
+    run("test.bin");
+}
diff --git a/tests/run-make/pointer-auth-link-with-c-lto-clang/test.c b/tests/run-make/pointer-auth-link-with-c-lto-clang/test.c
new file mode 100644
index 00000000000..9fe07f82f9e
--- /dev/null
+++ b/tests/run-make/pointer-auth-link-with-c-lto-clang/test.c
@@ -0,0 +1 @@
+int foo() { return 0; }
diff --git a/tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs b/tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs
new file mode 100644
index 00000000000..1a3be80e898
--- /dev/null
+++ b/tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs
@@ -0,0 +1,10 @@
+#[link(name = "test")]
+extern "C" {
+    fn foo() -> i32;
+}
+
+fn main() {
+    unsafe {
+        foo();
+    }
+}