-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update unstable book with global_asm feature
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# `global_asm` | ||
|
||
The tracking issue for this feature is: [#35119] | ||
|
||
[#35119]: https://github.com/rust-lang/rust/issues/35119 | ||
|
||
------------------------ | ||
|
||
The `global_asm!` macro allows the programmer to write arbitrary | ||
assembly outside the scope of a function body, passing it through | ||
`rustc` and `llvm` to the assembler. The macro is a no-frills | ||
interface to LLVM's concept of module-level assembly. That is, all | ||
caveats, constraints, injunctions, rules, best practices, terms, and | ||
conditions apply to assembly written with `global_asm!`. | ||
|
||
`global_asm!` fills a role currently not satisfied by either `asm!` | ||
or `#[naked]` functions. With it, a programmer may define arbitrary | ||
symbols, assembler macros, functions, or _any_ other low-level | ||
behavior. The programmer has all features of the assembler at their | ||
disposal. This means linker will expect to resolve any symbols | ||
defined by the macro, modulo any symbols marked as external. It also | ||
means syntax for directives and assembly follow the conventions of | ||
the assembler in your toolchain. | ||
|
||
A simple usage looks like this: | ||
|
||
```rust,ignore | ||
global_asm!(r#" | ||
.global my_asm_func | ||
.hidden __cancel | ||
my_asm_func: | ||
ret | ||
__other_cancel: | ||
jmp __cancel | ||
"#); | ||
extern "C" { | ||
fn my_asm_func(); | ||
fn __other_cancel(); | ||
} | ||
fn __cancel() { | ||
// do strange stuff | ||
} | ||
``` |