Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:rustc

From ReverseEngineering.wiki
Tool
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 example rustc version 1.xx.y (<short commit> <date>)); LLVM writes it into the ELF .comment section, so search .comment for rustc version . On wasm the version appears in the producers custom 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 strip does not delete sections itself: for strip=symbols/debuginfo it passes --strip-all or --strip-debug to the linker (rustc_codegen_ssa/src/back/linker.rs), and GNU ld and LLD --strip-all drop symbol tables and debug sections, not .comment. Unverified by test: confirm on a real strip = true build with readelf -p .comment; an external strip --remove-section=.comment would remove it.
  • Panic location strings. Every panic, unwrap, expect, bounds and arithmetic check passes a pointer to a static core::panic::Location (the source declares filename: NonNull<str> (pointer and length), line: u32, col: u32, no repr attribute, 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 (and library/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 a None value", "called Result::unwrap() on an Err value", "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 prints thread '<name>' panicked at <file>:<line>:<col>: and then the message, and the note "run with RUST_BACKTRACE=1 environment 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 u64 u64::from_ne_bytes(*b"MOZ\0RUST"), which is 0x54535552005A4F4D on little-endian targets; bytes in memory 4D 4F 5A 00 52 55 53 54), raised with _Unwind_RaiseException, and the personality routine rust_eh_personality reads the standard LSDA (Platform:Itanium C++ ABI/LSDA). Windows MSVC targets use SEH instead. panic=abort builds have no landing pads and no personality.
  • Entry. The C main calls std::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_name strings. A vtable is an array of pointer-sized words that starts with three common entries: slot 0 drop_in_place (function pointer, or null when the type needs no drop), slot 1 size (size_of the concrete type), slot 2 align; the trait's methods follow from slot 3, supertrait methods included (rustc_middle/src/ty/vtable.rs: COMMON_VTABLE_ENTRIES = [MetadataDropInPlace, MetadataSize, MetadataAlign], indexes COMMON_VTABLE_ENTRIES_DROPINPLACE/SIZE/ALIGN = 0, 1, 2; allocation built in vtable_allocation_provider with entry count times pointer size). Method order and upcasting pointers for supertraits are compiler-internal and can change between releases. A &dyn Trait is (data pointer, vtable pointer);
  • Strings are (pointer, length) pairs without NUL and are merged into large .rodata blobs, 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.ident rustc version {CFG_VERSION}), library/core/src/panic/location.rs (Location), library/core/src/panicking.rs lines 188-197 and 271, library/core/src/option.rs 2253, library/core/src/result.rs 1232, library/std/src/panicking.rs 270 and 295, library/panic_unwind/src/gcc.rs 111 (MOZ\0RUST), library/std/src/sys/personality/gcc.rs 105 (rust_eh_personality).
  • rustc-dev-guide src/backend/libs-and-metadata.md (rlib, dylib .rustc, rmeta).