blob: 775eb0f9d2d5cbe36b41fb77405d40a29655ec93 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#include <errno.h>
2#include <stdlib.h>
3#include <unistd.h>
4/*
5static void (*__CTOR_END__[1]) __P((void))
6 __attribute__((section(".ctors"))) = { (void *)-1 };
7
8static void (*__DTOR_END__[1]) __P((void))
9 __attribute__((__unused__))
10 __attribute__((section(".dtors"))) = { (void *)0 };
11*/
12extern void (*__CTOR_END__[]) __P((void));
13static void __do_global_ctors_aux __P((void));
14
15static void
16__do_global_ctors_aux()
17{
18 void (**p)(void) = __CTOR_END__ - 1;
19
20 while (*p)
21 (**p--)();
22}
23
24static void dummy_init(void) __attribute__((section(".trash")));
25
26void
27dummy_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}