summaryrefslogtreecommitdiff
path: root/src/env/__libc_start_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/env/__libc_start_main.c')
-rw-r--r--src/env/__libc_start_main.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 58da9e83..c5b277bd 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -17,6 +17,9 @@ weak_alias(dummy1, __init_ssp);
#define AUX_CNT 38
+#ifdef __GNUC__
+__attribute__((__noinline__))
+#endif
void __init_libc(char **envp, char *pn)
{
size_t i, *auxv, aux[AUX_CNT] = { 0 };
@@ -25,7 +28,7 @@ void __init_libc(char **envp, char *pn)
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];
+ if (aux[AT_SYSINFO]) __sysinfo = aux[AT_SYSINFO];
libc.page_size = aux[AT_PAGESZ];
if (!pn) pn = (void*)aux[AT_EXECFN];
@@ -63,11 +66,29 @@ static void libc_start_init(void)
weak_alias(libc_start_init, __libc_start_init);
-int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
+typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
+static lsm2_fn libc_start_main_stage2;
+
+int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
+ void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
{
char **envp = argv+argc+1;
+ /* External linkage, and explicit noinline attribute if available,
+ * are used to prevent the stack frame used during init from
+ * persisting for the entire process lifetime. */
__init_libc(envp, argv[0]);
+
+ /* Barrier against hoisting application code or anything using ssp
+ * or thread pointer prior to its initialization above. */
+ lsm2_fn *stage2 = libc_start_main_stage2;
+ __asm__ ( "" : "+r"(stage2) : : "memory" );
+ return stage2(main, argc, argv);
+}
+
+static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, char **argv)
+{
+ char **envp = argv+argc+1;
__libc_start_init();
/* Pass control to the application */