mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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.
This commit is contained in:
@@ -1,23 +1,31 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
using cb = void (*)(void);
|
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;
|
extern cb __init_array_end;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void
|
void
|
||||||
run_global_ctors()
|
run_ctor_list(cb *array, cb *end)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
const cb &fp = __init_array_start[i++];
|
const cb &ctor = array[i++];
|
||||||
if (&fp == &__init_array_end)
|
if (&ctor == end) return;
|
||||||
return;
|
ctor();
|
||||||
fp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run_global_ctors()
|
||||||
|
{
|
||||||
|
run_ctor_list(&__preinit_array_start, &__preinit_array_end);
|
||||||
|
run_ctor_list(&__init_array_start, &__init_array_end);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|||||||
Reference in New Issue
Block a user