I wrote a simple C++ program with which defined a class like below:
#include <iostream>
using namespace std;
class Computer
{
public:
Computer();
~Computer();
};
Computer::Computer()
{
}
Computer::~Computer()
{
}
int main()
{
Computer compute;
return 0;
}
When I use g++
(Test is on x86 32bit Linux with g++ 4.6.3.) to produce the ctors
and dtors
, I get these definitions at the end of section .ctors
.
.globl _ZN8ComputerC1Ev
.set _ZN8ComputerC1Ev,_ZN8ComputerC2Ev
.globl _ZN8ComputerD1Ev
.set _ZN8ComputerD1Ev,_ZN8ComputerD2Ev
After digging into the assembly code produced, I figured out that _ZN8ComputerC1Ev
should be the function name which is used when class Computer
is constructed, while _ZN8ComputerC2Ev
is the name of class Computer
's constructor. The same thing happens in Computer
's destructor declaring and invoking.
It seems that a table is built, linking the constructor and its implementation.
So my questions are:
What actually is this constructor/destructor information for?
Where can I find them in
ELF
format?
I dumped related .ctors
and .init_array
section, but I just can not find the meta data that defined the relation between _ZN8ComputerC1Ev
and _ZN8ComputerC2Ev
...