This is the mail archive of the
mailing list for the GCC project.
Re: gcc-4.9.2: Assembly for i386 Target
- From: Abhishek Aggarwal <abhiinnitald at gmail dot com>
- To: Stefan Ring <stefanrin at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 13 Oct 2015 09:55:49 +0200
- Subject: Re: gcc-4.9.2: Assembly for i386 Target
- Authentication-results: sourceware.org; auth=none
- References: <CAGy+Z4jBeMpFEJ6qmPtHbK9c1sbNvhJcNKS=ARcikgSBhHLzvg at mail dot gmail dot com> <CAH6eHdRY+XxKxZ3JBPcgohQB1W4MaP1e3H6gmYD-2JMCJxAwPQ at mail dot gmail dot com> <CAGy+Z4gtx6Y2Oibp9TQr3FQ+9Go8PrrhzPORcpNDJhocZgGjVA at mail dot gmail dot com> <CAGy+Z4gy853bjecTVaKad19bCB3UmSe+qO1XZcaPG26hy0gGhw at mail dot gmail dot com> <CAGy+Z4j=AYJPHzKjBPsVhun4-YUSkz5AeMrubQxyRoAzuo0uDA at mail dot gmail dot com> <CAAxjCExKzjPurVWo3vHTu9mtpsDi8S5yFKDp4hMdrciPaOUtKQ at mail dot gmail dot com>
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
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 <firstname.lastname@example.org> wrote:
> On Mon, Oct 12, 2015 at 1:06 PM, Abhishek Aggarwal
> <email@example.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
> 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.