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
RajSanpui
  • 11,556
  • 32
  • 79
  • 146
  • 2
    Call the functions without implementing them, the linker will be kind enough to tell you the mangled name in the error message. :) – Luchian Grigore Jun 25 '13 at 16:20

4 Answers4

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
paulm
  • 5,629
  • 7
  • 47
  • 70
  • 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 '13 at 16:34
  • @kingsmasher1 I'm curious as to why mine doesn't "serve the purpose". –  Jun 25 '13 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
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
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.

  • Once you've got the assembler, `c++filt myProg.s | diff - myProg.s` should give the information you need. – James Kanze Jun 25 '13 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 '13 at 17:15
0

There should be some options in your compiler/linker to create a map file. Within that file you can see the mangled names of all functions and methods.

Philip Stuyck
  • 7,344
  • 3
  • 28
  • 39
  • It is compiler specific. I may have said should, but I meant that there really are switches like that. Like eventually was indicated by the answer of paulm. A mapfile is really the way to go. – Philip Stuyck Jun 25 '13 at 19:26
  • Yes, what I meant is that the asker already said which is its compiler (gcc). Your answer is not incorrect in itself, but wrt to the question, it is not an real answer to that. Hope you understand what I mean; your post should have been a comment instead :) – Sebastian Mach Jun 25 '13 at 20:13