void __init_tls(size_t *);
-#ifndef SHARED
-static void dummy() {}
-weak_alias(dummy, _init);
+extern void _init() __attribute__((weak));
extern void (*const __init_array_start)() __attribute__((weak));
extern void (*const __init_array_end)() __attribute__((weak));
-#endif
static void dummy1(void *p) {}
weak_alias(dummy1, __init_ssp);
#define AUX_CNT 38
-#ifndef SHARED
-static
-#endif
void __init_libc(char **envp, char *pn)
{
size_t i, *auxv, aux[AUX_CNT] = { 0 };
libc.secure = 1;
}
+static void libc_start_init(void)
+{
+ if (_init) _init();
+ uintptr_t a = (uintptr_t)&__init_array_start;
+ for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
+ (*(void (**)())a)();
+}
+
+weak_alias(libc_start_init, __libc_start_init);
+
int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
{
char **envp = argv+argc+1;
-#ifndef SHARED
__init_libc(envp, argv[0]);
- _init();
- uintptr_t a = (uintptr_t)&__init_array_start;
- for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
- (*(void (**)())a)();
-#else
- void __libc_start_init(void);
__libc_start_init();
-#endif
/* Pass control to the application */
exit(main(argc, argv, envp));
weak_alias(dummy, __funcs_on_exit);
weak_alias(dummy, __stdio_exit);
-#ifndef SHARED
-weak_alias(dummy, _fini);
+extern void _fini() __attribute__((weak));
extern void (*const __fini_array_start)() __attribute__((weak));
extern void (*const __fini_array_end)() __attribute__((weak));
-#endif
-_Noreturn void exit(int code)
+static void libc_exit_fini(void)
{
- __funcs_on_exit();
-
-#ifndef SHARED
uintptr_t a = (uintptr_t)&__fini_array_end;
for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
(*(void (**)())(a-sizeof(void(*)())))();
- _fini();
-#endif
+ if (_fini) _fini();
+}
- __stdio_exit();
+weak_alias(libc_exit_fini, __libc_exit_fini);
+_Noreturn void exit(int code)
+{
+ __funcs_on_exit();
+ __libc_exit_fini();
+ __stdio_exit();
_Exit(code);
}