[Git][ghc/ghc][wip/T23568] Define FFI_GO_CLOSURES

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Jun 28 15:38:40 UTC 2023



Ben Gamari pushed to branch wip/T23568 at Glasgow Haskell Compiler / GHC


Commits:
35710a32 by Ben Gamari at 2023-06-28T11:38:34-04:00
Define FFI_GO_CLOSURES

The libffi shipped with Apple's XCode toolchain does not contain a
definition of the FFI_GO_CLOSURES macro, despite containing references
to said macro. Work around this by defining the macro, following the
model of a similar workaround in OpenJDK [1].

[1] https://github.com/openjdk/jdk17u-dev/pull/741/files

- - - - -


7 changed files:

- compiler/GHC/Driver/CodeOutput.hs
- libraries/ghci/GHCi/FFI.hsc
- rts/Interpreter.c
- rts/adjustor/LibffiAdjustor.c
- + rts/include/rts/ghc_ffi.h
- rts/rts.cabal.in
- rts/sm/Storage.c


Changes:

=====================================
compiler/GHC/Driver/CodeOutput.hs
=====================================
@@ -295,7 +295,7 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs
 
             -- wrapper code mentions the ffi_arg type, which comes from ffi.h
             ffi_includes
-              | platformMisc_libFFI $ platformMisc dflags = "#include <ffi.h>\n"
+              | platformMisc_libFFI $ platformMisc dflags = "#include \"ghc_ffi.h\"\n"
               | otherwise = ""
 
         stub_h_file_exists


=====================================
libraries/ghci/GHCi/FFI.hsc
=====================================
@@ -23,6 +23,13 @@
 
 #if !defined(javascript_HOST_ARCH)
 #include <ffi.h>
+
+-- See Note [FFI_GO_CLOSURES workaround] in ghc_ffi.h
+#if darwin_HOST_OS
+#if !defined(FFI_GO_CLOSURES)
+#define FFI_GO_CLOSURES 0
+#endif
+#endif
 #endif
 
 {-# LANGUAGE CPP, DeriveGeneric, DeriveAnyClass #-}


=====================================
rts/Interpreter.c
=====================================
@@ -39,7 +39,7 @@
 #endif
 #endif
 
-#include "ffi.h"
+#include "rts/ghc_ffi.h"
 
 /* --------------------------------------------------------------------------
  * The bytecode interpreter


=====================================
rts/adjustor/LibffiAdjustor.c
=====================================
@@ -11,7 +11,7 @@
 #include "Hash.h"
 #include "Adjustor.h"
 
-#include "ffi.h"
+#include "rts/ghc_ffi.h"
 #include <string.h>
 
 // Note that ffi_alloc_prep_closure is a non-standard libffi closure


=====================================
rts/include/rts/ghc_ffi.h
=====================================
@@ -0,0 +1,28 @@
+/*
+ * <ffi.h> wrapper working around #23586.
+ *
+ * (c) The University of Glasgow 2023
+ *
+ */
+
+#pragma once
+
+#include "ffi.h"
+
+/*
+ * Note [FFI_GO_CLOSURES workaround]
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * Apple ships a broken libffi with Xcode which lacks a definition of
+ * FFI_GO_CLOSURES despite having references to said macro. Work around this
+ * for now to avoid -Wundef warnings.
+ *
+ * We choose the value zero here by following the model of OpenJDK.
+ * See https://github.com/openjdk/jdk17u-dev/pull/741/files.
+ *
+ * See #23568.
+ */
+#if darwin_HOST_OS
+#if !defined(FFI_GO_CLOSURES)
+#define FFI_GO_CLOSURES 0
+#endif
+#endif


=====================================
rts/rts.cabal.in
=====================================
@@ -237,6 +237,7 @@ library
                         rts/EventLogConstants.h
                         rts/EventTypes.h
                         -- ^ generated
+                        rts/ghc_ffi.h
                         rts/Adjustor.h
                         rts/ExecPage.h
                         rts/BlockSignals.h


=====================================
rts/sm/Storage.c
=====================================
@@ -53,7 +53,7 @@
 
 #include <string.h>
 
-#include "ffi.h"
+#include "rts/ghc_ffi.h"
 
 /*
  * All these globals require sm_mutex to access in THREADED_RTS mode.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/35710a3262ab307e4ceb84403c389132ec71a4bf

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/35710a3262ab307e4ceb84403c389132ec71a4bf
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230628/ff5624f5/attachment-0001.html>


More information about the ghc-commits mailing list