Summary

This RFC exposes LLVM's support for module-level inline assembly by adding

たす
a global_asm! macro. The syntax
文法
is very simple: it just takes
とる
a string literal containing
含む
the assembly code.

Example:

#![allow(unused)] fn main() { global_asm!(r#" .globl my_asm_func my_asm_func: ret "#); extern { fn my_asm_func(); } }

Motivation

There are two main use cases for this feature. The first is that it allows

許可する、可能にする
functions to be written completely in assembly, which mostly eliminates the need for a naked attribute. This is mainly useful for function that use a custom calling
呼び出し
convention, such as interrupt handlers.

Another important use case is that it allows

許可する、可能にする
external assembly files to be used in a Rust module without needing hacks in the build system:

#![allow(unused)] fn main() { global_asm!(include_str!("my_asm_file.s")); }

Assembly files can also be preprocessed or generated

生成する
by build.rs (for example using the C preprocessor), which will produce
産出する
output files in the Cargo output directory:

#![allow(unused)] fn main() { global_asm!(include_str!(concat!(env!("OUT_DIR"), "/preprocessed_asm.s"))); }

Detailed design
設計(する)

See description above, not much to add. The macro will map directly

直接
to LLVM's module asm.

Drawbacks

Like asm!, this feature depends on LLVM's integrated

統合された
assembler.

Alternatives

The current way of including external assembly is to compile the assembly files using gcc in build.rs and link them into the Rust program as a static

静的な
library.

An alternative

代わりのもの、選択肢
for functions written entirely in assembly is to add a #[naked] function attribute.

Unresolved questions

None