Prologue and Epilogue removed GCC Optimization

Taking an empty program

//demo.c

int main(void)
{

}

Compilation of the program with optimization by default.

gcc -S  demo.c -o dasm.asm 

I get assembly output as

//Removed labels and directive which are not relevant

main:

pushl   %ebp                  // prologue of main
movl    %esp, %ebp            // prologue of main
popl    %ebp                  // epilogue of main
ret

Now compiling the program with optimization -O2.

gcc -O2 -S  demo.c -o dasm.asm 

I get optimized build

main:

rep
ret

In my initial search, I found that the optimization flag -fomit-frame-pointer is responsible for removing the prolog and epilogue.

I found additional flag information in the gcc compiler . But I could not understand this reason below in the manual for deleting the prologue and epilogue.

Do not keep the frame pointer in register for functions that one does not need.

Is there any other way to put the above reason?

What is the reason for the instruction "rep"that appears when optimizing -02?

?

, ?

?

+5
1

, , , , , main(), .

rep ret:

. , , . , , .

AMD , ret , , ret . , ret , .

"rep ret", -, , . "Rep" .

: , google , .

, , , , , , .

, /, . , , , , . Visual Studio :

__declspec(naked)
+5

All Articles