From 19206f75ee81a1941f2e23bca6cbb302bca6dacf Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Wed, 24 Apr 2024 15:42:36 -0400 Subject: [PATCH] DynamicLoader: Ensure that optimizer won't interfere with early init --- Userland/DynamicLoader/main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/DynamicLoader/main.cpp b/Userland/DynamicLoader/main.cpp index 2822c0d7b83..2873094b8d5 100644 --- a/Userland/DynamicLoader/main.cpp +++ b/Userland/DynamicLoader/main.cpp @@ -103,6 +103,11 @@ static ErrorOr 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();