我有一个“大”的问题。 我目前正在尝试在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
VBScript中对象的破坏顺序是什么?
我怎样才能find一个全局variables的析构函数调用使用gdb?
为什么不能在析构函数中closures串口?
_Exit如何在C ++程序中运行?
在Linux上,为什么析构函数在C ++的全局variables的共享实例上运行两次?
在程序结束时,类的静态实例不能正确处理资源删除
为什么在类对象数组上调用delete而不是delete 会导致堆损坏?
gcc好像有了一些变化。 ctor和dtor列表已被init_array和fini_array所取代。
我不是很确定这是否是发生在你身上,但是当我看到objdumps(析构函数,构造函数属性声明的程序)和(没有它们的程序)之间的差异时,主要突出显示的部分是.init_array和.fini_array
这可能是指https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
我不知道如何从列表中获得函数的地址,但希望你可以从这里拿走它。
他们(在海湾合作委员会的bugzilla)所提到的一个简单的例子可能会帮助你。
#include <stdio.h> static void init () { printf ("init_arrayn"); } static void (*const init_array []) () __attribute__ ((section (".init_array"),aligned (sizeof (void *)))) = { init }; static void fini () { printf ("fini_arrayn"); } static void (*const fini_array []) () __attribute__ ((section (".fini_array"),aligned (sizeof (void *)))) = { fini }; static void ctor () { printf ("ctorn"); } static void (*const ctors []) () __attribute__ ((section (".ctors"),aligned (sizeof (void *)))) = { ctor }; static void dtor () { printf ("dtorn"); } static void (*const dtors []) () __attribute__ ((section (".dtors"),aligned (sizeof (void *)))) = { dtor }; int main () { printf ("mainn"); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。