Tool:Rustc/Symbol mangling
Topic page of Tool:Rustc. 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 numbers, basic type letters and the hashed variant.
Release: RELEASES.md of rust-lang/rust lists 'Rust will use the v0 symbol mangling scheme by default' (pull request 151994) under the Compatibility Notes of Version 1.97.0 (2026-07-09); Session::get_symbol_mangling_version in rustc_session/src/config.rs returns V0 when -C symbol-mangling-version is unset (master 33295d73). Binaries built with rustc before 1.97 default to legacy _ZN...17h<hash>E names, unless they passed -C symbol-mangling-version=v0 (stabilised in 1.59 as opt-in); the standard library shipped with a toolchain is whatever that toolchain's build used.
Which scheme
Legacy was the default for years; at the 2026 master (02fb0a16311c) get_symbol_mangling_version returns V0 unless -C symbol-mangling-version says otherwise (compiler/rustc_session/src/config.rs line 1578). Unverified: the release that switched; older toolchains and many existing binaries are legacy. Both occur in the wild, even in one binary (prebuilt std is not rebuilt).
Legacy scheme
Looks like Itanium C++ (_ZN nested name) so GNU tools demangle it: _ZN + each path component as <decimal length><text> + a last component 17h<16 lowercase hex digits> + E. Example: _ZN4core9panicking5panic17h0123456789abcdefE is core::panicking::panic. The h... component is a 64-bit hash of the item's def-path hash, its type with regions erased, the function signature, the generic arguments, the instantiating crate (generic items) and the shim kind, so equal paths with different monomorphizations differ only in the hash. The hash does not contain a version string and cannot be reversed; recover names from the path part. rustc-demangle, llvm-cxxfilt and recent binutils print it as ::h0123....
Escapes inside a component: @ $SP$, * $BP$, & $RF$, < $LT$, > $GT$, ( $LP$, ) $RP$, , $C$, - and : become . (so :: inside a component is ..), any other non-identifier character becomes $u<hex>$ (a space is $u20$, so <impl Foo for Bar> becomes _$LT$impl$u20$Foo$u20$for$u20$Bar$GT$; a component starting with a non-identifier character gets a leading _). Special instances end with a pseudo-component: {{closure}}, {{vtable-shim}}, {{reify-shim}}, {{drop-shim}}, {{tls-shim}}, written with the same escapes ($u7b$$u7b$closure$u7d$$u7d$). Several closures of one function therefore differ only in their hash.
v0 scheme
Prefix _R, then a path, optionally an instantiating crate and a vendor suffix introduced by . or $:
C <ident>: crate root; the identifier may be preceded by a disambiguators<base62>_(Cs1234_7mycrate).N <ns> <path> <ident>: nested path; namespacevvalue (function, static),ttype,Cclosure,Sshim; other uppercase letters special, lowercase implementation-internal. Example_RNvNtNtCs1234_7mycrate3foo3bar3baz=mycrate::foo::bar::baz.M <impl-path> <type>inherent impl;X <impl-path> <type> <trait path>trait impl;Y <type> <trait path>trait definition.I <path> <args> E: generic arguments (types,L<base62>lifetimes,K<const>).- Identifiers:
<decimal length>[_]<bytes>; the_separator is present if the text starts with a digit or_; aubefore the length means Punycode. B <base62>: back-reference to an earlier byte offset in the symbol (compression).- Base-62 numbers use
0-9a-zA-Zand end with_; a bare_is 0, otherwise the value plus one.
Basic types: a=i8, b=bool, c=char, d=f64, e=str, f=f32, h=u8, i=isize, j=usize, l=i32, m=u32, n=i128, o=u128, s=i16, t=u16, u=(), v=variadic, x=i64, y=u64, z=!, p=placeholder. Compound: A array, S slice, T..E tuple, R/Q &/&mut, P/O *const/*mut, F fn pointer, D dyn Trait.
Examples (RFC 2603): _RINvNtC3std3mem8align_ofjE = std::mem::align_of::<usize>; _RNvXmNtC7mycrate3Foo3foo = <u32 as mycrate::Foo>::foo; _RNvMINtC7mycrate3FoomE3foo = <mycrate::Foo<u32>>::foo.
At the 2026 master, standard-library-internal functions that used fixed names (__rust_alloc, ...) can be generated as v0 paths in a crate named __rustc whose disambiguator hashes the rustc version, so they look like _RNvCs<base62>_7___rustc<len>__rust_alloc (v0.rs lines 141-175). Unverified: the first release that emits them.
Hashed variant
The hashed mode produces _RNxC<len><crate name><len>H<base62 digits> (base 62 with the final _ dropped; hashed.rs lines 25-45): the item path is not recoverable.
Use in reverse engineering
- Demangle every
_ZN...17hand_Rsymbol and ignore the hash; for stripped files the panic strings of Tool:rustc name the source file of the caller. - The same generic function instantiated for different types gives near-identical functions; compare size and callees to tell them apart.
Evidence & references
- rust-lang/rust 02fb0a16311c3411fa373627706da085cd8fbd3c
compiler/rustc_symbol_mangling/src/legacy.rslines 87-116 (shim suffixes), 122-175 (hash inputs), 198-215 (_ZN,17h,E), 531-550 (escape table);v0.rslines 38, 141-175, 492-517 (basic types), 561-650 (type codes);hashed.rslines 25-45;lib.rslines 329-356. - RFC 2603 (rust-lang/rfcs
text/2603-rust-symbol-name-mangling-v0.md).