diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 80a1da5ad8..58d361cf46 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -166,6 +166,16 @@ native-comp-async-query-on-exit :type 'boolean :version "28.1") +(defcustom native-comp-compiler-options nil + "Options passed verbatim to the native compiler's c driver. +Note that not all options are meaningful and some options might even +break your code. Use at own risk. + +Passing these options is only available in libgccjit version 9 +and above." + :type '(repeat string) ; FIXME is this right? + :version "28.1") + (defcustom native-comp-driver-options nil "Options passed verbatim to the native compiler's back-end driver. Note that not all options are meaningful; typically only the options @@ -755,6 +765,8 @@ comp-data-container :documentation "Default speed for this compilation unit.") (debug native-comp-debug :type number :documentation "Default debug level for this compilation unit.") + (compiler-options native-comp-compiler-options :type list + :documentation "Options for the GCC C compiler.") (driver-options native-comp-driver-options :type list :documentation "Options for the GCC driver.") (top-level-forms () :type list @@ -1347,6 +1359,8 @@ comp-spill-lap-function byte-native-qualities) (comp-ctxt-debug comp-ctxt) (alist-get 'native-comp-debug byte-native-qualities) + (comp-ctxt-compiler-options comp-ctxt) (alist-get 'native-comp-compiler-options + byte-native-qualities) (comp-ctxt-driver-options comp-ctxt) (alist-get 'native-comp-driver-options byte-native-qualities) (comp-ctxt-top-level-forms comp-ctxt) @@ -3665,6 +3679,8 @@ comp-final native-comp-eln-load-path ',native-comp-eln-load-path native-comp-driver-options ',native-comp-driver-options + native-comp-compiler-options + ',native-comp-compiler-options load-path ',load-path) ,native-comp-async-env-modifier-form (message "Compiling %s..." ',output) @@ -3928,6 +3944,8 @@ comp-run-async-workers native-comp-eln-load-path ',native-comp-eln-load-path native-comp-driver-options ',native-comp-driver-options + native-comp-compiler-options + ',native-comp-compiler-options load-path ',load-path warning-fill-column most-positive-fixnum) ,native-comp-async-env-modifier-form diff --git a/src/comp.c b/src/comp.c index 74a5337f8d..7058f80cdf 100644 --- a/src/comp.c +++ b/src/comp.c @@ -517,6 +517,7 @@ #define NUM_CAST_TYPES 15 EMACS_INT speed; EMACS_INT debug; Lisp_Object driver_options; + Lisp_Object compiler_options; gcc_jit_context *ctxt; gcc_jit_type *void_type; gcc_jit_type *bool_type; @@ -4383,6 +4384,23 @@ DEFUN ("comp-native-driver-options-effective-p", } #pragma GCC diagnostic pop +#pragma GCC diagnostic ignored "-Waddress" +DEFUN ("comp-native-compiler-options-effective-p", + Fcomp_native_compiler_options_effective_p, + Scomp_native_compiler_options_effective_p, + 0, 0, 0, + doc: /* Return t if `comp-native-compiler-options' is effective. */) + (void) +{ +#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option) \ + || defined (WINDOWSNT) + if (gcc_jit_context_add_command_line_option) + return Qt; +#endif + return Qnil; +} +#pragma GCC diagnostic pop + static void add_driver_options (void) { @@ -4422,6 +4440,45 @@ add_driver_options (void) #endif } +static void +add_compiler_options (void) +{ + Lisp_Object options = Fsymbol_value (Qnative_comp_compiler_options); + +#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option) \ + || defined (WINDOWSNT) + load_gccjit_if_necessary (true); + if (!NILP (Fcomp_native_compiler_options_effective_p ())) + FOR_EACH_TAIL (options) + gcc_jit_context_add_command_line_option (comp.ctxt, + /* FIXME: Need to encode + this, but how? either + ENCODE_FILE or + ENCODE_SYSTEM. */ + SSDATA (XCAR (options))); +#endif + if (CONSP (options)) + xsignal1 (Qnative_compiler_error, + build_string ("Customizing native compiler options" + " via `comp-native-compiler-options' is" + " only available on libgccjit version 9" + " and above.")); + + /* Captured `comp-native-driver-options' because file-local. */ +#if defined (LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option) \ + || defined (WINDOWSNT) + options = comp.compiler_options; + if (!NILP (Fcomp_native_compiler_options_effective_p ())) + FOR_EACH_TAIL (options) + gcc_jit_context_add_command_line_option (comp.ctxt, + /* FIXME: Need to encode + this, but how? either + ENCODE_FILE or + ENCODE_SYSTEM. */ + SSDATA (XCAR (options))); +#endif +} + DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, Scomp__compile_ctxt_to_file, 1, 1, 0, @@ -4542,6 +4599,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file, #endif add_driver_options (); + add_compiler_options (); if (comp.debug > 1) gcc_jit_context_dump_to_file (comp.ctxt, @@ -5248,6 +5306,7 @@ syms_of_comp (void) DEFSYM (Qnative_comp_speed, "native-comp-speed"); DEFSYM (Qnative_comp_debug, "native-comp-debug"); DEFSYM (Qnative_comp_driver_options, "native-comp-driver-options"); + DEFSYM (Qnative_comp_compiler_options, "native-comp-compiler-options"); DEFSYM (Qcomp_libgccjit_reproducer, "comp-libgccjit-reproducer"); /* Limple instruction set. */