2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016, Richard Lowe.
17 * That of the CRT startup routine which itself may be implemented in C.
20 #include <sys/feature_tests.h>
21 #include <sys/types.h>
28 extern uintptr_t _DYNAMIC
;
30 #pragma weak environ = _environ
31 char **_environ
= NULL
;
32 char **___Argv
= NULL
;
34 extern int main(int argc
, char **argv
, char **envp
);
35 extern void _init(void);
36 extern void _fini(void);
38 #pragma weak _start_crt_compiler
39 extern void _start_crt_compiler(int argc
, char **argv
);
42 int __longdouble_used
= 0;
43 extern void __fpstart(void);
46 #if defined(__i386) /* Not amd64 */
47 #pragma weak __fsr_init_value
48 extern long __fsr_init_value
;
49 extern void __fsr(uintptr_t);
54 * Defined here for ABI reasons, must match the definition in libc.
55 * If it cannot, a new symbol must be created.
57 mutex_t __environ_lock
= DEFAULTMUTEX
;
60 _start_crt(int argc
, char **argv
, void (*exit_handler
)(void))
65 * On x86, we check whether we're a dynamic executable to see whether
66 * we'll receive an exit_handler.
68 * On SPARC, we just need to check whether the handler was NULL.
71 if (&_DYNAMIC
!= NULL
)
72 (void) atexit(exit_handler
);
73 #elif defined(__sparc)
74 if (exit_handler
!= NULL
)
75 (void) atexit(exit_handler
);
80 _environ
= argv
+ (argc
+ 1);
83 if (&_start_crt_compiler
!= NULL
)
84 _start_crt_compiler(argc
, argv
);
89 #if defined(__i386) /* Not amd64 */
91 * Note that Studio cc(1) sets the _value of the symbol_, that is, its
92 * address. Not the value _at_ that address.
94 __fsr((uintptr_t)&__fsr_init_value
);
97 ret
= main(argc
, argv
, _environ
);