forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loader_exe.c
76 lines (64 loc) · 2.24 KB
/
loader_exe.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
// This file is a part of Julia. License is MIT: https://julialang.org/license
// This defines a bare-bones loader that opens `libjulia` and immediately invokes its `load_repl()` function.
#include "loader.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Bring in helper functions for windows without libgcc. */
#ifdef _OS_WINDOWS_
#include "loader_win_utils.c"
#endif
JULIA_DEFINE_FAST_TLS
#ifdef _COMPILER_ASAN_ENABLED_
JL_DLLEXPORT const char* __asan_default_options(void)
{
return "allow_user_segv_handler=1:detect_leaks=0";
// FIXME: enable LSAN after fixing leaks & defining __lsan_default_suppressions(),
// or defining __lsan_default_options = exitcode=0 once publicly available
// (here and in flisp/flmain.c)
}
#endif
#ifdef _OS_WINDOWS_
int mainCRTStartup(void)
{
int argc;
LPWSTR * wargv = CommandLineToArgv(GetCommandLine(), &argc);
char ** argv = (char **)malloc(sizeof(char*) * (argc + 1));
setup_stdio();
#else
int main(int argc, char * argv[])
{
#endif
#if defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_) || defined(_COMPILER_MSAN_ENABLED_)
// ASAN/TSAN do not support RTLD_DEEPBIND
// https://github.com/google/sanitizers/issues/611
putenv("LBT_USE_RTLD_DEEPBIND=0");
#endif
// Convert Windows wchar_t values to UTF8
#ifdef _OS_WINDOWS_
for (int i = 0; i < argc; i++) {
argv[i] = wchar_to_utf8(wargv[i]);
if (!argv[i]) {
jl_loader_print_stderr("Unable to convert all arguments to UTF-8!\n");
return 1;
}
}
argv[argc] = NULL;
#endif
// Call load_repl with our initialization arguments:
int ret = jl_load_repl(argc, argv);
// On Windows we're running without the CRT that would do this for us
exit(ret);
return ret;
}
#if defined(__GLIBC__) && (defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_))
// fork is generally bad news, but it is better if we prevent applications from
// making it worse as openblas threadpools cause it to hang
int __register_atfork232(void (*prepare)(void), void (*parent)(void), void (*child)(void), void *dso_handle) {
return 0;
}
__asm__ (".symver __register_atfork232, __register_atfork@@GLIBC_2.3.2");
#endif
#ifdef __cplusplus
} // extern "C"
#endif