[Git][ghc/ghc][master] Document that ccall convention doesn't support varargs
Marge Bot
gitlab at gitlab.haskell.org
Tue Nov 3 04:45:50 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
0b772221 by Ben Gamari at 2020-11-02T23:45:42-05:00
Document that ccall convention doesn't support varargs
We do not support foreign "C" imports of varargs functions. While this
works on amd64, in general the platform's calling convention may need
more type information that our Cmm representation can currently provide.
For instance, this is the case with Darwin's AArch64 calling convention.
Document this fact in the users guide and fix T5423 which makes use of a
disallowed foreign import.
Closes #18854.
- - - - -
5 changed files:
- docs/users_guide/exts/ffi.rst
- testsuite/tests/rts/T5423.hs
- testsuite/tests/rts/T5423.stdout
- testsuite/tests/rts/T5423_c.c
- testsuite/tests/rts/T5423_cmm.cmm
Changes:
=====================================
docs/users_guide/exts/ffi.rst
=====================================
@@ -83,6 +83,21 @@ For more details on the implementation see the Paper:
Last known to be accessible `here
<https://www.microsoft.com/en-us/research/wp-content/uploads/2004/09/conc-ffi.pdf>`_.
+Varargs not supported by ``ccall`` calling convention
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Note that functions requiring varargs arguments are unsupported by the ``ccall``
+calling convention. Foreign imports needing to call such functions should rather
+use the ``capi`` convention, giving an explicit signature for the needed
+call-pattern. For instance, one could write: ::
+
+ foreign import "capi" "printf"
+ my_printf :: Ptr CChar -> CInt -> IO ()
+
+ printInt :: CInt -> IO ()
+ printInt n = my_printf "printed number %d" n
+
+
.. _ffi-ghcexts:
GHC extensions to the FFI Chapter
=====================================
testsuite/tests/rts/T5423.hs
=====================================
@@ -1,3 +1,5 @@
+-- | Verify that @foreign import prim@ calls with more than 10 arguments
+-- are lowered correctly.
{-# LANGUAGE MagicHash, GHCForeignImportPrim, UnliftedFFITypes #-}
=====================================
testsuite/tests/rts/T5423.stdout
=====================================
@@ -1,2 +1,2 @@
-111 112 113 114 115 116 117 118 119 120
+111 112 113 114 115 116 117 118 119 120
120
=====================================
testsuite/tests/rts/T5423_c.c
=====================================
@@ -1,6 +1,34 @@
+#include <Rts.h>
#include <stdio.h>
void flush_stdout(void)
{
fflush(stdout);
}
+
+void print_it(
+ StgWord r1,
+ StgWord r2,
+ StgWord r3,
+ StgWord r4,
+ StgWord r5,
+ StgWord r6,
+ StgWord r7,
+ StgWord r8,
+ StgWord r9,
+ StgWord r10
+ )
+{
+ printf("%" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word
+ " %" FMT_Word "\n",
+ r1, r2, r3, r4, r5,
+ r6, r7, r8, r9, r10);
+}
=====================================
testsuite/tests/rts/T5423_cmm.cmm
=====================================
@@ -10,7 +10,6 @@ test (W_ r1,
W_ r9,
W_ r10)
{
- foreign "C" printf("%d %d %d %d %d %d %d %d %d %d\n",
- r1, r2, r3, r4, r5, r6, r7, r8, r9, r10);
+ foreign "C" print_it(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10);
return (r10);
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b7722219ffdb109c3a8b034a8e112d18e6e4336
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0b7722219ffdb109c3a8b034a8e112d18e6e4336
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/20201102/f902c515/attachment-0001.html>
More information about the ghc-commits
mailing list