I am particularly interested about the placement of these 3 assembly instructions in 'main' function and the way it changes the stack memory layout shown in Table 2.2, page 11 of http://www.uclibc.org/docs/psABI-i386.pdf. This layout shows that first argument of the called function is at offset of +8 bytes wrt the frame pointer (%ebp) of the called function.
Considering the first few assembly instructions generated for the 'main' function given in the first email: lea 0x4(%esp), %ecx and 0xfffffff0, %esp pushl -0x4(%ecx) push %ebp mov %esp, %ebp 'and' instruction changes the stack pointer value and 'pushl' instruction pushes the return address of the function (that called 'main') at the location pointed by this new stack pointer value. Then frame pointer of the function (that called 'main') is pushed on stack and new frame pointer for 'main' function is set. The return address of the calling function is still at +4 byte offset wrt to new frame pointer (%ebp) of 'main' function. However, now the first argument of 'main' function may not be at +8 byte offset wrt to the new frame pointer of the 'main' function. Is it acceptable from ABI point of view? On Mon, Oct 12, 2015 at 1:22 PM, Stefan Ring <stefan...@gmail.com> wrote: > On Mon, Oct 12, 2015 at 1:06 PM, Abhishek Aggarwal > <abhiinnit...@gmail.com> wrote: >> @Jonathan: The reason I started this discussion is due to my suspicion >> of a potential bug in gcc-4.9.2. However, I may be wrong. Here is the >> explanation: > > I think everything is alright. The code is only emitted for the main > function, and the stack is assumed to be aligned for every other > function. This is probably done because of compatibility > considerations with older environments. > > So you can rename your function and watch the instructions disappear.