See the disassembly of the unoptimized & optimized executables produced by GCC!!! :)
run.out (inside of the attachment): -------------------------------------------------------------------------------- #!/bin/sh cat $0 echo "" gcc --version # # Unoptimized # gcc -Wall -S arr.c # to see arr.s mv arr.s arr1.s cat arr1.s echo "" gcc -Wall -ggdb2 arr.c echo "" gdb --quiet --command=arr.gdb a.out echo "" rm -f a.out # # Optimized (-Os) # gcc -Wall -Os -S arr.c # to see arr.s mv arr.s arr2.s cat arr2.s echo "" gcc -Wall -Os -ggdb2 arr.c echo "" gdb --quiet --command=arr.gdb a.out echo "" rm -f a.out gcc (GCC) 3.3.5 20040804 (prerelease) Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. arr.c: In function `main': arr.c:7: warning: unused variable `arr' .file "arr.c" .section .rodata .LC0: .string "%d\n" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $1073741848, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp movl $268435455, 4(%esp) movl $.LC0, (%esp) call printf movl $0, %eax leave ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.3.5 20040804 (prerelease)" arr.c: In function `main': arr.c:7: warning: unused variable `arr' Using host libthread_db library "/lib/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. main () at arr.c:8 8 printf("%d\n",SIZE);Line 8 of "arr.c" starts at address 0x8048377 <main+19> and ends at 0x804838b <main+39>.
Dump of assembler code for function main: 0x08048364 <main+0>: push %ebp 0x08048365 <main+1>: mov %esp,%ebp 0x08048367 <main+3>: sub $0x40000018,%esp 0x0804836d <main+9>: and $0xfffffff0,%esp 0x08048370 <main+12>: mov $0x0,%eax 0x08048375 <main+17>: sub %eax,%esp 0x08048377 <main+19>: movl $0xfffffff,0x4(%esp) 0x0804837f <main+27>: movl $0x8048464,(%esp) 0x08048386 <main+34>: call 0x8048288 <_init+56> 0x0804838b <main+39>: mov $0x0,%eax0x08048390 <main+44>: leave 0x08048391 <main+45>: ret End of assembler dump.
Stack level 0, frame at 0xbffff770: eip = 0x8048377 in main (arr.c:8); saved eip 0x40036936 source language c. Arglist at 0xbffff768, args: Locals at 0xbffff768, Previous frame's sp is 0xbffff770 Saved registers: ebp at 0xbffff768, eip at 0xbffff76c arr.c: In function `main': arr.c:7: warning: unused variable `arr' .file "arr.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "%d\n" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $1073741824, %esp pushl $268435455 pushl $.LC0 call printf leave xorl %eax, %eax ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.3.5 20040804 (prerelease)" arr.c: In function `main': arr.c:7: warning: unused variable `arr' Using host libthread_db library "/lib/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. main () at arr.c:8 8 printf("%d\n",SIZE);Line 8 of "arr.c" starts at address 0x804836d <main+9> and ends at 0x804837c <main+24>.
Dump of assembler code for function main: 0x08048364 <main+0>: push %ebp 0x08048365 <main+1>: mov %esp,%ebp 0x08048367 <main+3>: sub $0x40000000,%esp 0x0804836d <main+9>: push $0xfffffff 0x08048372 <main+14>: push $0x8048444 0x08048377 <main+19>: call 0x8048288 <_init+56>0x0804837c <main+24>: leave 0x0804837d <main+25>: xor %eax,%eax 0x0804837f <main+27>: ret End of assembler dump.
Stack level 0, frame at 0xbffff770: eip = 0x804836d in main (arr.c:8); saved eip 0x40036936 source language c. Arglist at 0xbffff768, args: Locals at 0xbffff768, Previous frame's sp is 0xbffff770 Saved registers: ebp at 0xbffff768, eip at 0xbffff76c -------------------------------------------------------------------------------- Bye-bye :)
huge_array_in_stack_crashes.tar.gz
Description: application/gzip