From f76ca2247998bff4e10b73fcb464a0a83edbfeb0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:30:24 +0000 Subject: [PATCH] Enable inline asm on macOS --- Readme.md | 4 +--- example/mini_core_hello_world.rs | 14 ++++++++++++-- src/global_asm.rs | 8 ++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index 8a2db5a43ec..1e84c7fa365 100644 --- a/Readme.md +++ b/Readme.md @@ -52,9 +52,7 @@ configuration options. ## Not yet supported * Inline assembly ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1041)) - * On Linux there is support for invoking an external assembler for `global_asm!` and `asm!`. - `llvm_asm!` will remain unimplemented forever. `asm!` doesn't yet support reg classes. You - have to specify specific registers instead. + * On UNIX there is support for invoking an external assembler for `global_asm!` and `asm!`. * SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171), some basic things work) ## License diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 7e9cbe1bba5..e83be3a3df5 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -321,7 +321,7 @@ fn main() { #[cfg(not(any(jit, windows)))] test_tls(); - #[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] + #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))] unsafe { global_asm_test(); } @@ -343,7 +343,7 @@ fn main() { } } -#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] +#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))] extern "C" { fn global_asm_test(); } @@ -358,6 +358,16 @@ global_asm! { " } +#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))] +global_asm! { + " + .global _global_asm_test + _global_asm_test: + // comment that would normally be removed by LLVM + ret + " +} + #[repr(C)] enum c_void { _1, diff --git a/src/global_asm.rs b/src/global_asm.rs index 8e711988f81..917a6fff727 100644 --- a/src/global_asm.rs +++ b/src/global_asm.rs @@ -41,9 +41,7 @@ pub(crate) struct GlobalAsmConfig { impl GlobalAsmConfig { pub(crate) fn new(tcx: TyCtxt<'_>) -> Self { - let asm_enabled = cfg!(feature = "inline_asm") - && !tcx.sess.target.is_like_osx - && !tcx.sess.target.is_like_windows; + let asm_enabled = cfg!(feature = "inline_asm") && !tcx.sess.target.is_like_windows; GlobalAsmConfig { asm_enabled, @@ -74,9 +72,7 @@ pub(crate) fn compile_global_asm( .to_owned(), ); } else { - return Err( - "asm! and global_asm! are not yet supported on macOS and Windows".to_owned() - ); + return Err("asm! and global_asm! are not yet supported on Windows".to_owned()); } }