tags:

views:

1128

answers:

5

Hello all,

I'm quiet familiar with gcc assembly... Recently I was forced to turn back to g++ for some codes clean up. Let me mention I'm too much familiar with assembly, hence, for some curiosity purposes, I often get a look at how good the compiler generated asm is.

But the naming conventions with g++ are just bizaare. I was wondering is there any guidline on how to read its asm output ?

Thanks too much,

+5  A: 

If you're looking at the naming convention for external symbols then this will follow the name mangling convention of the platform that you are using. It can be reversed with the c++filt program which will give you the human readable version of C++ function names, although they will (in all probability) no longer be valid linker symbols.

If you're just looking at local function labels, then you're out of luck. g++'s assembler output is for talking to the assembler and not really designed for ease of human comprehension. It's going to generate a set of relatively meaningless labels.

Charles Bailey
+7  A: 

From man g++:

-fverbose-asm
Put extra commentary information in the generated assembly code to make it more readable. This option is generally only of use to those who actually need to read the generated assembly code (perhaps while debugging the compiler itself).

Eliseo Ocampos
Dislamer: not as 'verbose' as you think.
LiraNuna
LiraNuna is right. It doesn't make it more readable, to me at least. It doesn't demangle labels for you, which is what the OP seems to want.
strager
+7  A: 

I don't find g++'s asm 'ugly' or hard to understand, though I've been working with GCC for over 8 years now.

On Linux, function labels usually go by _ZN, The "_ZN" prefix being a token that designates C++ name mangling (as opposed to C), followed by namespace the function belongs, then function names and argument types, then templates, if any.

Example:

    // tests::vec4::testEquality()
    _ZN5tests4vec412testEqualityEv

    _ZN - C++ mangling, 'N' for member (_ZZ for const or others)
    5tests - length (5 chars) + name
    4vec4 -length (4 chars) + sub namespace
    12testEquality - length (12 chars) + function name
    Ev - void argument (none)
LiraNuna
Based on your example, I have to agree with Sam, that's ugly! They call it name "Mangling" for a reason! Although, you did provide the best answer so far.
NoMoreZealots
I think "ID" in your example is the length of the next argument. _ZN, 5 "tests", 4 "vec4", 12 "testEquality", E, v.
strager
@Pete, if you think that's ugly, look at MSVC's C++ mangling...
LiraNuna
A: 

If the code has debugging information, objdump can provide a more helpful disassembly :

-S, --source             Intermix source code with disassembly
-l, --line-numbers             Include line numbers and filenames in output
Bastien Léonard
A: 

g++ generated symbols or asm are not for human being.

EffoStaff Effo