surenyi
6 months ago
3 changed files with 71 additions and 62 deletions
@ -0,0 +1,56 @@ |
|||
#include <stddef.h> |
|||
|
|||
/* {{{ __libc_init_array */ |
|||
/* These magic symbols are provided by the linker. */ |
|||
/* clang-format off */ |
|||
extern void (*__preinit_array_start[])(void)__attribute__((weak)); |
|||
extern void (*__preinit_array_end [])(void)__attribute__((weak)); |
|||
extern void (*__init_array_start [])(void)__attribute__((weak)); |
|||
extern void (*__init_array_end [])(void)__attribute__((weak)); |
|||
/* clang-format on */ |
|||
|
|||
static void __empty(void) |
|||
{ |
|||
} |
|||
|
|||
/* clang-format off */ |
|||
void _init (void) __attribute__((weak, alias("__empty"))); |
|||
/* clang-format on */ |
|||
|
|||
/* iterate over all the init routines. */ |
|||
void __libc_init_array(void) |
|||
{ |
|||
size_t count; |
|||
size_t i; |
|||
|
|||
count = __preinit_array_end - __preinit_array_start; |
|||
for (i = 0; i < count; i++) |
|||
__preinit_array_start[i](); |
|||
|
|||
_init(); |
|||
|
|||
#if !defined(__RTTHREAD__) |
|||
count = __init_array_end - __init_array_start; |
|||
for (i = 0; i < count; i++) |
|||
__init_array_start[i](); |
|||
#endif |
|||
} |
|||
/* }}} */ |
|||
|
|||
/* {{{ __libc_fini_array */ |
|||
extern void (*__fini_array_start[])(void) __attribute__((weak)); |
|||
extern void (*__fini_array_end[])(void) __attribute__((weak)); |
|||
void _fini(void) __attribute__((weak, alias("__empty"))); |
|||
/* Run all the cleanup routines. */ |
|||
void __libc_fini_array(void) |
|||
{ |
|||
size_t count; |
|||
size_t i; |
|||
|
|||
count = __fini_array_end - __fini_array_start; |
|||
for (i = count; i > 0; i--) |
|||
__fini_array_start[i - 1](); |
|||
|
|||
_fini(); |
|||
} |
|||
/* }}} */ |
Loading…
Reference in new issue