rust/tests/codegen-llvm/sanitizer/kcfi/naked-function.rs
Jonathan Pallant 6ecb3f33f0
Adds two new Tier 3 targets - aarch64v8r-unknown-none and aarch64v8r-unknown-none-softfloat.
The existing `aarch64-unknown-none` target assumes Armv8.0-A as a baseline. However, Arm recently released the Arm Cortex-R82 processor which is the first to implement the Armv8-R AArch64 mode architecture. This architecture is similar to Armv8-A AArch64, however it has a different set of mandatory features, and is based off of Armv8.4. It is largely unrelated to the existing Armv8-R architecture target (`armv8r-none-eabihf`), which only operates in AArch32 mode.

The second `aarch64v8r-unknown-none-softfloat` target allows for possible Armv8-R AArch64 CPUs with no FPU, or for use-cases where FPU register stacking is not desired. As with the existing `aarch64-unknown-none` target we have coupled FPU support and Neon support together - there is no 'has FPU but does not have NEON' target proposed even though the architecture technically allows for it.

This PR was developed by Ferrous Systems on behalf of Arm. Arm is the owner of these changes.
2026-01-26 12:43:52 +00:00

50 lines
1.4 KiB
Rust

//@ add-minicore
//@ revisions: aarch64 aarch64v8r x86_64
//@ [aarch64] compile-flags: --target aarch64-unknown-none
//@ [aarch64] needs-llvm-components: aarch64
//@ [aarch64v8r] compile-flags: --target aarch64v8r-unknown-none
//@ [aarch64v8r] needs-llvm-components: aarch64
//@ [x86_64] compile-flags: --target x86_64-unknown-none
//@ [x86_64] needs-llvm-components: x86
//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Cno-prepopulate-passes -Copt-level=0
#![feature(no_core, lang_items)]
#![crate_type = "lib"]
#![no_core]
extern crate minicore;
use minicore::*;
struct Thing;
trait MyTrait {
// NOTE: this test assumes that this trait is dyn-compatible.
#[unsafe(naked)]
extern "C" fn my_naked_function(&self) {
// the real function is defined
// CHECK: .globl
// CHECK-SAME: my_naked_function
naked_asm!("ret")
}
}
impl MyTrait for Thing {}
// the shim calls the real function
// CHECK-LABEL: define
// CHECK-SAME: my_naked_function
// CHECK-SAME: reify_fnptr
// CHECK-LABEL: main
#[unsafe(no_mangle)]
pub fn main() {
// Trick the compiler into generating an indirect call.
const F: extern "C" fn(&Thing) = Thing::my_naked_function;
// main calls the shim function
// CHECK: call void
// CHECK-SAME: my_naked_function
// CHECK-SAME: reify_fnptr
(F)(&Thing);
}
// CHECK: declare !kcfi_type
// CHECK-SAME: my_naked_function