summaryrefslogtreecommitdiffstats
path: root/src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs')
-rw-r--r--src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs b/src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs
new file mode 100644
index 000000000..79b0bb2d7
--- /dev/null
+++ b/src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs
@@ -0,0 +1,21 @@
+// compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti
+// assembly-output: emit-asm
+// needs-asm-support
+// only-aarch64
+
+#![crate_type = "lib"]
+#![feature(naked_functions)]
+use std::arch::asm;
+
+// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
+// meaning "no prologue whatsoever, no, really, not one instruction."
+// Unfortunately, aarch64's "branch target identification" works via hints at landing sites.
+// LLVM implements this via making sure of that, even for functions with the naked attribute.
+// So, we must emit an appropriate instruction instead!
+#[no_mangle]
+#[naked]
+pub unsafe extern "C" fn _hlt() -> ! {
+ // CHECK-NOT: hint #34
+ // CHECK: hlt #0x1
+ asm!("hlt #1", options(noreturn))
+}