__attribute__((naked) on x86 would be useful

Mat Hostetter mat@curl.com
Mon Feb 16 14:56:00 GMT 2004


>>>>> "rth" == Richard Henderson <rth@redhat.com> writes:

 rth> Certainly the compiler can handle this ---

 >> My main use for this is for some small machine-generated assembly
 >> language trampolines that implement multiple inheritance
 >> (e.g. offset a "self" parameter and jump elsewhere)...

 rth> all by itself at -O2.

OK, fair question.  I tried this:

extern int bar (int x, int y, int z, double q, float r);
int
foo (int x, int y, int z, double q, float r)
{
  return bar (x + 16, y, z, q, r);
}

gcc -O2 does figure out the tail call, which is nice, but it turns
what I'd like to be two instructions:

        addl $16,4(%esp)
        jmp bar

into seven:

foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        addl    $16, %eax
        movl    %eax, 8(%ebp)
        leave
        jmp     bar

I also tried -fomit-frame-pointer, but unfortunately that kills the
tail call optimization.

Interestingly, that movl/addl/movl in the middle there could just as
well be one instruction.  Perhaps there is a missing peephole
optimization, or something is missed in the interaction between tail
calls and peephole optimizations.

 rth> In any case, there's still zero chance that such a patch will be
 rth> written or accepted.

OK, I can see why you dislike it.  Is there any plausible extension
that would give me what I want?  I'd guess the need to write a proc
entirely in assembly while avoiding the irksome boilerplate issues has
come up before.  Maybe some extension to top-level "asm" that lets you
direct gcc to emit the proc boilerplate?  Something like this:

    asm __attribute__((proc ("my_proc_name")))

Also, is there any chance gcc could "forget" the current asm section
when it emits user assembly code, since that assembly may change the
section behind its back?  I haven't checked, but that sounds like a
one-line fix somewhere.  Alternatively, supporting a syntax like this:

    asm __attribute__((section ("text")))

would work.

-Mat



More information about the Gcc mailing list