How is Rust compiled for machine code?

I recently watched the Rust programming language . How it works? The rust code seems to be compiled into ELF or PE binaries (etc.), but I could not find any information on how this is done? Was it compiled in an intermediate format and then compiled the rest of the path with gxx? Any help (or links) would be really appreciated.

+16
source share
1 answer

The Rust compiler code generation phase is mainly performed by LLVM . LLVM is the compiler toolkit most commonly used by Clang C [++] Compiler clang[++] .

Firstly, the Rust compiler (like clang , for example) does all Rust-specific stuff, such as type checking and borrowing; in the end, it generates LLVM-IR. IR stands for intermediate presentation, and it ... is comparable to an assembly, but a bit higher level and, most importantly, platform independent. Then the Rust compiler simply calls ☏ LLVM and says:

Hey buddy, could you please take this IR and generate machine code for the current platform? That would be fantastic β—• β—‘ β—•

What LLVM answers:

Ure Of course no problem, new friend. Here is your highly optimized machine code for [for example] x86_64 ! β™« β™ͺ β™«

After that, they invite several more friends to wrap all this in a small pretty [for example] ELF package and put it in the user file system. (and the user is like ...)


Such information can be found in the official FAQ, which in any case contains a lot of interesting information. For more information on the Rust compiler, you can read the Rustc Guide . On this issue, the High Level Review chapter is quite interesting.

+46
source

Source: https://habr.com/ru/post/1266675/


All Articles