[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Pkg-haskell-maintainers] libffi changes - help needed


Am Donnerstag, den 05.04.2012, 22:18 +0200 schrieb Iustin Pop:
> On Wed, Apr 04, 2012 at 08:15:31PM +0200, Joachim Breitner wrote:
> > Hi,
> > 
> > am I understanding the problem correctly: If one calls a variadic C
> > function with libffi, one should use ffi_prep_cif_variadic() instead of
> > ffi_prep_cif(), otherwise bad things may happen. Whether the function is
> > variadic or not might not be known when looking at the source that calls
> > ffi_prep_cif(), e.g. in the implementation of the Haskell Foreign
> > Function Interface.
> > 
> > In GHC itself, ffi_prep_cif is called
> >  * in ./rts/Adjustor.c when provding Haskell code to C calls; as Haskell
> > functions are never variadic, this is not a problem.
> >  * in ./compiler/ghci/LibFFI.hsc in the Haskell function
> > prepForeignCall, called by generateCCall
> > in ./compiler/ghci/ByteCodeGen.lhs. It seems that this is only relevant
> > for ghci.
> [-other lists]
> Hmm. If ffi_prep_cif is not called by regular (compiled) Haskell code,
> how is such code calling foreign functions? Reading ffi(3), it seems
> that if using ffi_call, one needs to prepare the call either this or
> ffi_prep_cif_variadic, and no way around it.
> Apologies if this is obvious to everyone else :)

Unfortunately, I am not sure. When generating code for a FFI call
("sin"), the assembly looks like this:

        addq $8,%rsp
        movsd 64(%rsp),%xmm0
        subq $8,%rsp
        movq %rax,80(%rsp)
        movl $1,%eax
        call sin
        addq $8,%rsp
        movq 72(%rsp),%rax
        movq %rax,%rdi
        subq $8,%rsp
        movl $0,%eax
        movsd %xmm0,88(%rsp)

so somewhere before, GHC knew the calling convention. I assume it is
just baked in (and hence most likely does not support variadic

On arm, without the native code generator, GHC generates llvm code:

%ln1aM = load double* %lc18u
%ln1aN = call ccc double (double)* @sin( double %ln1aM ) nounwind

so here, LLVM has to know about the calling convention, so not our


Joachim "nomeata" Breitner
Debian Developer
  nomeata@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nomeata@joachim-breitner.de | http://people.debian.org/~nomeata

Attachment: signature.asc
Description: This is a digitally signed message part

Reply to: