[ld.so] Call all image global ctors, not just libc

With the move to dynamic executables, crt0's _start was only ever
calling libc's __init_libc, which only ran libc's init_array list. Now
make crt0 itself (which is statically linked into every executable) call
it's own init_array list and have ld.so call every other image's ctor
lists.
This commit is contained in:
Justin C. Miller
2024-04-29 01:07:18 -07:00
parent 70af5a31cd
commit 7322df98f5
4 changed files with 71 additions and 34 deletions

View File

@@ -1,33 +1,6 @@
#include <stddef.h>
using cb = void (*)(void);
extern cb __preinit_array_start;
extern cb __preinit_array_end;
extern cb __init_array_start;
extern cb __init_array_end;
namespace {
void
run_ctor_list(cb *p, cb *end)
{
while (p && end && p < end) {
if (p) (*p)();
++p;
}
}
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" void
__init_libc()
{
run_global_ctors();
}