fix ordering of shared library ctors with respect to libc init
[musl] / src / env / __libc_start_main.c
index e350fdb..04a454e 100644 (file)
@@ -3,9 +3,12 @@
 
 void __init_tls(size_t *);
 void __init_security(size_t *);
+void __init_ldso_ctors(void);
 
 #define AUX_CNT 38
 
+extern size_t __hwcap, __sysinfo;
+
 void __init_libc(char **envp)
 {
        size_t i, *auxv, aux[AUX_CNT] = { 0 };
@@ -14,6 +17,7 @@ void __init_libc(char **envp)
        libc.auxv = auxv = (void *)(envp+i+1);
        for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
        __hwcap = aux[AT_HWCAP];
+       __sysinfo = aux[AT_SYSINFO];
 
        __init_tls(aux);
        __init_security(aux);
@@ -34,6 +38,10 @@ int __libc_start_main(
        /* Execute constructors (static) linked into the application */
        if (init) init(argc, argv, envp);
 
+#ifdef SHARED
+       __init_ldso_ctors();
+#endif
+
        /* Pass control to to application */
        exit(main(argc, argv, envp));
        return 0;