forked from ensc/dietlibc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyn_start.c
84 lines (66 loc) · 2.11 KB
/
dyn_start.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "dietfeatures.h"
#ifdef WANT_DYNAMIC
#include <sys/cdefs.h>
#include <stdlib.h>
struct object {
void *detail[7]; /* see gcc sources unwind-dw2-fde.h */
};
extern void __register_frame_info (const void *, struct object *) __attribute__((weak));
extern void __deregister_frame_info (const void *) __attribute__((weak));
typedef void(*structor)(void);
__attribute__((section(".ctors")))
__attribute__((aligned(sizeof(structor))))
__attribute_used
static structor __CTOR_LIST__[1]={((structor)-1)};
__attribute__((section(".dtors")))
__attribute__((aligned(sizeof(structor))))
__attribute_used
static structor __DTOR_LIST__[1]={((structor)-1)};
/* see gcc-3.4/gcc/crtstuff.c */
#if !defined(EH_FRAME_SECTION_CONST)
#if defined(__s390__) || defined(__x86_64__)
# define EH_FRAME_SECTION_CONST const
#endif
#endif
#if !defined(EH_FRAME_SECTION_CONST)
# define EH_FRAME_SECTION_CONST
#endif
__attribute__((section(".eh_frame")))
__attribute__((aligned(sizeof(structor))))
__attribute_used
EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[] = { };
static void __do_global_dtors_aux(void)
{
structor *df=__CTOR_LIST__; /* ugly trick to prevent warning */
for (df=((__DTOR_LIST__)+1);(*df) != (structor)0; df++) (*df)();
}
void _fini(void) __attribute__((section(".fini")));
__attribute__((section(".fini"))) void _fini(void)
{
__do_global_dtors_aux();
if (__deregister_frame_info)
__deregister_frame_info(__EH_FRAME_BEGIN__);
}
#ifndef __DYN_LIB_SHARED
/* pre main, post _start */
extern __attribute__((section(".init"))) void _init(void);
int _dyn_start(int argc, char **argv, char **envp, structor dl_init);
int _dyn_start(int argc, char **argv, char **envp, structor dl_init)
{
int CALL_IN_STARTCODE(int argc, char **argv, char **envp);
#ifndef __arm__
/* GT: segfaults on arm, don't know why (for now) */
void _dl_aux_init_from_envp(char **envp);
_dl_aux_init_from_envp(envp);
#endif
if (dl_init) atexit(dl_init);
_init();
atexit(_fini);
if (__register_frame_info) {
static struct object ob;
__register_frame_info(__EH_FRAME_BEGIN__, &ob);
}
return CALL_IN_STARTCODE(argc, argv, envp);
}
#endif
#endif