tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] BUG: called function should pop the arguments when us


From: 张博洋
Subject: Re: [Tinycc-devel] BUG: called function should pop the arguments when using fastcall
Date: Wed, 30 Aug 2017 01:38:08 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Hello,

I tested this on Linux myself, according to gcc doc, the behavior should be same as windows: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html

fastcall

    On x86-32 targets, the fastcall attribute causes the compiler to pass the 
first argument (if of integral type) in the register ECX and the second 
argument (if of integral type) in the register EDX. Subsequent and other typed 
arguments are passed on the stack. The called function pops the arguments off 
the stack. If the number of arguments is variable all arguments are pushed on 
the stack.

   I also tested with a simple C source code:
int __attribute__ ((fastcall)) test(int a, int b, int c, int d, int e)
{
    return a - b + c + d + e;
}
   GCC generated the following assembly:

Disassembly of section .text:

00000000 <test>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 08                sub    $0x8,%esp
   6:   89 4d fc                mov    %ecx,-0x4(%ebp)
   9:   89 55 f8                mov    %edx,-0x8(%ebp)
   c:   8b 45 f8                mov    -0x8(%ebp),%eax
   f:   8b 55 fc                mov    -0x4(%ebp),%edx
  12:   29 c2                   sub    %eax,%edx
  14:   8b 45 08                mov    0x8(%ebp),%eax
  17:   01 c2                   add    %eax,%edx
  19:   8b 45 0c                mov    0xc(%ebp),%eax
  1c:   01 c2                   add    %eax,%edx
  1e:   8b 45 10                mov    0x10(%ebp),%eax
  21:   01 d0                   add    %edx,%eax
23: c9 leave 24: c2 0c 00 ret $0xc

  The "ret $0xc" indicates that the behavior is same as windows.



Zhang Boyang





在 2017年08月23日 20:42, grischka 写道:
张博洋 wrote:
Hello,

I found that TCC implement 'fastcall' that the calling function pops arguments. However, according to MSDN (https://msdn.microsoft.com/en-us/library/6xa169sk.aspx), the called function should pop arguments when using fastcall. I provided a patch and I have already pushed it to the mob branch, since I'm new to TCC and compilers, please review my patch carefully. I also wrote a test case which is in attachments, you may use the testcase to discover the problem.

Did someone try this on Linux?  The wanted behavior might be different.

-- gr


  Thanks

Zhang Boyang

_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel



reply via email to

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