From 7a13a0d616cde9f0f2a6fe217144e9891e769b61 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 7 Mar 2021 12:49:05 +0200 Subject: [PATCH] Fix libgccjit PROGNAME on MS-Windows * src/comp.c [WINDOWSNT]: Import gcc_jit_context_set_str_option. (init_gccjit_functions): Load gcc_jit_context_set_str_option. (gcc_jit_context_set_str_option) [WINDOWSNT]: New macro. (Fcomp__compile_ctxt_to_file) [WINDOWSNT]: Pass the actual name of the libgccjit DLL to the library, to be used as PROGNAME. --- src/comp.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/comp.c b/src/comp.c index 94d3fa99a33..d9ad623ec79 100644 --- a/src/comp.c +++ b/src/comp.c @@ -89,6 +89,7 @@ along with GNU Emacs. If not, see . */ #undef gcc_jit_context_set_bool_option #undef gcc_jit_context_set_int_option #undef gcc_jit_context_set_logfile +#undef gcc_jit_context_set_str_option #undef gcc_jit_function_get_param #undef gcc_jit_function_new_block #undef gcc_jit_function_new_local @@ -248,6 +249,9 @@ DEF_DLL_FN (void, gcc_jit_context_set_int_option, (gcc_jit_context *ctxt, enum gcc_jit_int_option opt, int value)); DEF_DLL_FN (void, gcc_jit_context_set_logfile, (gcc_jit_context *ctxt, FILE *logfile, int flags, int verbosity)); +DEF_DLL_FN (void, gcc_jit_context_set_str_option, + (gcc_jit_context *ctxt, enum gcc_jit_str_option opt, + const char *value)); DEF_DLL_FN (void, gcc_jit_struct_set_fields, (gcc_jit_struct *struct_type, gcc_jit_location *loc, int num_fields, gcc_jit_field **fields)); @@ -304,6 +308,7 @@ init_gccjit_functions (void) LOAD_DLL_FN (library, gcc_jit_context_set_bool_option); LOAD_DLL_FN (library, gcc_jit_context_set_int_option); LOAD_DLL_FN (library, gcc_jit_context_set_logfile); + LOAD_DLL_FN (library, gcc_jit_context_set_str_option); LOAD_DLL_FN (library, gcc_jit_function_get_param); LOAD_DLL_FN (library, gcc_jit_function_new_block); LOAD_DLL_FN (library, gcc_jit_function_new_local); @@ -373,6 +378,7 @@ init_gccjit_functions (void) #define gcc_jit_context_set_bool_option fn_gcc_jit_context_set_bool_option #define gcc_jit_context_set_int_option fn_gcc_jit_context_set_int_option #define gcc_jit_context_set_logfile fn_gcc_jit_context_set_logfile +#define gcc_jit_context_set_str_option fn_gcc_jit_context_set_str_option #define gcc_jit_function_get_param fn_gcc_jit_function_get_param #define gcc_jit_function_new_block fn_gcc_jit_function_new_block #define gcc_jit_function_new_local fn_gcc_jit_function_new_local @@ -4364,6 +4370,30 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, comp.func_relocs_local = NULL; +#ifdef WINDOWSNT + /* Tell libgccjit the actual file name of the loaded DLL, otherwise + it will use 'libgccjit.so', which is not useful. */ + Lisp_Object libgccjit_loaded_from = Fget (Qgccjit, QCloaded_from); + Lisp_Object libgccjit_fname; + + if (CONSP (libgccjit_loaded_from)) + { + /* Use the absolute file name if available, otherwise the name + we looked for in w32_delayed_load. */ + libgccjit_fname = XCDR (libgccjit_loaded_from); + if (NILP (libgccjit_fname)) + libgccjit_fname = XCAR (libgccjit_loaded_from); + /* Must encode to ANSI, as libgccjit will not be able to handle + UTF-8 encoded file names. */ + libgccjit_fname = ansi_encode_filename (libgccjit_fname); + gcc_jit_context_set_str_option (comp.ctxt, GCC_JIT_STR_OPTION_PROGNAME, + SSDATA (libgccjit_fname)); + } + else /* this should never happen */ + gcc_jit_context_set_str_option (comp.ctxt, GCC_JIT_STR_OPTION_PROGNAME, + "libgccjit-0.dll"); +#endif + comp.speed = XFIXNUM (CALL1I (comp-ctxt-speed, Vcomp_ctxt)); eassert (comp.speed < INT_MAX); comp.debug = XFIXNUM (CALL1I (comp-ctxt-debug, Vcomp_ctxt)); -- 2.39.2