Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f76ca22

Browse files
committed
Enable inline asm on macOS
1 parent e45f600 commit f76ca22

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ configuration options.
5252
## Not yet supported
5353

5454
* Inline assembly ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1041))
55-
* On Linux there is support for invoking an external assembler for `global_asm!` and `asm!`.
56-
`llvm_asm!` will remain unimplemented forever. `asm!` doesn't yet support reg classes. You
57-
have to specify specific registers instead.
55+
* On UNIX there is support for invoking an external assembler for `global_asm!` and `asm!`.
5856
* SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171), some basic things work)
5957

6058
## License

example/mini_core_hello_world.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn main() {
321321
#[cfg(not(any(jit, windows)))]
322322
test_tls();
323323

324-
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
324+
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
325325
unsafe {
326326
global_asm_test();
327327
}
@@ -343,7 +343,7 @@ fn main() {
343343
}
344344
}
345345

346-
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
346+
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
347347
extern "C" {
348348
fn global_asm_test();
349349
}
@@ -358,6 +358,16 @@ global_asm! {
358358
"
359359
}
360360

361+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))]
362+
global_asm! {
363+
"
364+
.global _global_asm_test
365+
_global_asm_test:
366+
// comment that would normally be removed by LLVM
367+
ret
368+
"
369+
}
370+
361371
#[repr(C)]
362372
enum c_void {
363373
_1,

src/global_asm.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ pub(crate) struct GlobalAsmConfig {
4141

4242
impl GlobalAsmConfig {
4343
pub(crate) fn new(tcx: TyCtxt<'_>) -> Self {
44-
let asm_enabled = cfg!(feature = "inline_asm")
45-
&& !tcx.sess.target.is_like_osx
46-
&& !tcx.sess.target.is_like_windows;
44+
let asm_enabled = cfg!(feature = "inline_asm") && !tcx.sess.target.is_like_windows;
4745

4846
GlobalAsmConfig {
4947
asm_enabled,
@@ -74,9 +72,7 @@ pub(crate) fn compile_global_asm(
7472
.to_owned(),
7573
);
7674
} else {
77-
return Err(
78-
"asm! and global_asm! are not yet supported on macOS and Windows".to_owned()
79-
);
75+
return Err("asm! and global_asm! are not yet supported on Windows".to_owned());
8076
}
8177
}
8278

0 commit comments

Comments
 (0)