Branch data Line data Source code
1 : : // This file is a part of Julia. License is MIT: https://julialang.org/license 2 : : 3 : : // This defines a bare-bones loader that opens `libjulia` and immediately invokes its `load_repl()` function. 4 : : #include "loader.h" 5 : : 6 : : #ifdef __cplusplus 7 : : extern "C" { 8 : : #endif 9 : : 10 : : /* Bring in helper functions for windows without libgcc. */ 11 : : #ifdef _OS_WINDOWS_ 12 : : #include "loader_win_utils.c" 13 : : #endif 14 : : 15 : 6059013142 : JULIA_DEFINE_FAST_TLS 16 : : 17 : : #ifdef _COMPILER_ASAN_ENABLED_ 18 : : JL_DLLEXPORT const char* __asan_default_options() 19 : : { 20 : : return "allow_user_segv_handler=1:detect_leaks=0"; 21 : : // FIXME: enable LSAN after fixing leaks & defining __lsan_default_suppressions(), 22 : : // or defining __lsan_default_options = exitcode=0 once publicly available 23 : : // (here and in flisp/flmain.c) 24 : : } 25 : : #endif 26 : : 27 : : #ifdef _OS_WINDOWS_ 28 : : int mainCRTStartup(void) 29 : : { 30 : : int argc; 31 : : LPWSTR * wargv = CommandLineToArgv(GetCommandLine(), &argc); 32 : : char ** argv = (char **)malloc(sizeof(char*) * (argc + 1)); 33 : : setup_stdio(); 34 : : #else 35 : 15 : int main(int argc, char * argv[]) 36 : : { 37 : : #endif 38 : : 39 : : #if defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_) 40 : : // ASAN/TSAN do not support RTLD_DEEPBIND 41 : : // https://github.com/google/sanitizers/issues/611 42 : : putenv("LBT_USE_RTLD_DEEPBIND=0"); 43 : : #endif 44 : : 45 : : // Convert Windows wchar_t values to UTF8 46 : : #ifdef _OS_WINDOWS_ 47 : : for (int i = 0; i < argc; i++) { 48 : : size_t max_arg_len = 4*wcslen(wargv[i]); 49 : : argv[i] = (char *)malloc(max_arg_len); 50 : : if (!wchar_to_utf8(wargv[i], argv[i], max_arg_len)) { 51 : : jl_loader_print_stderr("Unable to convert all arguments to UTF-8!\n"); 52 : : return 1; 53 : : } 54 : : } 55 : : argv[argc] = NULL; 56 : : #endif 57 : : 58 : : // Call load_repl with our initialization arguments: 59 : 15 : int ret = jl_load_repl(argc, argv); 60 : : 61 : : // On Windows we're running without the CRT that would do this for us 62 : 13 : exit(ret); 63 : : return ret; 64 : : } 65 : : 66 : : #if defined(__GLIBC__) && (defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_)) 67 : : // fork is generally bad news, but it is better if we prevent applications from 68 : : // making it worse as openblas threadpools cause it to hang 69 : : int __register_atfork232(void (*prepare)(void), void (*parent)(void), void (*child)(void), void *dso_handle) { 70 : : return 0; 71 : : } 72 : : __asm__ (".symver __register_atfork232, __register_atfork@@GLIBC_2.3.2"); 73 : : #endif 74 : : 75 : : #ifdef __cplusplus 76 : : } // extern "C" 77 : : #endif