void __init_tls(size_t *);
-#ifndef SHARED
-static void dummy() {}
+static void dummy(void) {}
weak_alias(dummy, _init);
-extern void (*const __init_array_start)() __attribute__((weak));
-extern void (*const __init_array_end)() __attribute__((weak));
-#endif
+
+__attribute__((__weak__, __visibility__("hidden")))
+extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
static void dummy1(void *p) {}
weak_alias(dummy1, __init_ssp);
#define AUX_CNT 38
-extern size_t __hwcap, __sysinfo;
-extern char *__progname, *__progname_full;
-
-#ifndef SHARED
-static
-#endif
void __init_libc(char **envp, char *pn)
{
size_t i, *auxv, aux[AUX_CNT] = { 0 };
__sysinfo = aux[AT_SYSINFO];
libc.page_size = aux[AT_PAGESZ];
- if (pn) {
- __progname = __progname_full = pn;
- for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
- }
+ if (!pn) pn = (void*)aux[AT_EXECFN];
+ if (!pn) pn = "";
+ __progname = __progname_full = pn;
+ for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
__init_tls(aux);
__init_ssp((void *)aux[AT_RANDOM]);
&& !aux[AT_SECURE]) return;
struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
+ int r =
#ifdef SYS_poll
__syscall(SYS_poll, pfd, 3, 0);
#else
__syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8);
#endif
+ if (r<0) a_crash();
for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
if (__sys_open("/dev/null", O_RDWR)<0)
a_crash();
libc.secure = 1;
}
+static void libc_start_init(void)
+{
+ _init();
+ uintptr_t a = (uintptr_t)&__init_array_start;
+ for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
+ (*(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)();
-#endif
+ __libc_start_init();
- /* Pass control to to application */
+ /* Pass control to the application */
exit(main(argc, argv, envp));
return 0;
}