Read C++ name mangling

Ever wondering what’s the meaning of xyz@?$abc@V?$def@H@@PAX@@ when getting linking error? Not again, because now you can read it easily only by finishing this!

First, what is it?
Compiler need to pass information to linker so linker able to link object code correctly, but linker and compiler have to talk with one language. That’s how this C++ name mangling invented, bad news is there is no standard of this name mangling (Right! Microsoft has its own mangling scheme). What we know about visual C++ name mangling is only based on reverse engineer because Microsoft doesn’t release any documentation about it.

How to read it ?
You can read this article for complete table and scheme “reverse engineered” specification, but I will introduce you to the basic principle.
1. Read it in reversed order
2. It has structure :
a. Prefix ?
b. Optional prefix : @
c. Qualified name
d. Type of information
3. Look scheme documentation

Example :

void __cdecl abc<def<int>,void*>::xyz(void)

It will become :

xyz@?$abc@V?$def@H@@PAX@@

How Come?

1. abc<def<int>,void*>::xyz
2. xyz@ abc<def<int>,void*> @
3. xyz@ ?$abc@ def<int> void* @ @
4. xyz@ ?$abc@ V def<int> @ PAX @ @
5. xyz@ ?$abc@ V ?$def@H@ @ PAX @ @
6. xyz@?$abc@V?$def@H@@PAX@@

But that’s too complicated and not practical!
Yes, I know. Let’s find another way, there is always another way to Rome right?
In your visual c++ toolkit directory you can find undname, use it to translate this unhuman text to readable and friendlier text.

Wanna do some research, create parser for this languange?
This is good starting point for you, basically I just rewrite information from this sources :
1. http://www.kegel.com/mangle.html
2. http://en.wikipedia.org/wiki/Visual_C%2B%2B_name_mangling
3. http://sourceforge.net/projects/php-ms-demangle/
4. https://msdn.microsoft.com/en-us/library/5x49w699.aspx

2 thoughts on “Read C++ name mangling

  1. YarrPattern.obj : error LNK2019: unresolved external symbol “struct JSC::Yarr::C
    haracterClass * __cdecl JSC::Yarr::nonwordcharCreate(void)” (?nonwordcharCreate@
    Yarr@JSC@@YAPEAUCharacterClass@12@XZ) referenced in function “public: struct JSC
    ::Yarr::CharacterClass * __cdecl JSC::Yarr::YarrPattern::nonwordcharCharacterCla
    ss(void)” (?nonwordcharCharacterClass@YarrPattern@Yarr@JSC@@QEAAPEAUCharacterCla
    ss@23@XZ

    Kalau beginian ini maunya apa dia?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s