8

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
1
  • 2
    Call the functions without implementing them, the linker will be kind enough to tell you the mangled name in the error message. :) Jun 25, 2013 at 16:20

3 Answers 3

10

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
2
  • Great answer. Yours and chrisaycock both serve the purpose, but since i asked from the gcc perspective, so yours is the one i should choose. Thanks :-)
    – RajSanpui
    Jun 25, 2013 at 16:34
  • @kingsmasher1 I'm curious as to why mine doesn't "serve the purpose".
    – user529758
    Jun 25, 2013 at 16:48
5

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
3

The -S option tells GCC to only compile but not assemble a function. I. e., it will output human-readable assembly text, in which you'll be able to see the function names. Run it through c++filt so that you can associate the mangled names with the unmangled ones.

2
  • Once you've got the assembler, c++filt myProg.s | diff - myProg.s should give the information you need. Jun 25, 2013 at 16:27
  • Your answer serves the purpose too, and thanks for letting us know an alternate way to achieve the same goal, but i can accept only 1 answer at a time (unfortunately), and since i asked the question from gcc perspective, so the other one was a closer match.
    – RajSanpui
    Jun 25, 2013 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.