diff options
| author | Andreas Fuchs | 2020-08-08 16:22:43 -0400 |
|---|---|---|
| committer | Andrea Corallo | 2020-08-19 17:12:21 +0200 |
| commit | bec2adebc6a5c4984d52ea7e66a7a3632e7dc578 (patch) | |
| tree | 6376d4f50fa151be5601d1ef16d800df1d4bf3ec | |
| parent | 8a931a97b8dd19a38d6f719f810280a07ba76438 (diff) | |
| download | emacs-bec2adebc6a5c4984d52ea7e66a7a3632e7dc578.tar.gz emacs-bec2adebc6a5c4984d52ea7e66a7a3632e7dc578.zip | |
Pass driver options to libgccjit where supported
Add a customizable variable for driver options (such as linker flags)
to pass to libgccjit (Bug #42761).
* lisp/emacs-lisp/comp.el (comp-native-driver-options): New
customization variable.
* src/comp.c: Use comp-native-driver-options to set libgccjit's driver
options, if supported on the library's ABI version.
| -rw-r--r-- | lisp/emacs-lisp/comp.el | 10 | ||||
| -rw-r--r-- | src/comp.c | 28 |
2 files changed, 38 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 3176351b37d..37559c20dd4 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el | |||
| @@ -134,6 +134,16 @@ before compilation. Usable to modify the compiler environment." | |||
| 134 | :type 'list | 134 | :type 'list |
| 135 | :group 'comp) | 135 | :group 'comp) |
| 136 | 136 | ||
| 137 | (defcustom comp-native-driver-options nil | ||
| 138 | "Options passed verbatim to the native compiler's backend driver. | ||
| 139 | Note that not all options are meaningful; typically only the options | ||
| 140 | affecting the assembler and linker are likely to be useful. | ||
| 141 | |||
| 142 | Passing these options is only available in libgccjit version 9 | ||
| 143 | and above." | ||
| 144 | :type 'list | ||
| 145 | :group 'comp) | ||
| 146 | |||
| 137 | (defvar comp-dry-run nil | 147 | (defvar comp-dry-run nil |
| 138 | "When non nil run everything but the C back-end.") | 148 | "When non nil run everything but the C back-end.") |
| 139 | 149 | ||
diff --git a/src/comp.c b/src/comp.c index a00088bb7f8..97a56658707 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -54,6 +54,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 54 | #undef gcc_jit_block_end_with_return | 54 | #undef gcc_jit_block_end_with_return |
| 55 | #undef gcc_jit_block_end_with_void_return | 55 | #undef gcc_jit_block_end_with_void_return |
| 56 | #undef gcc_jit_context_acquire | 56 | #undef gcc_jit_context_acquire |
| 57 | #undef gcc_jit_context_add_driver_option | ||
| 57 | #undef gcc_jit_context_compile_to_file | 58 | #undef gcc_jit_context_compile_to_file |
| 58 | #undef gcc_jit_context_dump_reproducer_to_file | 59 | #undef gcc_jit_context_dump_reproducer_to_file |
| 59 | #undef gcc_jit_context_dump_to_file | 60 | #undef gcc_jit_context_dump_to_file |
| @@ -119,6 +120,8 @@ DEF_DLL_FN (const char *, gcc_jit_context_get_first_error, | |||
| 119 | DEF_DLL_FN (gcc_jit_block *, gcc_jit_function_new_block, | 120 | DEF_DLL_FN (gcc_jit_block *, gcc_jit_function_new_block, |
| 120 | (gcc_jit_function *func, const char *name)); | 121 | (gcc_jit_function *func, const char *name)); |
| 121 | DEF_DLL_FN (gcc_jit_context *, gcc_jit_context_acquire, (void)); | 122 | DEF_DLL_FN (gcc_jit_context *, gcc_jit_context_acquire, (void)); |
| 123 | DEF_DLL_FN (void, gcc_jit_context_add_driver_option, | ||
| 124 | (gcc_jit_context *ctxt, const char *optname)); | ||
| 122 | DEF_DLL_FN (gcc_jit_field *, gcc_jit_context_new_field, | 125 | DEF_DLL_FN (gcc_jit_field *, gcc_jit_context_new_field, |
| 123 | (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *type, | 126 | (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *type, |
| 124 | const char *name)); | 127 | const char *name)); |
| @@ -256,6 +259,7 @@ init_gccjit_functions (void) | |||
| 256 | LOAD_DLL_FN (library, gcc_jit_block_end_with_return); | 259 | LOAD_DLL_FN (library, gcc_jit_block_end_with_return); |
| 257 | LOAD_DLL_FN (library, gcc_jit_block_end_with_void_return); | 260 | LOAD_DLL_FN (library, gcc_jit_block_end_with_void_return); |
| 258 | LOAD_DLL_FN (library, gcc_jit_context_acquire); | 261 | LOAD_DLL_FN (library, gcc_jit_context_acquire); |
| 262 | LOAD_DLL_FN (library, gcc_jit_context_add_driver_option); | ||
| 259 | LOAD_DLL_FN (library, gcc_jit_context_compile_to_file); | 263 | LOAD_DLL_FN (library, gcc_jit_context_compile_to_file); |
| 260 | LOAD_DLL_FN (library, gcc_jit_context_dump_reproducer_to_file); | 264 | LOAD_DLL_FN (library, gcc_jit_context_dump_reproducer_to_file); |
| 261 | LOAD_DLL_FN (library, gcc_jit_context_dump_to_file); | 265 | LOAD_DLL_FN (library, gcc_jit_context_dump_to_file); |
| @@ -317,6 +321,7 @@ init_gccjit_functions (void) | |||
| 317 | #define gcc_jit_block_end_with_return fn_gcc_jit_block_end_with_return | 321 | #define gcc_jit_block_end_with_return fn_gcc_jit_block_end_with_return |
| 318 | #define gcc_jit_block_end_with_void_return fn_gcc_jit_block_end_with_void_return | 322 | #define gcc_jit_block_end_with_void_return fn_gcc_jit_block_end_with_void_return |
| 319 | #define gcc_jit_context_acquire fn_gcc_jit_context_acquire | 323 | #define gcc_jit_context_acquire fn_gcc_jit_context_acquire |
| 324 | #define gcc_jit_context_add_driver_option fn_gcc_jit_context_add_driver_option | ||
| 320 | #define gcc_jit_context_compile_to_file fn_gcc_jit_context_compile_to_file | 325 | #define gcc_jit_context_compile_to_file fn_gcc_jit_context_compile_to_file |
| 321 | #define gcc_jit_context_dump_reproducer_to_file fn_gcc_jit_context_dump_reproducer_to_file | 326 | #define gcc_jit_context_dump_reproducer_to_file fn_gcc_jit_context_dump_reproducer_to_file |
| 322 | #define gcc_jit_context_dump_to_file fn_gcc_jit_context_dump_to_file | 327 | #define gcc_jit_context_dump_to_file fn_gcc_jit_context_dump_to_file |
| @@ -4118,6 +4123,26 @@ DEFUN ("comp--release-ctxt", Fcomp__release_ctxt, Scomp__release_ctxt, | |||
| 4118 | } | 4123 | } |
| 4119 | 4124 | ||
| 4120 | static void | 4125 | static void |
| 4126 | add_driver_options () | ||
| 4127 | { | ||
| 4128 | Lisp_Object options = Fsymbol_value (Qcomp_native_driver_options); | ||
| 4129 | |||
| 4130 | #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option | ||
| 4131 | while (CONSP (options)) | ||
| 4132 | { | ||
| 4133 | gcc_jit_context_add_driver_option (comp.ctxt, SSDATA (XCAR (options))); | ||
| 4134 | options = XCDR (options); | ||
| 4135 | } | ||
| 4136 | #else | ||
| 4137 | if (CONSP (options)) | ||
| 4138 | { | ||
| 4139 | xsignal1 (Qnative_compiler_error, | ||
| 4140 | build_string ("Customizing native compiler options via `comp-native-driver-options' is only available on libgccjit version 9 and above.")); | ||
| 4141 | } | ||
| 4142 | #endif | ||
| 4143 | } | ||
| 4144 | |||
| 4145 | static void | ||
| 4121 | restore_sigmask (void) | 4146 | restore_sigmask (void) |
| 4122 | { | 4147 | { |
| 4123 | pthread_sigmask (SIG_SETMASK, &saved_sigset, 0); | 4148 | pthread_sigmask (SIG_SETMASK, &saved_sigset, 0); |
| @@ -4186,6 +4211,8 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, | |||
| 4186 | for (ptrdiff_t i = 0; i < func_h->count; i++) | 4211 | for (ptrdiff_t i = 0; i < func_h->count; i++) |
| 4187 | compile_function (HASH_VALUE (func_h, i)); | 4212 | compile_function (HASH_VALUE (func_h, i)); |
| 4188 | 4213 | ||
| 4214 | add_driver_options (); | ||
| 4215 | |||
| 4189 | if (COMP_DEBUG) | 4216 | if (COMP_DEBUG) |
| 4190 | gcc_jit_context_dump_to_file (comp.ctxt, | 4217 | gcc_jit_context_dump_to_file (comp.ctxt, |
| 4191 | format_string ("%s.c", SSDATA (base_name)), | 4218 | format_string ("%s.c", SSDATA (base_name)), |
| @@ -4992,6 +5019,7 @@ native compiled one. */); | |||
| 4992 | 5019 | ||
| 4993 | DEFSYM (Qcomp_speed, "comp-speed"); | 5020 | DEFSYM (Qcomp_speed, "comp-speed"); |
| 4994 | DEFSYM (Qcomp_debug, "comp-debug"); | 5021 | DEFSYM (Qcomp_debug, "comp-debug"); |
| 5022 | DEFSYM (Qcomp_native_driver_options, "comp-native-driver-options"); | ||
| 4995 | 5023 | ||
| 4996 | /* Limple instruction set. */ | 5024 | /* Limple instruction set. */ |
| 4997 | DEFSYM (Qcomment, "comment"); | 5025 | DEFSYM (Qcomment, "comment"); |