[libc] Pull crt0 out into its own module
Sorta. crt0 is a separate module as far as bonnibel is concerned, but it's still part of the libc module file.
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
%include "util/got.inc"
|
||||
extern _GLOBAL_OFFSET_TABLE_
|
||||
|
||||
extern main
|
||||
extern exit
|
||||
extern __init_libj6
|
||||
extern __init_libc
|
||||
|
||||
; Put the address of the given symbol in rax
|
||||
; This macro is the same as in util/got.inc,
|
||||
; but crt0 can't have a dep on libutil
|
||||
%macro lookup_GOT 1
|
||||
lea rax, [rel _GLOBAL_OFFSET_TABLE_]
|
||||
mov rax, [rax + %1 wrt ..got]
|
||||
%endmacro
|
||||
|
||||
global _start:function weak (_libc_crt0_start.end - _libc_crt0_start)
|
||||
global _libc_crt0_start:function (_libc_crt0_start.end - _libc_crt0_start)
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#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 *array, cb *end)
|
||||
{
|
||||
if (!array || !end)
|
||||
return;
|
||||
|
||||
size_t i = 0;
|
||||
while (true) {
|
||||
const cb &ctor = array[i++];
|
||||
if (&ctor == end) return;
|
||||
if (ctor) 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"
|
||||
void __init_libc()
|
||||
{
|
||||
run_global_ctors();
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
extern "C" {
|
||||
// Stub out these libdl functions for libunwind until
|
||||
// we have a real libdl
|
||||
int dladdr(const void *, void *) { return 0; }
|
||||
int dl_iterate_phdr(void *, void *) { return 0; }
|
||||
}
|
||||
Reference in New Issue
Block a user