I have a file called "main.c":
-- main.c ------------------------------------------
int main(void) {
int i, j;
for (i = 0; i < 10; i ++)
j = 5;
return 0;
}
----------------------------------------------------
When I compile it with "gcc -O1 -c -o main.o main.c" and I do an
"objdump -d main.o" I get:
------------------------------------------------------
main.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <main>:
0: 31 c0 xor %eax,%eax
2: c3 retq
------------------------------------------------------
But when I try to use just only one optimization flag by compiling with
"gcc -ftree-dce -c -o main.o main.c" the optimization flag seems to do
nothing at all:
------------------------------------------------------
main.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <main>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
b: eb 0b jmp 18 <main+0x18>
d: c7 45 f8 05 00 00 00 movl $0x5,-0x8(%rbp)
14: 83 45 fc 01 addl $0x1,-0x4(%rbp)
18: 83 7d fc 09 cmpl $0x9,-0x4(%rbp)
1c: 7e ef jle d <main+0xd>
1e: b8 00 00 00 00 mov $0x0,%eax
23: c9 leaveq
24: c3 retq
------------------------------------------------------
And even if I specify all the optimization flags that are enabled by -O1
I get the same previous objdump. What am I doing wrong?
Thank you,
--
Juan Alonso