Suffix of mangled rust name

Hi all,

I am playing with Rust's LLVM backend, from where I find rust's rule of mangled name is rather confusing and remains a myth to me.

I compile libcore/ via rustc --emit=llvm-bc,llvm-ir, from which I see core::fmt::write is mangled to _ZN4core3fmt5write17h34ec53ff1bfcf343E. Later I compile another rust source file via the same command, I get _ZN4core3fmt5write17hed5a9f5780519923E. Looks like these two mangled names have a common prefix, but what are these two different suffixes? Can I have a way to unify them?


The suffix is a hash. I believe there's a rustc-demangle crate for doing exactly this.

I can't answer why the same symbol from libcore would have different hashes across invocations of the compiler, but check out this explanation which covers the role of the hash suffix and various things that factor into it.

Isn't fmt:write monomorphised based on its arguments? It would make sense that the different monomorphised have a different symbol?

core::fmt::write is not monomorphized based on its arguments because there are no generic types parameters or impl trait in its signature.

1 Like

Thank you, I stand corrected! :heart: