Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22207

Why gcc -O0 allocating extra space for local variable (16 instead of 8 bytes)?

$
0
0

I have written simple function in C,

void GetInput(){    char buffer[8];    gets(buffer);    puts(buffer);}

When I disassemble it in gdb's disassembler, it gives following disassembly.

   0x08048464 <+0>: push   %ebp   0x08048465 <+1>: mov    %esp,%ebp   0x08048467 <+3>: sub    $0x10,%esp   0x0804846a <+6>: mov    %gs:0x14,%eax   0x08048470 <+12>:    mov    %eax,-0x4(%ebp)   0x08048473 <+15>:    xor    %eax,%eax=> 0x08048475 <+17>:    lea    -0xc(%ebp),%eax   0x08048478 <+20>:    mov    %eax,(%esp)   0x0804847b <+23>:    call   0x8048360 <gets@plt>   0x08048480 <+28>:    lea    -0xc(%ebp),%eax   0x08048483 <+31>:    mov    %eax,(%esp)   0x08048486 <+34>:    call   0x8048380 <puts@plt>   0x0804848b <+39>:    mov    -0x4(%ebp),%eax   0x0804848e <+42>:    xor    %gs:0x14,%eax   0x08048495 <+49>:    je     0x804849c <GetInput+56>   0x08048497 <+51>:    call   0x8048370 <__stack_chk_fail@plt>   0x0804849c <+56>:    leave     0x0804849d <+57>:    ret    

Now please look at line number three, 0x08048467 <+3>: sub $0x10,%esp, I have only 8 bytes allocated as local variable, then why compiler is allocating 16 bytes(0x10).

Secondly, what is meaning of xor %gs:0x14,%eax.

If it is optimization, is there any way to stop it.


Viewing all articles
Browse latest Browse all 22207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>