Tool:rustc
| Developer | The Rust Project |
|---|---|
| License | MIT OR Apache-2.0 |
| Website | https://www.rust-lang.org |
| On this wiki | Facts · Code · Notes · Topics |
The Rust compiler. Rust executables are recognised by their rustc version string, panic messages with source paths, core/alloc/std symbol names in _ZN...17h<16 hex>E or _R mangling, and the MOZ\0RUST exception class.
Overview
rustc compiles through LLVM, so Rust binaries are native code in the platform's normal container (Format:ELF (Executable and Linkable Format), PE, Mach-O) with no Rust-specific header. They are recognised from strings and symbol names, and even a stripped Rust binary keeps many strings (panic messages and source paths).
Recognising a Rust binary
- Producer string. rustc adds the LLVM named metadata
llvm.ident=rustc version <CFG_VERSION>(for examplerustc version 1.xx.y (<short commit> <date>)); LLVM writes it into the ELF.commentsection, so search.commentforrustc version. On wasm the version appears in theproducerscustom section (Format:WebAssembly binary format). The source (rustc_codegen_llvm/src/context.rs) inserts this metadata unconditionally for every module, so every non-stripped object and executable has it. rustc's-C stripdoes not delete sections itself: forstrip=symbols/debuginfoit passes--strip-allor--strip-debugto the linker (rustc_codegen_ssa/src/back/linker.rs), and GNU ld and LLD--strip-alldrop symbol tables and debug sections, not.comment. Unverified by test: confirm on a realstrip = truebuild withreadelf -p .comment; an externalstrip --remove-section=.commentwould remove it. - Panic location strings. Every panic, unwrap, expect, bounds and arithmetic check passes a pointer to a static
core::panic::Location(the source declaresfilename: NonNull<str>(pointer and length),line: u32,col: u32, noreprattribute, so 24 bytes on 64-bit targets and the field order is not guaranteed). The file strings are source paths: the standard library appears as/rustc/<40-hex commit>/library/core/src/option.rs(andlibrary/alloc/src/...,library/std/src/...), dependencies as<cargo home>/registry/src/index.crates.io-<hash>/<crate>-<version>/src/lib.rs. They give the rustc commit (hence version) and the crate names with their versions: a software inventory of the binary. Unverified: the/rustc/<commit>/prefix comes from official toolchains remapping their source root; a self-built toolchain shows its own build path. - Panic message strings are stored without NUL terminator among other strings: "called
Option::unwrap()on aNonevalue", "calledResult::unwrap()on anErrvalue", "attempt to add with overflow" (also subtract, multiply, divide, negate, shift left, shift right), "attempt to divide by zero", "attempt to calculate the remainder with a divisor of zero", "index out of bounds: the len is {len} but the index is {index}" (a format template, filled at run time), "explicit panic". The default panic hook printsthread '<name>' panicked at <file>:<line>:<col>:and then the message, and the note "run withRUST_BACKTRACE=1environment variable to display a backtrace". - Symbols.
rust_eh_personality,rust_begin_unwind,rust_panic,__rust_alloc,__rust_dealloc,__rust_realloc,_ZN4core9panicking5panic17h<hash>E,_ZN3std2rt10lang_start17h<hash>E; see Tool:rustc/Symbol mangling. - Unwinding. Panics use the platform unwinder with exception class
MOZ\0RUST(the u64u64::from_ne_bytes(*b"MOZ\0RUST"), which is 0x54535552005A4F4D on little-endian targets; bytes in memory4D 4F 5A 00 52 55 53 54), raised with_Unwind_RaiseException, and the personality routinerust_eh_personalityreads the standard LSDA (Platform:Itanium C++ ABI/LSDA). Windows MSVC targets use SEH instead.panic=abortbuilds have no landing pads and no personality. - Entry. The C
maincallsstd::rt::lang_start, which sets up the runtime and calls the user's main through a function pointer.
Metadata files
An rlib is an ar archive with a lib.rmeta member and per-codegen-unit object files; a dylib keeps its metadata in a section named .rustc; .rmeta is a custom format tied to the exact compiler version (the compiler refuses files from another version). A finished executable does not carry crate metadata.
Differences from C++ binaries
- No RTTI: trait objects are fat pointers (data pointer, vtable pointer); names exist only in debug info and in
type_namestrings. A vtable is an array of pointer-sized words that starts with three common entries: slot 0drop_in_place(function pointer, or null when the type needs no drop), slot 1size(size_of the concrete type), slot 2align; the trait's methods follow from slot 3, supertrait methods included (rustc_middle/src/ty/vtable.rs:COMMON_VTABLE_ENTRIES = [MetadataDropInPlace, MetadataSize, MetadataAlign], indexesCOMMON_VTABLE_ENTRIES_DROPINPLACE/SIZE/ALIGN= 0, 1, 2; allocation built invtable_allocation_providerwith entry count times pointer size). Method order and upcasting pointers for supertraits are compiler-internal and can change between releases. A&dyn Traitis (data pointer, vtable pointer); - Strings are (pointer, length) pairs without NUL and are merged into large
.rodatablobs, so tools that look for NUL-terminated strings split or miss them. Search for source paths and message text instead. - Heavy monomorphization and inlining: one generic function appears many times with different hash suffixes.
Topics
- Symbol mangling — The Rust symbol-mangling schemes: legacy (_ZN...17h<16 hex>E) and v0 (_R prefix; the default at the 2026 rustc master), with the escape table, base-62…
Code & repositories
- https://github.com/rust-lang/rust @
02fb0a16311c3411fa373627706da085cd8fbd3c· license: Apache-2.0
The Rust compiler and standard library: symbol mangling in compiler/rustc_symbol_mangling, panic machinery in library/core/src/panicking.rs and library/panic_unwind, a compact LSDA parser in library/std/src/sys/personality/dwarf/eh.rs.
Tested on: source read, not run: Read at master 02fb0a16311c (2026-10-17), sparse checkout · checked 2026-10-18; last activity 2026-10-18
Evidence & references
- rust-lang/rust 02fb0a16311c3411fa373627706da085cd8fbd3c:
compiler/rustc_codegen_llvm/src/context.rs(llvm.identrustc version {CFG_VERSION}),library/core/src/panic/location.rs(Location),library/core/src/panicking.rslines 188-197 and 271,library/core/src/option.rs2253,library/core/src/result.rs1232,library/std/src/panicking.rs270 and 295,library/panic_unwind/src/gcc.rs111 (MOZ\0RUST),library/std/src/sys/personality/gcc.rs105 (rust_eh_personality). - rustc-dev-guide
src/backend/libs-and-metadata.md(rlib, dylib.rustc, rmeta).