Bläddra i källkod

DynamicLoader: Ensure that optimizer won't interfere with early init

Dan Klishch 1 år sedan
förälder
incheckning
19206f75ee
1 ändrade filer med 12 tillägg och 0 borttagningar
  1. 12 0
      Userland/DynamicLoader/main.cpp

+ 12 - 0
Userland/DynamicLoader/main.cpp

@@ -103,6 +103,11 @@ static ErrorOr<int> open_executable(char const* path)
     return checked_fd;
 }
 
+ALWAYS_INLINE static void optimizer_fence()
+{
+    asm("" ::: "memory");
+}
+
 void _entry(int argc, char** argv, char** envp)
 {
     char** env;
@@ -121,8 +126,15 @@ void _entry(int argc, char** argv, char** envp)
     }
     VERIFY(at_random_found);
 
+    // Make sure compiler won't move any functions calls above __stack_chk_guard initialization even
+    // if their definitions somehow become available.
+    optimizer_fence();
+
     perform_self_relocations(auxvp);
 
+    // Similarly, make sure no non-offset-agnostic language features are used above this point.
+    optimizer_fence();
+
     // Initialize the copy of libc included statically in Loader.so,
     // initialization of the dynamic libc.so is done by the DynamicLinker
     __libc_init();