Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64bit name mangling for c++

I have a bit of code which has the following line

  #pragma comment(linker, "/include:_test@12") 

The project which uses this code works fine when I compile the code using C++ Visual Studio 2010 with configuration type 32bit (I am also on a 32 bit windows machine).

I get a link error when I change the machine to 64bit and use x64 configuration which compiling with C++ Visual Studio 2010.

Is C++ name mangling different for 32bit vs 64bit? If so, where can I find the 64bit C++ name mangling conventions?

like image 561
user1612986 Avatar asked Nov 14 '12 19:11

user1612986


People also ask

Does C have name mangling?

Since C is a programming language that does not support name function overloading, it does no name mangling.

What is code mangling?

Name mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language. Type names may also be mangled. Name mangling is commonly used to facilitate the overloading feature and visibility within different scopes.

How do you know if your name is mangling?

linux gnu tool chain nm command can be used to see mangled name.

What is mean by name mangling naming decoration?

In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages.


1 Answers

Yes the name mangling is different between 32 and 64 bit. A reasonable article covering the exact formats can be found here. You can tell the major differences pretty quickly, however, by simply compiling to both targets and examining the resulting map files. From my experience they're almost identical (64bit adds a small datum, potentially changes others).

Simple sample: void foo();

32bit: ?foo@A@@QAEXXZ
64bit: ?foo@A@@QEAAXXZ

For non-mangled std call, the length suffix can be substantially different, depending on the parameter stack usage. The default 64-bit settings for VC++ do not prepend underscores nor does it encode length-suffixes. The following was compiled both 32/64bit configs with pure out-of-the-box settings:

extern "C" int _stdcall func2(int, int, char*);

32bit: _func2@12
64bit: func2

Not much point there, is there.

Completing the circuit, unmangled _cdecl, which does this:

extern "C" int _cdecl func2(int, int, char*);

32bit: _func2
64bit: func2

If it seems like they went out of their way to make you know what you're pulling-in or exporting-out, evidence suggests you're probably correct.

like image 142
WhozCraig Avatar answered Oct 12 '22 14:10

WhozCraig