tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] x86_64: second struct va_arg fails


From: shinichiro hamaji
Subject: Re: [Tinycc-devel] x86_64: second struct va_arg fails
Date: Tue, 28 Dec 2010 20:09:18 +0900

Hi,

I pushed a patch which fixes this issue. I confirmed this only for
a trivial case (the test case by Henry) so we may need further tests.

http://repo.or.cz/w/tinycc.git/commitdiff/0ed7ba3f5e79f407a206b387079c9fd68327064b

> Maybe you can use a support function in combination with a builtin.
> This would keep the generated code reasonably small and most of the
> logic could be in convenient C.  Such as:
>
> in stdarg.h:
>  #define va_arg(ap,type) *(type)*__va_arg(ap, __builtin_va_type(type))
> and in libtcc1.c:
>  enum va_type { va_reg, va_double, va_aggregate, ... };
>  void *__va_arg(va_list ap, int va_type)
>  {
>    switch(va_type) [
>    ...

Thanks for the suggestion! I've used this approach. Now we could remove
__builtin_malloc and __builtin_free by moving stdarg code into libtcc1.
IMO the new code structure would be better. I touched win64-only code
in tcctok.h but I didn't confirm the change is OK. Could you kindly check
my patches are working on win64?

> Btw, I was wondering whether alignment '4' for structures is correct.
> Basically registers and mmx would possibly go on top of some structure
> in the overflow_area when the register space is used up.  There could
> also be doubles in a structure.  Just wondering.

Good point! If I remember correctly, I didn't use operations which
require alignments
(such as movaps) in TCC, but 8 bytes alignment would be much better because it
seems http://www.x86-64.org/documentation/abi.pdf says we need the 8 bytes
alignment and this would improve ABI compatibility with GCC.

BTW, we need more efforts to make TCC's ABI compatible with GCC's ABI.
For example,

#include <stdlib.h>
int main() {
  div_t r = div(42, 5);
  printf("%d %d\n", r.quot, r.rem);
}

shows weird value with TCC on x86-64 linux... I'll try fixing this
this year-end,
but I'm not sure if I can finish this task as x86-64's ABI around structures
is complicated :(

Thanks!



reply via email to

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