elf/startup: Add __mlibc_run_constructors() function for static linking
This commit is contained in:
parent
b57ce631aa
commit
02e740c90d
|
@ -6,6 +6,30 @@
|
|||
#include <bits/ensure.h>
|
||||
#include <mlibc/elf/startup.h>
|
||||
|
||||
extern "C" size_t __init_array_start[];
|
||||
extern "C" size_t __init_array_end[];
|
||||
|
||||
static int constructors_ran_already = 0;
|
||||
|
||||
struct global_constructor_guard {
|
||||
global_constructor_guard() {
|
||||
constructors_ran_already = 1;
|
||||
}
|
||||
};
|
||||
|
||||
static global_constructor_guard g;
|
||||
|
||||
void __mlibc_run_constructors() {
|
||||
if (!constructors_ran_already) {
|
||||
size_t constructor_count = (size_t)__init_array_end - (size_t)__init_array_start;
|
||||
constructor_count /= sizeof(void*);
|
||||
for (size_t i = 0; i < constructor_count; i++) {
|
||||
void (*ptr)(void) = (void(*)(void))(__init_array_start[i]);
|
||||
ptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
void parse_exec_stack(void *opaque_sp, exec_stack_data *data) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef MLIBC_ELF_STARTUP
|
||||
#define MLIBC_ELF_STARTUP
|
||||
|
||||
void __mlibc_run_constructors();
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
struct exec_stack_data {
|
||||
|
|
Loading…
Reference in a new issue