This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc-4.9.2: Assembly for i386 Target

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 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 <> wrote:
> On Mon, Oct 12, 2015 at 1:06 PM, Abhishek Aggarwal
> <> 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]