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

This commit is contained in:
Dan Klishch 2024-04-24 15:42:36 -04:00 committed by Andrew Kaster
parent 01f1d2daaa
commit 19206f75ee
Notes: sideshowbarker 2024-07-17 11:29:41 +09:00

View file

@ -103,6 +103,11 @@ static ErrorOr<int> open_executable(char const* path)
return checked_fd; return checked_fd;
} }
ALWAYS_INLINE static void optimizer_fence()
{
asm("" ::: "memory");
}
void _entry(int argc, char** argv, char** envp) void _entry(int argc, char** argv, char** envp)
{ {
char** env; char** env;
@ -121,8 +126,15 @@ void _entry(int argc, char** argv, char** envp)
} }
VERIFY(at_random_found); 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); 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, // Initialize the copy of libc included statically in Loader.so,
// initialization of the dynamic libc.so is done by the DynamicLinker // initialization of the dynamic libc.so is done by the DynamicLinker
__libc_init(); __libc_init();