We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Rust Before Main - Ryan Levick - Rust Linz, July 2022
Explore the internal workings of the Rust programming language and discover how it's compiled to machine code, utilizing concepts like ELF file format, dynamic linking, and object files.
- Rust’s Compilation Model: Rust is compiled to machine code using the Rust compiler, which is the first step in understanding how Rust works.
- ELF File Format: ELF stands for Executable and Linkable Format, a file format that contains executable and linkable files.
- Dynamic Linking: Dynamic linking is a way to load object files into memory at runtime, allowing programs to share libraries.
- Dynamic Loader: The dynamic loader is responsible for loading object files into memory and resolving symbols.
-
call __libc_start_main: Before reaching the main function, the program calls
__libc_start_main
which sets up the program’s stack and initializes the C standard library. - Main Function: The main function is where program execution begins, and is called by the dynamic loader after setup is complete.
- libc: The C standard library (libc) provides functionality to the program, such as input/output operations.
- Object Files: Object files are compiled from Rust source code and contain machine code.
- Optimization: Optimization levels (e.g. debug, release) can affect the size and performance of the program.
- Compilation: Rust code is compiled to machine code using the Rust compiler.
- Binary Executable: A binary executable is a file that contains machine code and can be executed directly by the computer.
- Executable and Linkable Format (ELF): ELF is a file format for executable and linkable files, containing executable and linkable code.
- Dynamic Linker: The dynamic linker is responsible for loading object files into memory and resolving symbols.
- Dynamic Dependencies: Dynamic dependencies are libraries that are loaded at runtime, such as libc.
- Object Dump: Object dump is a tool that disassembles the contents of an executable file.
-
readelf:
readelf
is a tool that reads and prints the contents of an executable file. - Runtime: The runtime environment is responsible for managing the program’s state and providing services.
- Panic: Panic is an error handling mechanism that aborts the program or terminates it with an error code.
-
j instruction: The
j
instruction is used to jump to a new location in the program. -
-d
flag: The-d
flag is used withobjdump
to disassemble the contents of an executable file. - LTO (Link-Time Optimization): LTO is a compiler optimization that can reduce the size and improve the performance of the program.