???C++????????????????????????
???????????? ???????[ 2013/1/31 11:17:11 ] ????????
ldscript
/* Script for ld --enable-auto-import: Like the default script except
read only data is placed into .data */
SECTIONS
{
/* Make the virtual address and file offset synced if the
alignment is lower than the target page size. */
. = SIZEOF_HEADERS;
. = ALIGN(__section_alignment__);
.text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
{
*(.init)
*(.text)
*(SORT(.text$*))
*(.text.*)
*(.glue_7t)
*(.glue_7)
___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0);
___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0);
*(.fini)
/* ??? Why is .gcc_exc here? */
*(.gcc_exc)
PROVIDE (etext = .);
*(.gcc_except_table)
}
……
}
????4
????????????е?18~21?С????е?????????г???????????????????????????е????????????????????????????????????????С???C++?????????????__CTOR_LIST__???鱻???????????????????????????__DTOR_LIST__???鱻?????????????????????????????????????????????????е?.ctors??.ctor?????.ctors.?????????????????????????????????-1??????????????0??
?????????gcc???????g++??????λ?????У????????gbl-ctors.h?п????????????????????libgcc2.c????????????????????????????????????α?????????? 5??????????????????????????????????????
gbl-ctors.h
typedef void (*func_ptr) (void);
extern func_ptr __CTOR_LIST__[];
extern func_ptr __DTOR_LIST__[];
#define DO_GLOBAL_CTORS_BODY
do {
unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
unsigned i;
if (nptrs == (unsigned long)-1)
for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
for (i = nptrs; i >= 1; i--)
__CTOR_LIST__[i] ();
} while (0)
libgcc2.c
void __do_global_dtors (void)
{
static func_ptr *p = __DTOR_LIST__ + 1;
while (*p) {
p++;
(*(p-1)) ();
}
}
void __do_global_ctors (void)
{
DO_GLOBAL_CTORS_BODY;
atexit (__do_global_dtors);
}
????5
?????????е?????????????????????????????????????__do_global_ctors()??????????????DO_GLOBAL_CTORS_BODY??????????????11??12?л???????й????????????????13??14???????????????????????????__do_global_ctors()??????????C???atexit()???????__do_gloabl_dtors()????????ó????????ú???????????á?
??????__do_global_dtors()???????????????????????????????????????????????ù????????????????????????“??????????????????????” ??__do_gloable_ctors() ??__do_gloable_dtors()?????????????C++???????????????????????????????????????????????main()??????????á?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11