测试在 x86、32 位 Linux 上进行。我正在使用g++
4.6.3 和objdump
2.22
这是我正在处理的一个简单的 C++ 代码:
#include <iostream>
using namespace std;
main()
{
cout << "Hello World!" << endl;
return 0;
}
当我使用以下命令将其编译为汇编代码时:
gcc -S hello.cc
我可以ctors
在下面的hello.s中找到一个部分:
.section .ctors,"aw",@progbits
.align 4
.long _GLOBAL__sub_I_main
.weakref _ZL20__gthrw_pthread_oncePiPFvvE,pthread_once
.weakref _ZL27__gthrw_pthread_getspecificj,pthread_getspecific
.weakref _ZL27__gthrw_pthread_setspecificjPKv,pthread_setspecific
.weakref _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_,pthread_create
.weakref _ZL20__gthrw_pthread_joinmPPv,pthread_join
.weakref _ZL21__gthrw_pthread_equalmm,pthread_equal
.weakref _ZL20__gthrw_pthread_selfv,pthread_self
.weakref _ZL22__gthrw_pthread_detachm,pthread_detach
.weakref _ZL22__gthrw_pthread_cancelm,pthread_cancel
.weakref _ZL19__gthrw_sched_yieldv,sched_yield
.weakref _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t,pthread_mutex_lock
.weakref _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t,pthread_mutex_trylock
.weakref _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec,pthread_mutex_timedlock
.weakref _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t,pthread_mutex_unlock
.weakref _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t,pthread_mutex_init
.weakref _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t,pthread_mutex_destroy
.weakref _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t,pthread_cond_broadcast
.weakref _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t,pthread_cond_signal
.weakref _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t,pthread_cond_wait
.weakref _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec,pthread_cond_timedwait
.weakref _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t,pthread_cond_destroy
.weakref _ZL26__gthrw_pthread_key_createPjPFvPvE,pthread_key_create
.weakref _ZL26__gthrw_pthread_key_deletej,pthread_key_delete
.weakref _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t,pthread_mutexattr_init
.weakref _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti,pthread_mutexattr_settype
.weakref _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t,pthread_mutexattr_destroy
但是,当我组装 asm 代码时,生成一个 exe 文件并使用objdump
生成该ctors
部分的包含如下所示:
objdump -Dr -j .ctors hellocpp
我所能得到的就是这样:
hellocpp: file format elf32-i386
Disassembly of section .ctors:
08049efc <__CTOR_LIST__>:
8049efc: ff (bad)
8049efd: ff (bad)
8049efe: ff (bad)
8049eff: ff 00 incl (%eax)
08049f00 <__CTOR_END__>:
8049f00: 00 00 add %al,(%eax)
...
目前我正在尝试恢复一些从c++
程序编译的 ELF 二进制文件的内容..
所以我想知道是否有办法让内容ctors
等于g++
产生的内容?
更新:
非常感谢@Igor 的帮助。但我仍然被困在 从 ELF 二进制文件中寻找class's
constructor
和destructor
信息。
在演化class
定义时,g++ 会在该.ctors
部分生成这些信息:
.globl _ZN8ComputerC1Ev
.set _ZN8ComputerC1Ev,_ZN8ComputerC2Ev
.globl _ZN8ComputerD1Ev
.set _ZN8ComputerD1Ev,_ZN8ComputerD2Ev
通常_ZN8ComputerC2Ev
是类的构造函数的名称,而_ZN8ComputerD2Ev
是其析构函数的名称。
但是,我只是在objdump
转储.ctors
或.init_array
部分中找不到相应的信息..我也试过.eh_frame
and gcc_except_table
,但转储的信息海量..我无法弄清楚这些信息的含义..
有人可以给我指导吗?