This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch i386]: Change stack probing and allocation implementation


2010/9/21 t66667@gmail.com <t66667@gmail.com>:
> On 24/08/2010 5:27 AM, Kai Tietz wrote:
>>
>> 2010/8/23 Richard Henderson<rth@redhat.com>:
>>>
>>> On 08/23/2010 11:38 AM, Kai Tietz wrote:
>>>>
>>>> Well, I tried this first, but then the clobber instruction of stack
>>>> probing getting simply ignored.
>>>
>>> What do you mean by this?
>>
>> I mean, if I use the original value for the rsp adjustment, the
>> register passing in r/eax isn't done any more. The constrain in
>> i386.md is correct, somehow register allocator thinks then it could
>> use a different register (in fact the ABI call register) to pass
>> argument, which is wrong.
>
> After patch and testing.
> RE: PR45694 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45694
> 458496 = ok
> Any number beyond 458496 fails for m64 it simply exit with some error code.
>
> Without GDB: Signal 126 (core dumped)
> With GDB: Program exited with code 06777360.
>
> And yet again m32 is fine.
>
> Both gcc-trunk m64 and m32 test case crash if appending a 0 behind this
> number.
>
> m64:
> #0 ?___chkstk_ms () at libgcc/../gcc/config/i386/cygwin.asm:134
> #1 ?0x000000000045f630 in ?? ()
> #2 ?0x000007fefffa1520 in msvcrt!_Strftime () from
> C:\Windows\system32\msvcrt.dll
> #3 ?0x0000000000401550 in b.2987 ()
> #4 ?0x00000000004015e4 in a ()
> #5 ?0x00000000004015f8 in main ()
> (gdb) disass $pc-30,$pc+30
> Dump of assembler code from 0x402b75 to 0x402bb1:
> ? 0x0000000000402b75 <___chkstk_ms+0>: add ? ?$0x7,%rax
> ? 0x0000000000402b79 <___chkstk_ms+4>: push ? %rcx
> ? 0x0000000000402b7a <___chkstk_ms+5>: and ? ?$0xfffffffffffffff8,%rax
> ? 0x0000000000402b7e <___chkstk_ms+9>: lea ? ?0x10(%rsp),%rcx
> ? 0x0000000000402b83 <___chkstk_ms+14>: ? ? ? ?push ? %rax
> ? 0x0000000000402b84 <___chkstk_ms+15>: ? ? ? ?cmp ? ?$0x1000,%rax
> ? 0x0000000000402b8a <___chkstk_ms+21>: ? ? ? ?jb ? ? 0x402ba5
> <___chkstk_ms+48>
> ? 0x0000000000402b8c <___chkstk_ms+23>: ? ? ? ?sub ? ?$0x1000,%rcx
> => 0x0000000000402b93 <___chkstk_ms+30>: ? ? ? ?orq ? ?$0x0,(%rcx)
> ? 0x0000000000402b97 <___chkstk_ms+34>: ? ? ? ?sub ? ?$0x1000,%rax
> ? 0x0000000000402b9d <___chkstk_ms+40>: ? ? ? ?cmp ? ?$0x1000,%rax
> ? 0x0000000000402ba3 <___chkstk_ms+46>: ? ? ? ?ja ? ? 0x402b8c
> <___chkstk_ms+23>
> ? 0x0000000000402ba5 <___chkstk_ms+48>: ? ? ? ?sub ? ?%rax,%rcx
> ? 0x0000000000402ba8 <___chkstk_ms+51>: ? ? ? ?orq ? ?$0x0,(%rcx)
> ? 0x0000000000402bac <___chkstk_ms+55>: ? ? ? ?pop ? ?%rax
> ? 0x0000000000402bad <___chkstk_ms+56>: ? ? ? ?pop ? ?%rcx
> ? 0x0000000000402bae <___chkstk_ms+57>: ? ? ? ?retq
> ? 0x0000000000402baf <___chkstk+0>: ? ?add ? ?$0x7,%rax
> End of assembler dump.
>
> m32:
> #0 ?__chkstk_ms () at libgcc/../gcc/config/i386/cygwin.asm:46
>
>>
>> For the small sample code:
>>
>> int foo (const char *);
>>
>> int bar (const char *l, const char *r)
>> {
>> ? char *h;
>> ? int i, j,ll;
>> ? for (i=0; l[i]!=0;i++);
>> ? ll = i;
>> ? for (i=0; r[i]!=0;i++);
>> ? ll += i;
>> ? h = __builtin_alloca (ll + 1);
>> ? i = 0; j = 0;
>> ? for (;l[j] != 0; j++, i++) h[i] = l[j];
>> ? for (j=0;r[j] != 0; j++, i++) h[i] = r[j];
>> ? h[i] = 0;
>> ? return foo (h);
>> }
>>
>> gcc produces with posted variant to following allocator code for alloca
>> call:
>>
>> ? ? ? ? leal ? ?1(%r9,%rcx), %eax
>> ? ? ? ? cltq
>> ? ? ? ? addq ? ?$30, %rax
>> ? ? ? ? andq ? ?$-16, %rax
>> ? ? ? ? call ? ?___chkstk_ms
>> ? ? ? ? movzbl ?(%r8), %r9d
>> ? ? ? ? xorl ? ?%r10d, %r10d
>> ? ? ? ? subq ? ?%rax, %rsp
>>
>> with change in allocate_stack (i386.md) as you suggested it produces:
>>
>> ? ? ? ? leal ? ?1(%r9,%rcx), %ecx
>> ? ? ? ? movslq ?%ecx, %rcx
>> ? ? ? ? addq ? ?$30, %rcx
>> ? ? ? ? andq ? ?$-16, %rcx
>> ? ? ? ? call ? ?___chkstk_ms
>> ? ? ? ? movzbl ?(%r8), %r9d
>> ? ? ? ? xorl ? ?%eax, %eax
>> ? ? ? ? xorl ? ?%r10d, %r10d
>> ? ? ? ? subq ? ?%rcx, %rsp
>>
>> As you see, result it wrong. I am not quite sure, why constraints of
>> gen_allocate_stack_worker_probe aren't treated here, but this is the
>> reason, why I did it as I did.
>>
>> Kai
>> Kai
>>
>>
>
>

Well, this is more an issue of stack-space reserved for your
executable. If you use -Wl,--stack,10485760 you will see that it works
even for high values (till the given stack-size).
PE-executables don't have dynamic stack-space. You need to specify
maximum at link time.

Regards,
Kai

-- 
|? (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]