From b46b6363fff1bebc937650259cc9966b87023e95 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sun, 13 Feb 2022 00:09:36 -0800 Subject: [PATCH] [libc] Run the .preinit_array as well in __init_libc The __init_libc function was already running the .init_array functions, but was never running the .preinit_array functions. Now it runs them both, in the correct order. --- src/libraries/libc/arch/amd64/crt/init.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libraries/libc/arch/amd64/crt/init.cpp b/src/libraries/libc/arch/amd64/crt/init.cpp index b183c01..603fa90 100644 --- a/src/libraries/libc/arch/amd64/crt/init.cpp +++ b/src/libraries/libc/arch/amd64/crt/init.cpp @@ -1,23 +1,31 @@ #include using cb = void (*)(void); -extern cb __init_array_start[0]; +extern cb __preinit_array_start; +extern cb __preinit_array_end; +extern cb __init_array_start; extern cb __init_array_end; namespace { void -run_global_ctors() +run_ctor_list(cb *array, cb *end) { size_t i = 0; while (true) { - const cb &fp = __init_array_start[i++]; - if (&fp == &__init_array_end) - return; - fp(); + const cb &ctor = array[i++]; + if (&ctor == end) return; + ctor(); } } +void +run_global_ctors() +{ + run_ctor_list(&__preinit_array_start, &__preinit_array_end); + run_ctor_list(&__init_array_start, &__init_array_end); +} + } // namespace extern "C"