[Git][ghc/ghc][wip/T23568] Define FFI_GO_CLOSURES
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Wed Jun 28 20:10:42 UTC 2023
Ben Gamari pushed to branch wip/T23568 at Glasgow Haskell Compiler / GHC
Commits:
cbe8a3b4 by Ben Gamari at 2023-06-28T16:10: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 \"rts/ghc_ffi.h\"\n"
| otherwise = ""
stub_h_file_exists
=====================================
libraries/ghci/GHCi/FFI.hsc
=====================================
@@ -22,6 +22,14 @@
-}
#if !defined(javascript_HOST_ARCH)
+-- See Note [FFI_GO_CLOSURES workaround] in ghc_ffi.h
+-- We can't include ghc_ffi.h here as we must build with stage0
+#if darwin_HOST_OS
+#if !defined(FFI_GO_CLOSURES)
+#define FFI_GO_CLOSURES 0
+#endif
+#endif
+
#include <ffi.h>
#endif
=====================================
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
+
+/*
+ * 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
+
+#include "ffi.h"
=====================================
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/cbe8a3b46303174d6b0da3e19a83b471b5242530
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cbe8a3b46303174d6b0da3e19a83b471b5242530
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/c5d17d26/attachment-0001.html>
More information about the ghc-commits
mailing list