gcc optimization??
Posted: Thu Aug 19, 2004 7:13 am
Hello all,
I tried to write a simple program in C (prints "hello world") and disassembled the same using -S option in GCC. The output of the file seems to be so huge than just pushing the variables into the stack, calling the printf function and clearing the stack. Can any one explain me, why is this so? I have seen the output of some other version which seems to be so simple.
And also some other query. The program calls the "printf" function. But, the output code doesn't seems to have the printf function. ??? Does the printf function is called during the run-time? (some function related to OS). I am using the GCC version 3.2.
Any help greately appreciated.
I tried to write a simple program in C (prints "hello world") and disassembled the same using -S option in GCC. The output of the file seems to be so huge than just pushing the variables into the stack, calling the printf function and clearing the stack. Can any one explain me, why is this so? I have seen the output of some other version which seems to be so simple.
And also some other query. The program calls the "printf" function. But, the output code doesn't seems to have the printf function. ??? Does the printf function is called during the run-time? (some function related to OS). I am using the GCC version 3.2.
Any help greately appreciated.
Code: Select all
#include<stdio.h>
int main()
{
printf("Hello World");
return 0;
}
Code: Select all
1 .file "test.c"
2 .section .rodata
3 .LC0:
4 .string "Hello world"
5 .text
6 .align 2
7 .globl main
8 .type main,@function
9 main:
10 pushl %ebp
11 movl %esp, %ebp
12 subl $8, %esp
13 andl $-16, %esp
14 movl $0, %eax
15 subl %eax, %esp
16 subl $12, %esp
17 pushl $.LC0
18 call printf
19 addl $16, %esp
20 movl $0, %eax
21 leave
22 ret
23 .Lfe1:
24 .size main,.Lfe1-main
25 .ident "GCC: (GNU) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)"