diff --git a/userspace/libraries/LibC/arch/i686/crt0.S b/userspace/libraries/LibC/arch/i686/crt0.S index 50d635ff..f50cdfb4 100644 --- a/userspace/libraries/LibC/arch/i686/crt0.S +++ b/userspace/libraries/LibC/arch/i686/crt0.S @@ -19,7 +19,11 @@ _start: call _init_libc # call global constructors - call _init + movl $_init, %eax + testl %eax, %eax + jz 1f + call *%eax + 1: movl $__init_array_start, %ebx jmp 2f diff --git a/userspace/libraries/LibC/arch/x86_64/crt0.S b/userspace/libraries/LibC/arch/x86_64/crt0.S index 46d83cdc..b5b543c9 100644 --- a/userspace/libraries/LibC/arch/x86_64/crt0.S +++ b/userspace/libraries/LibC/arch/x86_64/crt0.S @@ -20,7 +20,11 @@ _start: call _init_libc # call global constructors - call _init + movq $_init, %rax + testq %rax, %rax + jz 1f + call *%rax + 1: movq $__init_array_start, %rbx jmp 2f diff --git a/userspace/libraries/LibC/stdlib.cpp b/userspace/libraries/LibC/stdlib.cpp index 3be7c717..18773023 100644 --- a/userspace/libraries/LibC/stdlib.cpp +++ b/userspace/libraries/LibC/stdlib.cpp @@ -16,7 +16,7 @@ extern "C" char** environ; -extern "C" void _fini(); +extern "C" __attribute__((weak)) void _fini(); static void (*at_exit_funcs[64])(); static uint32_t at_exit_funcs_count = 0; @@ -34,7 +34,7 @@ void exit(int status) at_exit_funcs[i - 1](); fflush(nullptr); __cxa_finalize(nullptr); - _fini(); + if (_fini) _fini(); _exit(status); ASSERT_NOT_REACHED(); }