[cfe-dev] stack size issue
Jonny Yu
yingshen.yu at gmail.com
Mon Mar 5 17:59:44 PST 2012
Hi Joerg,
Thanks for the reply. I re-tried with -O0 so the my_assert function isn't inlined and the stack alloc is still 0x120.
Here's how I get the result.
clang -g -O0 -lstdc++ test_stack_alloc.cpp -o test_stack_alloc
otool -t -V test_stack_alloc | c++filt
recurse():
0000000100000cb0 pushq %rbp
0000000100000cb1 movq %rsp,%rbp
0000000100000cb4 subq $0x00000120,%rsp
0000000100000cbb movq 0x00000386(%rip),%rax
0000000100000cc2 movq (%rax),%rax
0000000100000cc5 movq %rax,0xf8(%rbp)
0000000100000cc9 callq check_stack_limit()
0000000100000cce leaq 0xfffffef0(%rbp),%rax
0000000100000cd5 movq 0x000003e4(%rip),%rcx
0000000100000cdc subq %rax,%rcx
0000000100000cdf movq %rcx,0xfffffee8(%rbp)
0000000100000ce6 cmpq $0x0001e100,0xfffffee8(%rbp)
0000000100000cf1 jbe 0x100000cfc
0000000100000cf7 callq my_assert()
0000000100000cfc callq recurse()
0000000100000d01 callq recurse()
0000000100000d06 movq 0x0000033b(%rip),%rax
0000000100000d0d movq (%rax),%rax
0000000100000d10 movq 0xf8(%rbp),%rcx
0000000100000d14 cmpq %rcx,%rax
0000000100000d17 jne 0x100000d26
0000000100000d1d addq $0x00000120,%rsp
0000000100000d24 popq %rbp
0000000100000d25 ret
0000000100000d26 callq 0x100000d94 ; symbol stub for: ___stack_chk_fail
0000000100000d2b nopl 0x00(%rax,%rax)
Here's the LLVM GCC 4.2 .1 generates.
recurse():
0000000100000bc0 pushq %rbp
0000000100000bc1 movq %rsp,%rbp
0000000100000bc4 subq $0x00000110,%rsp
0000000100000bcb movq 0x0000047e(%rip),%rax
0000000100000bd2 movq (%rax),%rax
0000000100000bd5 movq %rax,0xf8(%rbp)
0000000100000bd9 callq check_stack_limit()
0000000100000bde movq 0x000004f3(%rip),%rax
0000000100000be5 leaq 0xfffffef8(%rbp),%rcx
0000000100000bec subq %rcx,%rax
0000000100000bef movq %rax,0xfffffef0(%rbp)
0000000100000bf6 movq 0xfffffef0(%rbp),%rax
0000000100000bfd cmpq $0x0001e100,%eax
0000000100000c03 jbe 0x100000c0a
0000000100000c05 callq my_assert()
0000000100000c0a callq recurse()
0000000100000c0f callq recurse()
0000000100000c14 movq 0x00000435(%rip),%rax
0000000100000c1b movq (%rax),%rax
0000000100000c1e movq 0xf8(%rbp),%rcx
0000000100000c22 cmpq %rcx,%rax
0000000100000c25 jne 0x100000c30
0000000100000c27 addq $0x00000110,%rsp
0000000100000c2e popq %rbp
0000000100000c2f ret
0000000100000c30 callq 0x100000d46 ; symbol stub for: ___stack_chk_fail
0000000100000c35 nopl 0x00(%rax,%rax)
0000000100000c3a nopw 0x00(%rax,%rax)
On Mar 5, 2012, at 9:13 PM, Joerg Sonnenberger wrote:
> On Mon, Mar 05, 2012 at 06:40:47PM +0800, Yingshen Yu wrote:
>> Anyone can explain why clang needs alloc extra 16 bytes stack for the same
>> code?
>
> my_assert is inlined and it uses the additional stack space for the
> arguments.
>
> Joerg
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list