In C + +, due to the existence of overloading and other technologies, the compiler to the function, struct, class, and so on to the linker, it can not be as simple as the C language through the function name, it needs to provide additional parameter information, but also with the C language to share the linker, which requires a name adaptation (name mangling), also called name retouching (name decoration).
Name adaptation, but for historical reasons, C + + does not have this standard (C + + does not have ABI standards, name adaptation is only part of the ABI problem). So the compilers are fragmented and the resulting files are not generic.
So: Under Windows, you will find that the same version of QtCore4.dll, different compilers compiled by the cannot be common. The same function void F (std::wstring s), the same compiler (MSVC), different options (/zc:wchar_t- or /zc:wchar_t), the exported symbols are different.
In Qt, we only focus on the following two types of name adaptations:
- Itanium C + + ABI (GCC3, GCC4, including MinGW)
- Microsoft C + + ABI
Note: For Intel compilers, it is consistent with the Microsoft ABI under Windows, and in other platforms, with GCC.
Use examples to speak
What's an example? The amount ... Find a simple dynamic library and see the name of the function it derives from. QT's core and GUI modules are too complex, take the QT test module to see it, QtTest4.dll or libqttest.so.4.8.0
How do you see the symbols?
- Under Windows, we can use the DUMPBIN tool:
Dumpbin/exports Qttest4.dll
- On Linux, we can use NM or readelf tools:
nm-d libqttest.so.4.8.0readelf-ws libqttest.so.4.8.0
Ready to work, you run the above command, you can see a lot of symbols appear on the screen, we compare the functions given by QT Manual, look at these symbols (only a few, otherwise I can not understand)
Put a line too long, have to do this, prototype/itanium/microsoft |
1 |
void Qtest::qsleep (int ms) |
Prototype |
_zn5qtest6qsleepei |
Itanium ABI |
[Email Protected]@@[email protected] |
Microsoft ABI |
2 |
const char * qtest::currenttestfunction () |
|
_zn5qtest19currenttestfunctionev |
|
[Email protected]@ @YAPBDXZ |
|
3 |
int qtest::qexec (qobject *testobject, int argc=0, char **argv=0) |
|
_zn5qtest5qexecep7qobjectippc |
|
[Email protected]@@[email protected]@[email protected] |
|
4 |
int qtest::qexec (qobject *testobject, const qstringlist &arguments) |
|
_zn5qtest5qexecep7qobjectrk11qstringlist |
|
[Email protected]@@[email protected]@[email protected]@@z |
|
5 |
Qtestdata & Qtest::newrow (const char * datatag) |
|
_zn5qtest6newrowepkc |
|
[Email protected]@@[email protected]@[email protected] |
|
6 |
... |
|
... |
|
... |
|
This pile of things, a mess, how to see Ah??
Try to read and read.
void Qtest::qsleep (int ms) |
Prototype |
_zn5qtest6qsleepei |
Itanium ABI |
[Email Protected]@@[email protected] |
Microsoft ABI |
Itanium
_zn5qtest6qsleepei
Add a few spaces
_z N 5 qtest 6 Qsleep E I
_z |
|
C + + name prefixes |
N... E |
Compound name start character Qtest::qsleep |
|
|
5 Qtest |
Name of length 5 qtest |
|
6 Qsleep |
Name of length 6 qsleep |
I |
|
Parameter type int |
Microsoft
[Email Protected]@@[email protected]
This information is a bit more, a little messy, far worse than the previous style. And a lot of outdated things are mixed up in them.
? |
C + + name prefixes |
Qsleep |
The name of the inner layer |
@ |
Name Separator |
Qtest |
The outer name of the previous name |
@@ |
End of name |
Y |
Function call is near mode |
A |
Call Convention __cdecl |
X |
return value type void |
H |
Parameter type int |
@ |
End of parameter table |
Z |
Indicates that this is a function |
For explanations of these things, see calling_conventions
Reference
Http://www.agner.org/optimize/calling_conventions.pdf
Http://en.wikipedia.org/wiki/Name_mangling
Http://stackoverflow.com/questions/4667266/c-name-mangling-by-hand
http://labs.qt.nokia.com/2009/08/12/some-thoughts-on-binary-compatibility/
Http://developer.qt.nokia.com/wiki/toStdWStringAndBuiltInWchar_SimplifiedChinese
http://blog.csdn.net/dbzhang800/article/details/6707051
C + + ABI name change, compiler generation symbol study (QT for example)