crt1.c 668 Bytes
Newer Older
PoroCYon's avatar
PoroCYon committed
1
2
3
4
5
6
7
8
9
10

#include <stddef.h>

extern int main(int argc, char* argv[]);
extern int __libc_start_main(int (*main)(int, char**),
        int argc, char** argv,
        void (*init)(void), void(*fini)(void),
        void (*rtld_fini)(void),
        void* stack) __attribute__((__noreturn__));

PoroCYon's avatar
PoroCYon committed
11
12
__attribute__((__externally_visible__, __section__(".text.startup._start"),
            __noreturn__))
PoroCYon's avatar
PoroCYon committed
13
int _start(void* stack) {
PoroCYon's avatar
PoroCYon committed
14
15
16
    // TODO: _dl_fini etc.
    int argc=*(size_t*)stack;
    char** argv=(void*)(&((size_t*)stack)[1]);
PoroCYon's avatar
PoroCYon committed
17

18
    // TODO: fix this. it borks with -fno-plt
PoroCYon's avatar
PoroCYon committed
19
20
21
22
23
    __libc_start_main(main, argc, argv, NULL, NULL, NULL, (void*)stack);

    __builtin_unreachable();
}