From ae8e070b9ef17f22d6f30da2467aa894d1b5c96d Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Sun, 2 Aug 2020 14:32:28 -0600
Subject: [PATCH] Init TLS before allocator

---
 src/start.rs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/start.rs b/src/start.rs
index e45ed130..d001d9dd 100644
--- a/src/start.rs
+++ b/src/start.rs
@@ -112,15 +112,17 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
         fn _init();
         fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int;
     }
-    // Step 1 setup the right allocator...
-    // if any memory rust based memory allocation happen before this step .. we are doomed.
-    alloc_init();
 
     // Ensure correct host system before executing more system calls
     relibc_verify_host();
 
+    // Initialize TLS, if necessary
     ld_so::init(sp);
 
+    // Set up the right allocator...
+    // if any memory rust based memory allocation happen before this step .. we are doomed.
+    alloc_init();
+
     // Set up argc and argv
     let argc = sp.argc;
     let argv = sp.argv();
-- 
GitLab