【发布时间】:2015-10-31 19:28:17
【问题描述】:
我有一个“大”问题。 我目前正在尝试在 Linux 上的程序(它是一个虚拟机)中获取我的 dtor 列表的地址。显然有一个析构函数,但是当我使用 nm 并显示所有地址及其名称时,我找不到它;唯一与之相关的是do_global_dtors_aux。此外,当代码运行时,它按预期工作得非常好。 这是我的一段代码:
#include <stdlib.h>
#include <stdio.h>
static void cleanup(void) __attribute__ ((destructor));
int main() {
printf("in the main function...");
exit(0);
}
void cleanup(void){
printf("in the cleanup");
}
这是我使用nm的时候
0000000000600808 d _DYNAMIC
00000000006009f0 d _GLOBAL_OFFSET_TABLE_
0000000000400678 R _IO_stdin_used
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
00000000004007e0 r __FRAME_END__
0000000000600800 d __JCR_END__
0000000000600800 d __JCR_LIST__
0000000000600a38 D __TMC_END__
0000000000600a38 A __bss_start
0000000000600a28 D __data_start
0000000000400550 t __do_global_dtors_aux
00000000006007f0 t __do_global_dtors_aux_fini_array_entry
0000000000600a30 D __dso_handle
00000000006007e8 t __frame_dummy_init_array_entry
w __gmon_start__
00000000006007f0 t __init_array_end
00000000006007e8 t __init_array_start
00000000004005d0 T __libc_csu_fini
00000000004005e0 T __libc_csu_init
U __libc_start_main@@GLIBC_2.2.5
0000000000600a38 A _edata
0000000000600a40 A _end
000000000040066c T _fini
0000000000400430 T _init
0000000000400490 T _start
00000000004004bc t call_gmon_start
00000000004005b4 t cleanup
0000000000600a38 b completed.6092
0000000000600a28 W data_start
00000000004004e0 t deregister_tm_clones
U exit@@GLIBC_2.2.5
0000000000400570 t frame_dummy
000000000040059c T main
U printf@@GLIBC_2.2.5
U puts@@GLIBC_2.2.5
0000000000400510 t register_tm_clones
【问题讨论】:
-
在
printf()格式字符串的末尾包含一个换行符是个好主意。或者,对于简单的“输出字符串”调用,请改用puts()。 -
我在文档 (gcc.gnu.org/onlinedocs/gccint/Initialization.html) 中没有看到它声明
__DTOR_LIST__将是可执行文件中的实际符号。 -
您也许可以使用可移植的 'atexit()' 函数作为 'attribute ((destructor));'不便携。
-
我明白了,但这里的问题是要知道 .dtor 在哪里,并且显然它已经消失了....但是谢谢您提供的信息,接下来我将使用 atexit()
标签: c linux destructor nm