From ae115ac6ff72c1fa90cb4dab47b8bfa70504fb2b Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Tue, 11 Dec 2018 21:01:10 -0700 Subject: [PATCH] Run pre-init array before _init --- src/start.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/start.rs b/src/start.rs index 5c5115e65..a21378c34 100644 --- a/src/start.rs +++ b/src/start.rs @@ -77,19 +77,25 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { stdio::stdout = stdio::default_stdout.get(); stdio::stderr = stdio::default_stderr.get(); + // Run preinit array + { + let mut f = &__preinit_array_start as *const _; + while f < &__preinit_array_end { + (*f)(); + f = f.offset(1); + } + } + // Call init section _init(); - // Look for the neighbor functions in memory until the end - let mut f = &__preinit_array_start as *const _; - while f < &__preinit_array_end { - (*f)(); - f = f.offset(1); - } - f = &__init_array_start as *const _; - while f < &__init_array_end { - (*f)(); - f = f.offset(1); + // Run init array + { + let mut f = &__init_array_start as *const _; + while f < &__init_array_end { + (*f)(); + f = f.offset(1); + } } // not argv or envp, because programs like bash try to modify this *const* pointer :| -- GitLab