diff --git a/compiler-builtins/src/int/specialized_div_rem/mod.rs b/compiler-builtins/src/int/specialized_div_rem/mod.rs index 7841e4f33..5ffe1f59b 100644 --- a/compiler-builtins/src/int/specialized_div_rem/mod.rs +++ b/compiler-builtins/src/int/specialized_div_rem/mod.rs @@ -196,13 +196,12 @@ unsafe fn u128_by_u64_div_rem(duo: u128, div: u64) -> (u64, u64) { unsafe { // divides the combined registers rdx:rax (`duo` is split into two 64 bit parts to do this) // by `div`. The quotient is stored in rax and the remainder in rdx. - // FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust. core::arch::asm!( "div {0}", in(reg) div, inlateout("rax") duo_lo => quo, inlateout("rdx") duo_hi => rem, - options(att_syntax, pure, nomem, nostack) + options(pure, nomem, nostack), ); } (quo, rem) @@ -283,13 +282,12 @@ unsafe fn u64_by_u32_div_rem(duo: u64, div: u32) -> (u32, u32) { unsafe { // divides the combined registers rdx:rax (`duo` is split into two 32 bit parts to do this) // by `div`. The quotient is stored in rax and the remainder in rdx. - // FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust. core::arch::asm!( "div {0}", in(reg) div, inlateout("rax") duo_lo => quo, inlateout("rdx") duo_hi => rem, - options(att_syntax, pure, nomem, nostack) + options(pure, nomem, nostack), ); } (quo, rem) diff --git a/compiler-builtins/src/mem/x86_64.rs b/compiler-builtins/src/mem/x86_64.rs index fb29eb11b..cb780ec03 100644 --- a/compiler-builtins/src/mem/x86_64.rs +++ b/compiler-builtins/src/mem/x86_64.rs @@ -22,13 +22,12 @@ use core::{intrinsics, mem}; #[inline(always)] #[cfg(target_feature = "ermsb")] pub unsafe fn copy_forward(dest: *mut u8, src: *const u8, count: usize) { - // FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust. - core::arch::asm!( - "repe movsb (%rsi), (%rdi)", + asm!( + "repe movsb [rdi], [rsi]", inout("rcx") count => _, inout("rdi") dest => _, inout("rsi") src => _, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); } @@ -42,21 +41,21 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, count: usize) inout("ecx") pre_byte_count => _, inout("rdi") dest => dest, inout("rsi") src => src, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); asm!( "rep movsq", inout("rcx") qword_count => _, inout("rdi") dest => dest, inout("rsi") src => src, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); asm!( "rep movsb", inout("ecx") byte_count => _, inout("rdi") dest => _, inout("rsi") src => _, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); } @@ -67,14 +66,14 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) { asm!( "std", "rep movsb", - "sub $7, %rsi", - "sub $7, %rdi", - "mov {qword_count:r}, %rcx", + "sub rsi, 7", + "sub rdi, 7", + "mov rcx, {qword_count:r}", "rep movsq", "test {pre_byte_count:e}, {pre_byte_count:e}", - "add $7, %rsi", - "add $7, %rdi", - "mov {pre_byte_count:e}, %ecx", + "add rsi, 7", + "add rdi, 7", + "mov ecx, {pre_byte_count:e}", "rep movsb", "cld", pre_byte_count = in(reg) pre_byte_count, @@ -83,20 +82,19 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) { inout("rdi") dest.add(count - 1) => _, inout("rsi") src.add(count - 1) => _, // We modify flags, but we restore it afterwards - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); } #[inline(always)] #[cfg(target_feature = "ermsb")] pub unsafe fn set_bytes(dest: *mut u8, c: u8, count: usize) { - // FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust. - core::arch::asm!( - "repe stosb %al, (%rdi)", + asm!( + "repe stosb [rdi], al", inout("rcx") count => _, inout("rdi") dest => _, inout("al") c => _, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ) } @@ -111,21 +109,21 @@ pub unsafe fn set_bytes(mut dest: *mut u8, c: u8, count: usize) { inout("ecx") pre_byte_count => _, inout("rdi") dest => dest, in("rax") c, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); asm!( "rep stosq", inout("rcx") qword_count => _, inout("rdi") dest => dest, in("rax") c, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); asm!( "rep stosb", inout("ecx") byte_count => _, inout("rdi") dest => _, in("rax") c, - options(att_syntax, nostack, preserves_flags) + options(nostack, preserves_flags) ); } @@ -212,10 +210,10 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize { let x = { let r; asm!( - "movdqa ({addr:r}), {dest}", + "movdqa {dest}, [{addr:r}]", addr = in(reg) s, dest = out(xmm_reg) r, - options(att_syntax, nostack), + options(nostack, preserves_flags), ); r }; @@ -232,10 +230,10 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize { let x = { let r; asm!( - "movdqa ({addr:r}), {dest}", + "movdqa {dest}, [{addr:r}]", addr = in(reg) s, dest = out(xmm_reg) r, - options(att_syntax, nostack), + options(nostack, preserves_flags), ); r }; @@ -277,10 +275,10 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize { let mut cs = { let r: u64; asm!( - "mov ({addr}), {dest}", + "mov {dest}, [{addr}]", addr = in(reg) s, dest = out(reg) r, - options(att_syntax, nostack), + options(nostack, preserves_flags), ); r }; diff --git a/compiler-builtins/src/probestack.rs b/compiler-builtins/src/probestack.rs index 72975485a..1cab64ea1 100644 --- a/compiler-builtins/src/probestack.rs +++ b/compiler-builtins/src/probestack.rs @@ -47,11 +47,11 @@ // We only define stack probing for these architectures today. #![cfg(any(target_arch = "x86_64", target_arch = "x86"))] -// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax, +// Our goal here is to touch each page between `rsp+8` and `rsp+8-rax`, // ensuring that if any pages are unmapped we'll make a page fault. // -// The ABI here is that the stack frame size is located in `%rax`. Upon -// return we're not supposed to modify `%rsp` or `%rax`. +// The ABI here is that the stack frame size is located in `rax`. Upon +// return we're not supposed to modify `rsp` or `rax`. #[cfg(target_arch = "x86_64")] #[unsafe(naked)] #[rustc_std_internal_symbol] @@ -59,50 +59,50 @@ pub unsafe extern "custom" fn __rust_probestack() { core::arch::naked_asm!( " .cfi_startproc - pushq %rbp + push rbp .cfi_adjust_cfa_offset 8 - .cfi_offset %rbp, -16 - movq %rsp, %rbp - .cfi_def_cfa_register %rbp + .cfi_offset rbp, -16 + mov rbp, rsp + .cfi_def_cfa_register rbp - mov %rax,%r11 // duplicate %rax as we're clobbering %r11 + mov r11, rax // duplicate rax as we're clobbering r11 // Main loop, taken in one page increments. We're decrementing rsp by // a page each time until there's less than a page remaining. We're // guaranteed that this function isn't called unless there's more than a // page needed. // - // Note that we're also testing against `8(%rsp)` to account for the 8 + // Note that we're also testing against `[rsp + 8]` to account for the 8 // bytes pushed on the stack originally with our return address. Using - // `8(%rsp)` simulates us testing the stack pointer in the caller's + // `[rsp + 8]` simulates us testing the stack pointer in the caller's // context. - // It's usually called when %rax >= 0x1000, but that's not always true. + // It's usually called when rax >= 0x1000, but that's not always true. // Dynamic stack allocation, which is needed to implement unsized - // rvalues, triggers stackprobe even if %rax < 0x1000. - // Thus we have to check %r11 first to avoid segfault. - cmp $0x1000,%r11 + // rvalues, triggers stackprobe even if rax < 0x1000. + // Thus we have to check r11 first to avoid segfault. + cmp r11, 0x1000 jna 3f 2: - sub $0x1000,%rsp - test %rsp,8(%rsp) - sub $0x1000,%r11 - cmp $0x1000,%r11 + sub rsp, 0x1000 + test qword ptr [rsp + 8], rsp + sub r11, 0x1000 + cmp r11, 0x1000 ja 2b 3: // Finish up the last remaining stack space requested, getting the last // bits out of r11 - sub %r11,%rsp - test %rsp,8(%rsp) + sub rsp, r11 + test qword ptr [rsp + 8], rsp // Restore the stack pointer to what it previously was when entering // this function. The caller will readjust the stack pointer after we // return. - add %rax,%rsp + add rsp, rax leave - .cfi_def_cfa_register %rsp + .cfi_def_cfa_register rsp .cfi_adjust_cfa_offset -8 ", #[cfg(not(all(target_env = "sgx", target_vendor = "fortanix")))] @@ -112,14 +112,13 @@ pub unsafe extern "custom" fn __rust_probestack() { // for this target, [manually patch for LVI]. // // [manually patch for LVI]: https://software.intel.com/security-software-guidance/insights/deep-dive-load-value-injection#specialinstructions - pop %r11 + pop r11 lfence - jmp *%r11 + jmp r11 ", " .cfi_endproc ", - options(att_syntax) ) } @@ -135,36 +134,35 @@ pub unsafe extern "custom" fn __rust_probestack() { core::arch::naked_asm!( " .cfi_startproc - push %ebp + push ebp .cfi_adjust_cfa_offset 4 - .cfi_offset %ebp, -8 - mov %esp, %ebp - .cfi_def_cfa_register %ebp - push %ecx - mov %eax,%ecx + .cfi_offset ebp, -8 + mov ebp, esp + .cfi_def_cfa_register ebp + push ecx + mov ecx, eax - cmp $0x1000,%ecx + cmp ecx, 0x1000 jna 3f 2: - sub $0x1000,%esp - test %esp,8(%esp) - sub $0x1000,%ecx - cmp $0x1000,%ecx + sub esp, 0x1000 + test dword ptr [esp + 8], esp + sub ecx, 0x1000 + cmp ecx, 0x1000 ja 2b 3: - sub %ecx,%esp - test %esp,8(%esp) + sub esp, ecx + test dword ptr [esp + 8], esp - add %eax,%esp - pop %ecx + add esp, eax + pop ecx leave - .cfi_def_cfa_register %esp + .cfi_def_cfa_register esp .cfi_adjust_cfa_offset -4 ret .cfi_endproc - ", - options(att_syntax) + ", ) } @@ -176,8 +174,8 @@ pub unsafe extern "custom" fn __rust_probestack() { // REF: Rust commit(74e80468347) // rust\src\llvm-project\llvm\lib\Target\X86\X86FrameLowering.cpp: 805 // Comments in LLVM: -// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves. -// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp +// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust esp themselves. +// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust `rsp` // themselves. #[unsafe(naked)] #[rustc_std_internal_symbol] @@ -185,40 +183,39 @@ pub unsafe extern "custom" fn __rust_probestack() { core::arch::naked_asm!( " .cfi_startproc - push %ebp + push ebp .cfi_adjust_cfa_offset 4 - .cfi_offset %ebp, -8 - mov %esp, %ebp - .cfi_def_cfa_register %ebp - push %ecx - push %edx - mov %eax,%ecx - - cmp $0x1000,%ecx + .cfi_offset ebp, -8 + mov ebp, esp + .cfi_def_cfa_register ebp + push ecx + push edx + mov ecx, eax + + cmp ecx, 0x1000 jna 3f 2: - sub $0x1000,%esp - test %esp,8(%esp) - sub $0x1000,%ecx - cmp $0x1000,%ecx + sub esp, 0x1000 + test dword ptr [esp + 8], esp + sub ecx, 0x1000 + cmp ecx, 0x1000 ja 2b 3: - sub %ecx,%esp - test %esp,8(%esp) - mov 4(%ebp),%edx - mov %edx, 12(%esp) - add %eax,%esp - pop %edx - pop %ecx + sub esp, ecx + test dword ptr [esp + 8], esp + mov edx, dword ptr [ebp + 4] + mov dword ptr [esp + 12], edx + add esp, eax + pop edx + pop ecx leave - sub %eax, %esp - .cfi_def_cfa_register %esp + sub esp, eax + .cfi_def_cfa_register esp .cfi_adjust_cfa_offset -4 ret .cfi_endproc - ", - options(att_syntax) + ", ) } diff --git a/compiler-builtins/src/x86.rs b/compiler-builtins/src/x86.rs index 51940b3b3..1a3c41860 100644 --- a/compiler-builtins/src/x86.rs +++ b/compiler-builtins/src/x86.rs @@ -22,26 +22,25 @@ intrinsics! { pub unsafe extern "custom" fn _alloca() { // __chkstk and _alloca are the same function core::arch::naked_asm!( - "push %ecx", - "cmp $0x1000,%eax", - "lea 8(%esp),%ecx", // esp before calling this routine -> ecx - "jb 1f", + "push ecx", + "cmp eax, 0x1000", + "lea ecx, [esp + 8]", // esp before calling this routine -> ecx + "jb 3f", "2:", - "sub $0x1000,%ecx", - "test %ecx,(%ecx)", - "sub $0x1000,%eax", - "cmp $0x1000,%eax", + "sub ecx, 0x1000", + "test [ecx], ecx", + "sub eax, 0x1000", + "cmp eax, 0x1000", "ja 2b", - "1:", - "sub %eax,%ecx", - "test %ecx,(%ecx)", - "lea 4(%esp),%eax", // load pointer to the return address into eax - "mov %ecx,%esp", // install the new top of stack pointer into esp - "mov -4(%eax),%ecx", // restore ecx - "push (%eax)", // push return address onto the stack - "sub %esp,%eax", // restore the original value in eax + "3:", + "sub ecx, eax", + "test [ecx], ecx", + "lea eax, [esp + 4]", // load pointer to the return address into eax + "mov esp, ecx", // install the new top of stack pointer into esp + "mov ecx, [eax - 4]", // restore ecx + "push [eax]", // push return address onto the stack + "sub eax, esp", // restore the original value in eax "ret", - options(att_syntax) ); } } diff --git a/compiler-builtins/src/x86_64.rs b/compiler-builtins/src/x86_64.rs index f9ae784d5..99a527ee9 100644 --- a/compiler-builtins/src/x86_64.rs +++ b/compiler-builtins/src/x86_64.rs @@ -12,24 +12,23 @@ intrinsics! { #[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin", target_os = "uefi"))] pub unsafe extern "custom" fn ___chkstk_ms() { core::arch::naked_asm!( - "push %rcx", - "push %rax", - "cmp $0x1000,%rax", - "lea 24(%rsp),%rcx", - "jb 1f", + "push rcx", + "push rax", + "cmp rax, 0x1000", + "lea rcx, [rsp + 24]", + "jb 3f", "2:", - "sub $0x1000,%rcx", - "test %rcx,(%rcx)", - "sub $0x1000,%rax", - "cmp $0x1000,%rax", + "sub rcx, 0x1000", + "test [rcx], rcx", + "sub rax, 0x1000", + "cmp rax, 0x1000", "ja 2b", - "1:", - "sub %rax,%rcx", - "test %rcx,(%rcx)", - "pop %rax", - "pop %rcx", + "3:", + "sub rcx, rax", + "test [rcx], rcx", + "pop rax", + "pop rcx", "ret", - options(att_syntax) ); } }