Symbol Mangling

Symbol name mangling is used by rustc to encode a unique name for symbols that are used during code generation. The encoded names are used by the linker to associate the name with the thing it refers to.

The method for mangling the names can be controlled with the -C symbol-mangling-version option.

Per-item control

The #[no_mangle] attribute can be used on items to disable name mangling on that item.

The #[export_name]attribute can be used to specify the exact name that will be used for a function or static.

Items listed in an extern block use the identifier of the item without mangling to refer to the item. The #[link_name] attribute can be used to change that name.


The encoded names may need to be decoded in some situations. For example, debuggers and other tooling may need to demangle the name so that it is more readable to the user. Recent versions of gdb and lldb have built-in support for demangling Rust identifiers. In situations where you need to do your own demangling, the rustc-demangle crate can be used to programmatically demangle names. rustfilt is a CLI tool which can demangle names.

An example of running rustfilt:

$ rustfilt _RNvCskwGfYPst2Cb_3foo16example_function

Mangling versions

rustc supports different mangling versions which encode the names in different ways. The legacy version (which is currently the default) is not described here. The "v0" mangling scheme addresses several limitations of the legacy format, and is described in the v0 Symbol Format chapter.