yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | #include <errno.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | /* |
| 5 | static void (*__CTOR_END__[1]) __P((void)) |
| 6 | __attribute__((section(".ctors"))) = { (void *)-1 }; |
| 7 | |
| 8 | static void (*__DTOR_END__[1]) __P((void)) |
| 9 | __attribute__((__unused__)) |
| 10 | __attribute__((section(".dtors"))) = { (void *)0 }; |
| 11 | */ |
| 12 | extern void (*__CTOR_END__[]) __P((void)); |
| 13 | static void __do_global_ctors_aux __P((void)); |
| 14 | |
| 15 | static void |
| 16 | __do_global_ctors_aux() |
| 17 | { |
| 18 | void (**p)(void) = __CTOR_END__ - 1; |
| 19 | |
| 20 | while (*p) |
| 21 | (**p--)(); |
| 22 | } |
| 23 | |
| 24 | static void dummy_init(void) __attribute__((section(".trash"))); |
| 25 | |
| 26 | void |
| 27 | dummy_init(void) |
| 28 | { |
| 29 | static smallint initialized; |
| 30 | static void (*volatile call__ctors)(void) = __do_global_ctors_aux; |
| 31 | /* |
| 32 | * Call global constructors. |
| 33 | * Arrange to call global destructors at exit. |
| 34 | */ |
| 35 | /* prevent function pointer constant propagation */ |
| 36 | __asm__ __volatile__ (".section .init"); |
| 37 | |
| 38 | if (!initialized) { |
| 39 | initialized = 1; |
| 40 | (*call__ctors)(); |
| 41 | } |
| 42 | __asm__ __volatile__ (".section .trash"); |
| 43 | |
| 44 | } |