gcc return struct code generation

jose gomez valcarcel jcgv33@yahoo.es
Mon Aug 29 11:41:00 GMT 2011


Hi All,

I'm not sure if this is the right way to ask gcc code generation questions. If so, point me in the righ direction.

This is a simple chunk of c code (z.c):

typedef struct {long x; long y;} point_t;

extern point_t calc (long);

long fn (long m)
{
    point_t p = calc (m);
    return p.x + p.y;
}

When compiled with gcc 4.5.x in an x86_64 arch:

gcc -fPIE -fno-stack-protector -O2 -Wall -std=gnu99 -nostdinc -S z.c

The generated assemble code is this (a cut of fn code):

.globl fn
        .type   fn, @function
fn:
.LFB0:
        .cfi_startproc
        subq    $40, %rsp
        .cfi_def_cfa_offset 48
        call    calc@PLT
        addq    $40, %rsp
        .cfi_def_cfa_offset 8
        leaq    (%rdx,%rax), %rax
        ret
I just read x86_64 ABI code generation, and the result is ok. The struct is returned in registers RAX, RDX. The only disappointing thing is the allocation of 40 stack bytes, whic apparently is not used. This effect cause my kernel code not to mix well with hand-assembler code.

Can anyone give me any advice on this issue? Can I remove this effect with some flags combination?

Thanks in advance for any sugestion.

Regards.



More information about the Gcc-help mailing list