]> git.eshelyaron.com Git - emacs.git/commitdiff
Pass driver options to libgccjit where supported
authorAndreas Fuchs <asf@boinkor.net>
Sat, 8 Aug 2020 20:22:43 +0000 (16:22 -0400)
committerAndrea Corallo <akrl@sdf.org>
Wed, 19 Aug 2020 15:12:21 +0000 (17:12 +0200)
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.

lisp/emacs-lisp/comp.el
src/comp.c

index 3176351b37db179c5f196009e8fb7ea4357d0f6a..37559c20dd42cfa5c280492f84ea206b838e1658 100644 (file)
@@ -134,6 +134,16 @@ before compilation.  Usable to modify the compiler environment."
   :type 'list
   :group 'comp)
 
+(defcustom comp-native-driver-options nil
+  "Options passed verbatim to the native compiler's backend driver.
+Note that not all options are meaningful; typically only the options
+affecting the assembler and linker are likely to be useful.
+
+Passing these options is only available in libgccjit version 9
+and above."
+  :type 'list
+  :group 'comp)
+
 (defvar comp-dry-run nil
   "When non nil run everything but the C back-end.")
 
index a00088bb7f8c91de493958144ffe212bdec7cf67..97a566587075c76bd23266041be54a24830fc427 100644 (file)
@@ -54,6 +54,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #undef gcc_jit_block_end_with_return
 #undef gcc_jit_block_end_with_void_return
 #undef gcc_jit_context_acquire
+#undef gcc_jit_context_add_driver_option
 #undef gcc_jit_context_compile_to_file
 #undef gcc_jit_context_dump_reproducer_to_file
 #undef gcc_jit_context_dump_to_file
@@ -119,6 +120,8 @@ DEF_DLL_FN (const char *, gcc_jit_context_get_first_error,
 DEF_DLL_FN (gcc_jit_block *, gcc_jit_function_new_block,
             (gcc_jit_function *func, const char *name));
 DEF_DLL_FN (gcc_jit_context *, gcc_jit_context_acquire, (void));
+DEF_DLL_FN (void, gcc_jit_context_add_driver_option,
+            (gcc_jit_context *ctxt, const char *optname));
 DEF_DLL_FN (gcc_jit_field *, gcc_jit_context_new_field,
             (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_type *type,
              const char *name));
@@ -256,6 +259,7 @@ init_gccjit_functions (void)
   LOAD_DLL_FN (library, gcc_jit_block_end_with_return);
   LOAD_DLL_FN (library, gcc_jit_block_end_with_void_return);
   LOAD_DLL_FN (library, gcc_jit_context_acquire);
+  LOAD_DLL_FN (library, gcc_jit_context_add_driver_option);
   LOAD_DLL_FN (library, gcc_jit_context_compile_to_file);
   LOAD_DLL_FN (library, gcc_jit_context_dump_reproducer_to_file);
   LOAD_DLL_FN (library, gcc_jit_context_dump_to_file);
@@ -317,6 +321,7 @@ init_gccjit_functions (void)
 #define gcc_jit_block_end_with_return fn_gcc_jit_block_end_with_return
 #define gcc_jit_block_end_with_void_return fn_gcc_jit_block_end_with_void_return
 #define gcc_jit_context_acquire fn_gcc_jit_context_acquire
+#define gcc_jit_context_add_driver_option fn_gcc_jit_context_add_driver_option
 #define gcc_jit_context_compile_to_file fn_gcc_jit_context_compile_to_file
 #define gcc_jit_context_dump_reproducer_to_file fn_gcc_jit_context_dump_reproducer_to_file
 #define gcc_jit_context_dump_to_file fn_gcc_jit_context_dump_to_file
@@ -4117,6 +4122,26 @@ DEFUN ("comp--release-ctxt", Fcomp__release_ctxt, Scomp__release_ctxt,
   return Qt;
 }
 
+static void
+add_driver_options ()
+{
+  Lisp_Object options = Fsymbol_value (Qcomp_native_driver_options);
+
+#ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option
+  while (CONSP (options))
+    {
+      gcc_jit_context_add_driver_option (comp.ctxt, SSDATA (XCAR (options)));
+      options = XCDR (options);
+    }
+#else
+  if (CONSP (options))
+    {
+      xsignal1 (Qnative_compiler_error,
+                build_string ("Customizing native compiler options via `comp-native-driver-options' is only available on libgccjit version 9 and above."));
+    }
+#endif
+}
+
 static void
 restore_sigmask (void)
 {
@@ -4186,6 +4211,8 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
   for (ptrdiff_t i = 0; i < func_h->count; i++)
     compile_function (HASH_VALUE (func_h, i));
 
+  add_driver_options ();
+
   if (COMP_DEBUG)
       gcc_jit_context_dump_to_file (comp.ctxt,
                                    format_string ("%s.c", SSDATA (base_name)),
@@ -4992,6 +5019,7 @@ native compiled one.  */);
 
   DEFSYM (Qcomp_speed, "comp-speed");
   DEFSYM (Qcomp_debug, "comp-debug");
+  DEFSYM (Qcomp_native_driver_options, "comp-native-driver-options");
 
   /* Limple instruction set.  */
   DEFSYM (Qcomment, "comment");