1 /* ------------------------------------------------------------- */
2 /* support for tcc_run() */
4 #ifdef __leading_underscore
11 extern void (*_(_init_array_start
)[]) (int argc
, char **argv
, char **envp
);
12 extern void (*_(_init_array_end
)[]) (int argc
, char **argv
, char **envp
);
13 static void run_ctors(int argc
, char **argv
, char **env
)
16 while (&_(_init_array_start
)[i
] != _(_init_array_end
))
17 (*_(_init_array_start
)[i
++])(argc
, argv
, env
);
21 extern void (*_(_fini_array_start
)[]) (void);
22 extern void (*_(_fini_array_end
)[]) (void);
23 static void run_dtors(void)
26 while (&_(_fini_array_end
)[i
] != _(_fini_array_start
))
27 (*_(_fini_array_end
)[--i
])();
30 static void *rt_exitfunc
[32];
31 static void *rt_exitarg
[32];
32 static int __rt_nr_exit
;
34 void __run_on_exit(int ret
)
38 --n
, ((void(*)(int,void*))rt_exitfunc
[n
])(ret
, rt_exitarg
[n
]);
41 int on_exit(void *function
, void *arg
)
45 rt_exitfunc
[n
] = function
;
53 int atexit(void (*function
)(void))
55 return on_exit(function
, 0);
58 typedef struct rt_frame
{
62 __attribute__((noreturn
)) void __rt_exit(rt_frame
*, int);
75 int main(int, char**, char**);
77 int _runmain(int argc
, char **argv
, char **envp
)
80 run_ctors(argc
, argv
, envp
);
81 ret
= main(argc
, argv
, envp
);