I have overloaded functions like:
void f(int)
void f(int, int)
void f(int, float)
How to compile it, so that i can see the mangled output? Something like:
void f(int) should show: ?f@@YAXH@Z(int)
Like for example, to see pre-processor output we use -E
, assembler output -s
, what is it for name mangled output?
P.S: Platform is Linux
EDIT:
And by the answers here we go:
void func(int);
void func(int, int);
void func(void);
void func(char);
[root@localhost ~]# cat a.map | grep func
0x0804881a _Z4funcc
0x08048790 _Z4funcv
0x080487be _Z4funcii
0x080487ec _Z4funci
Since C is a programming language that does not support name function overloading, it does no name mangling.
The need for name mangling arises where the language allows different entities to be named with the same identifier as long as they occupy a different namespace (typically defined by a module, class, or explicit namespace directive) or have different signatures (such as in function overloading).
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.
For GCC try using:
-Xlinker -Map=output.map
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
This will generate a map file which will have all of the mangled symbol names.
And for MSVC:
http://msdn.microsoft.com/en-us/library/k7xkk3e2(v=vs.80).aspx
This will generate something such as:
0002:00094190 ??0SerializationException@EM@@QAE@ABV01@@Z 10148190 f i y:foo.obj
In Linux, I can see the names of all symbols via nm
. For example:
$ nm a.out | grep pthread
w pthread_cancel@@GLIBC_2.2.5
U pthread_key_create@@GLIBC_2.2.5
U pthread_key_delete@@GLIBC_2.2.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With