@@ -8,12 +8,9 @@ The tracking issue for this feature is: [#35119]
8
8
9
9
The ` global_asm! ` macro allows the programmer to write arbitrary
10
10
assembly outside the scope of a function body, passing it through
11
- ` rustc ` and ` llvm ` to the assembler. The macro is a no-frills
12
- interface to LLVM's concept of [ module-level inline assembly] . That is,
13
- all caveats applicable to LLVM's module-level inline assembly apply
14
- to ` global_asm! ` .
15
-
16
- [ module-level inline assembly ] : http://llvm.org/docs/LangRef.html#module-level-inline-assembly
11
+ ` rustc ` and ` llvm ` to the assembler. That is to say, ` global_asm! ` is
12
+ equivalent to assembling the asm with an external assembler and then
13
+ linking the resulting object file with the current crate.
17
14
18
15
` global_asm! ` fills a role not currently satisfied by either ` asm! `
19
16
or ` #[naked] ` functions. The programmer has _ all_ features of the
@@ -69,8 +66,44 @@ pub mod harry {
69
66
```
70
67
71
68
You may use ` global_asm! ` multiple times, anywhere in your crate, in
72
- whatever way suits you. The effect is as if you concatenated all
73
- usages and placed the larger, single usage in the crate root.
69
+ whatever way suits you. However, you should not rely on assembler state
70
+ (e.g. assembler macros) defined in one ` global_asm! ` to be available in
71
+ another one. It is implementation-defined whether the multiple usages
72
+ are concatenated into one or assembled separately.
73
+
74
+ ` global_asm! ` also supports ` const ` operands like ` asm! ` , which allows
75
+ constants defined in Rust to be used in assembly code:
76
+
77
+ ``` rust,no_run
78
+ #![feature(global_asm)]
79
+ # #[cfg(any(target_arch="x86", target_arch="x86_64"))]
80
+ # mod x86 {
81
+ const C: i32 = 1234;
82
+ global_asm!(
83
+ ".global bar",
84
+ "bar: .word {c}",
85
+ c = const C,
86
+ );
87
+ # }
88
+ ```
89
+
90
+ The syntax for passing operands is the same as ` asm! ` except that only
91
+ ` const ` operands are allowed. Refer to the [ asm] ( asm.md ) documentation
92
+ for more details.
93
+
94
+ On x86, the assembly code will use intel syntax by default. You can
95
+ override this by adding ` options(att_syntax) ` at the end of the macro
96
+ arguments list:
97
+
98
+ ``` rust,no_run
99
+ #![feature(global_asm)]
100
+ # #[cfg(any(target_arch="x86", target_arch="x86_64"))]
101
+ # mod x86 {
102
+ global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
103
+ // is equivalent to
104
+ global_asm!("mov ecx, {}", const 5);
105
+ # }
106
+ ```
74
107
75
108
------------------------
76
109
0 commit comments