C++ class function in assembly
Asked Answered
B

4

1

Hello Community I am look at C++ assembly, I have compiled a benchmark from the PARSEC suite and I am having difficulty knowing how do they name the class attribute functions in assembly language. for example if I have a class with some functions to manipulate it, in cpp we call them like test.increment(); After some investigation I found out that this function is

atomic_load_acq_ptr

represented as:

_ZL19atomic_load_acq_intPVj

in assembly, or at least this is what I have found out.

Let me know if I am wrong! Is there some fixed rule for the mapping? or are they random? Thanks

Braunstein answered 7/2, 2011 at 11:13 Comment(0)
A
6

It's called name mangling, is necessary because of overloads and templates and such (i.e. the plain chars-and-numbers name isn't enough to identify a chunk of code unambiguously; embedding spaces or <> or :: in names usually isn't legal; copying the additional information in uncondensed, human-readable form would be wasteful), and it therefore depends on types, arity, etc.

The exact scheme can vary, but usually each compiler is self-consistent for a relatively long time (sometimes even several compilers can settle for one way).

Ark answered 7/2, 2011 at 11:17 Comment(1)
BTW, the exact rule of OP's scheme can be found in codesourcery.com/public/cxx-abi/abi.html#mangling.Want
H
2

That's called name mangling.. It is compiler dependant. No standard way, sorry :)

Hotel answered 7/2, 2011 at 11:18 Comment(1)
It may not be the C++ standard but some platforms do have a standard ABI. The then ensures that different compilers create binary compatible code. For instance the ARM EABI is well defined.Cortege
C
2

C++ allows function overloading, this means that one can have two functions with the same name but different parameters. Since your binary formats do not understand type this is a proble. The way that this is worked around is to use a scheme called name mangling. This adds a whole function of type information to the name used in the source file and ensures one calls the correct overload.

The extra letters etc that are added are governed by the particular Application Binary Interface (ABI) being used. Different compilers (and sometimes even different versions) may use different ABIs.

Cortege answered 7/2, 2011 at 11:22 Comment(0)
H
0

Yes there's a standard method for creating these symbols known as name mangling.

Henequen answered 7/2, 2011 at 11:20 Comment(1)
"The C++ language does not define a standard decoration scheme, so each compiler uses its own."Normy

© 2022 - 2024 — McMap. All rights reserved.