lightning
[Top][All Lists]
Advanced

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

Re: [Lightning] How to call varargs functions from lightning in x86_64?


From: Paulo César Pereira de Andrade
Subject: Re: [Lightning] How to call varargs functions from lightning in x86_64?
Date: Tue, 17 Aug 2010 20:21:10 -0300
User-agent: SquirrelMail/1.4.19

Paolo Bonzini wrote:

> Unless you show the failure happens in the call instruction, yes.  The
> problem is that arguments to variadic functions are passed on the
> stack, not in registers.  That's by the way also why prototypes are
> necessary for variadic functions.

  I made a local patch to create a new jit_va_prepare{,_d,f} that would
set a varargs field, and while non zero, would pass arguments on stack.
But that did not work, so I tried to pass both, on stack and on registers,
still no luck.

  Then, I tried the less portable way of directly accessing JIT_SP and
JIT_FP, but that needs setting the value JIT_SP to another register if
using ldx* or stx* because if compiled with -D_ASM_SAFETY (actually,
did not test without :-), it will fail due to using the stack registers.

  Also tried jit_allocai for a more portable way, but still no luck.

  But then, I figured out how to get it to work... Probably this is
Linux/glibc specific, but setting JIT_R0 (%rax) to the number of float
arguments, and passing arguments on registers works, at least for
printf.

  That just required creating a macro for the testing tool, that
now, instead of 'finish @printf', has a macro like:

#if defined(__x86_64__)
#  define printf(count)         \
        movi_ul %r0 count       \
        finish @printf
#else
#  define printf()              \
        finish @printf
#endif


> It's not insurmountable, but it needs a new form of prepare statement
> or something like that.
>
> Paolo

  Now, the test cases works for both, i386 and x86_64.

Thanks,
Paulo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]