Make #[naked]
an unsafe attribute
This commit is contained in:
parent
191df20fca
commit
41ddf86722
46 changed files with 375 additions and 403 deletions
|
@ -8,11 +8,9 @@
|
|||
#![feature(naked_functions)]
|
||||
#![no_std]
|
||||
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
pub unsafe extern "C" fn c_variadic(_: usize, _: ...) {
|
||||
// CHECK-NOT: va_start
|
||||
// CHECK-NOT: alloca
|
||||
core::arch::naked_asm! {
|
||||
"ret",
|
||||
}
|
||||
core::arch::naked_asm!("ret")
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ pub fn caller() {
|
|||
}
|
||||
|
||||
// CHECK: declare x86_intrcc void @page_fault_handler(ptr {{.*}}, i64{{.*}}){{.*}}#[[ATTRS:[0-9]+]]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[no_mangle]
|
||||
pub extern "x86-interrupt" fn page_fault_handler(_: u64, _: u64) {
|
||||
unsafe { core::arch::naked_asm!("ud2") };
|
||||
core::arch::naked_asm!("ud2")
|
||||
}
|
||||
|
||||
// CHECK: #[[ATTRS]] =
|
||||
|
|
|
@ -10,8 +10,8 @@ use std::arch::naked_asm;
|
|||
// CHECK-LABEL: naked_empty:
|
||||
#[repr(align(16))]
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_empty() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_empty() {
|
||||
// CHECK: ret
|
||||
naked_asm!("ret");
|
||||
naked_asm!("ret")
|
||||
}
|
||||
|
|
|
@ -28,21 +28,19 @@ fn test(x: u64) {
|
|||
// CHECK: add rax, 1
|
||||
// CHECK: add rax, 42
|
||||
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn using_const_generics<const N: u64>(x: u64) -> u64 {
|
||||
const M: u64 = 42;
|
||||
|
||||
unsafe {
|
||||
naked_asm!(
|
||||
"xor rax, rax",
|
||||
"add rax, rdi",
|
||||
"add rax, {}",
|
||||
"add rax, {}",
|
||||
"ret",
|
||||
const N,
|
||||
const M,
|
||||
)
|
||||
}
|
||||
naked_asm!(
|
||||
"xor rax, rax",
|
||||
"add rax, rdi",
|
||||
"add rax, {}",
|
||||
"add rax, {}",
|
||||
"ret",
|
||||
const N,
|
||||
const M,
|
||||
)
|
||||
}
|
||||
|
||||
trait Invert {
|
||||
|
@ -60,16 +58,14 @@ impl Invert for i64 {
|
|||
// CHECK: call
|
||||
// CHECK: ret
|
||||
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn generic_function<T: Invert>(x: i64) -> i64 {
|
||||
unsafe {
|
||||
naked_asm!(
|
||||
"call {}",
|
||||
"ret",
|
||||
sym <T as Invert>::invert,
|
||||
)
|
||||
}
|
||||
naked_asm!(
|
||||
"call {}",
|
||||
"ret",
|
||||
sym <T as Invert>::invert,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -81,10 +77,10 @@ struct Foo(u64);
|
|||
// CHECK: mov rax, rdi
|
||||
|
||||
impl Foo {
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[no_mangle]
|
||||
extern "C" fn method(self) -> u64 {
|
||||
unsafe { naked_asm!("mov rax, rdi", "ret") }
|
||||
naked_asm!("mov rax, rdi", "ret")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,10 +93,10 @@ trait Bar {
|
|||
}
|
||||
|
||||
impl Bar for Foo {
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[no_mangle]
|
||||
extern "C" fn trait_method(self) -> u64 {
|
||||
unsafe { naked_asm!("mov rax, rdi", "ret") }
|
||||
naked_asm!("mov rax, rdi", "ret")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +105,7 @@ impl Bar for Foo {
|
|||
// CHECK: lea rax, [rdi + rsi]
|
||||
|
||||
// this previously ICE'd, see https://github.com/rust-lang/rust/issues/124375
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
|
||||
naked_asm!("lea rax, [rdi + rsi]", "ret");
|
||||
|
|
|
@ -20,8 +20,8 @@ use minicore::*;
|
|||
// arm-mode: .arm
|
||||
// thumb-mode: .thumb
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
unsafe extern "C" fn test_unspecified() {
|
||||
#[unsafe(naked)]
|
||||
extern "C" fn test_unspecified() {
|
||||
naked_asm!("bx lr");
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ unsafe extern "C" fn test_unspecified() {
|
|||
// arm-mode: .arm
|
||||
// thumb-mode: .thumb
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[instruction_set(arm::t32)]
|
||||
unsafe extern "C" fn test_thumb() {
|
||||
extern "C" fn test_thumb() {
|
||||
naked_asm!("bx lr");
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ unsafe extern "C" fn test_thumb() {
|
|||
// arm-mode: .arm
|
||||
// thumb-mode: .thumb
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[instruction_set(arm::a32)]
|
||||
unsafe extern "C" fn test_arm() {
|
||||
extern "C" fn test_arm() {
|
||||
naked_asm!("bx lr");
|
||||
}
|
||||
|
|
|
@ -9,24 +9,24 @@
|
|||
//
|
||||
// CHECK: .balign 16
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_no_explicit_align() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_no_explicit_align() {
|
||||
core::arch::naked_asm!("ret")
|
||||
}
|
||||
|
||||
// CHECK: .balign 16
|
||||
#[no_mangle]
|
||||
#[repr(align(8))]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_lower_align() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_lower_align() {
|
||||
core::arch::naked_asm!("ret")
|
||||
}
|
||||
|
||||
// CHECK: .balign 32
|
||||
#[no_mangle]
|
||||
#[repr(align(32))]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_higher_align() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_higher_align() {
|
||||
core::arch::naked_asm!("ret")
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub unsafe extern "C" fn naked_higher_align() {
|
|||
// CHECK: .balign 16
|
||||
#[no_mangle]
|
||||
#[cold]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn no_explicit_align_cold() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn no_explicit_align_cold() {
|
||||
core::arch::naked_asm!("ret")
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ use minicore::*;
|
|||
// linux,win: .att_syntax
|
||||
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_empty() {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_empty() {
|
||||
#[cfg(not(all(target_arch = "arm", target_feature = "thumb-mode")))]
|
||||
naked_asm!("ret");
|
||||
|
||||
|
@ -114,8 +114,8 @@ pub unsafe extern "C" fn naked_empty() {
|
|||
// linux,win: .att_syntax
|
||||
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
{
|
||||
naked_asm!("lea rax, [rdi + rsi]", "ret")
|
||||
|
@ -138,9 +138,9 @@ pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize
|
|||
// thumb: .pushsection .text.some_different_name,\22ax\22, %progbits
|
||||
// CHECK-LABEL: test_link_section:
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
#[link_section = ".text.some_different_name"]
|
||||
pub unsafe extern "C" fn test_link_section() {
|
||||
pub extern "C" fn test_link_section() {
|
||||
#[cfg(not(all(target_arch = "arm", target_feature = "thumb-mode")))]
|
||||
naked_asm!("ret");
|
||||
|
||||
|
@ -159,7 +159,7 @@ pub unsafe extern "C" fn test_link_section() {
|
|||
// win_i686-LABEL: @fastcall_cc@4:
|
||||
#[cfg(target_os = "windows")]
|
||||
#[no_mangle]
|
||||
#[naked]
|
||||
pub unsafe extern "fastcall" fn fastcall_cc(x: i32) -> i32 {
|
||||
#[unsafe(naked)]
|
||||
pub extern "fastcall" fn fastcall_cc(x: i32) -> i32 {
|
||||
naked_asm!("ret");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue