diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-07-09 00:58:43 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-10 01:41:57 +0200 |
commit | 06883ed8a32cc44ce5fdf26af0b5ec5ee2e2dbe7 (patch) | |
tree | f72c8f0d697bede3f9a29ea3e95a7d8d974f8393 /Userland/Libraries/LibELF/DynamicLinker.cpp | |
parent | f4a318ee2d868d6d4f712afa8de786bba9703e36 (diff) | |
download | serenity-06883ed8a32cc44ce5fdf26af0b5ec5ee2e2dbe7.zip |
Kernel+Userland: Make the stack alignment comply with the System V ABI
The System V ABI for both x86 and x86_64 requires that the stack pointer
is 16-byte aligned on entry. Previously we did not align the stack
pointer properly.
As far as "main" was concerned the stack alignment was correct even
without this patch due to how the C++ _start function and the kernel
interacted, i.e. the kernel misaligned the stack as far as the ABI
was concerned but that misalignment (read: it was properly aligned for
a regular function call - but misaligned in terms of what the ABI
dictates) was actually expected by our _start function.
Diffstat (limited to 'Userland/Libraries/LibELF/DynamicLinker.cpp')
-rw-r--r-- | Userland/Libraries/LibELF/DynamicLinker.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp index cc93fea4ed..2aaa5b4175 100644 --- a/Userland/Libraries/LibELF/DynamicLinker.cpp +++ b/Userland/Libraries/LibELF/DynamicLinker.cpp @@ -41,6 +41,8 @@ using LibCExitFunction = void (*)(int); using DlIteratePhdrCallbackFunction = int (*)(struct dl_phdr_info*, size_t, void*); using DlIteratePhdrFunction = int (*)(DlIteratePhdrCallbackFunction, void*); +extern "C" [[noreturn]] void _invoke_entry(int argc, char** argv, char** envp, EntryPointFunction entry); + static size_t s_current_tls_offset = 0; static size_t s_total_tls_size = 0; static size_t s_allocated_tls_block_size = 0; @@ -550,14 +552,8 @@ void ELF::DynamicLinker::linker_main(String&& main_program_name, int main_progra if (s_do_breakpoint_trap_before_entry) { asm("int3"); } - rc = entry_point_function(argc, argv, envp); - dbgln_if(DYNAMIC_LOAD_DEBUG, "rc: {}", rc); - if (s_libc_exit != nullptr) { - s_libc_exit(rc); - } else { - _exit(rc); - } + _invoke_entry(argc, argv, envp, entry_point_function); VERIFY_NOT_REACHED(); } |