This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: PATCH for insn_data.genfun and usage


>  In message <199909241856.LAA30616@dilithium.transmeta.com>you write:
>   > The typedef is used to declare the pointers to the instruction
>   > generators in the insn_data struct.  But the callees are not variadic.
>   > In my picoJava gcc world, omitting the prototype is fine and just
>   > leads to slightly poorer code, but being explicit and wrong damages
>   > the stack.
> That sounds like a rather poorly designed ABI.  Why precisely are
> your stacks getting damaged? 

GCC and the binutils can deal with the problem now, but I believe that
the patch is still useful.

In picoJava, after executing a call with 3 arguments, the frame looks
like this (from high to low)

(vars+0)      vars-> arg0
(vars+4)	     arg1
(vars+8)	     arg2
(vars+12)	     old vars
(vars+16)	     old pc
(vars+20)      optop->

The callee makes space for automatics by moving optop down.  If the
callee expects no arguments, it would imagine the frame looked like

(vars+0)      vars-> old vars
(vars+4)	     old pc
(vars+8)      optop->auto0
(vars+12)	     auto1
(vars+16)	     auto2

The callee could write to the auto2 and trash the return address.
Similar problems happen if the caller sends to few arguments instead.

Argument mismatches aren't a problem when the callee has been defined
varadic, since the callee has to examine optop and vars and move the
variable arguments from the opstack onto the aggregate stack (because
values in the opstack can't have their address taken).

When I submitted the patch, the binutils couldn't cope when the callee
and caller's argument counts were incompatible.  My recent binutils
patches (not yet accepted) generate little thunk routines to clean up
when incompatible calls are made.

I've not finished implementing the full ABI in all the tools.  In the
picoJava-II Programmer's Reference Manual, section 9.6 "Handling of
Argument Mismatches" describes a different mechanism, solving the
problem by getting the compiler to generate two entry points per
function (one checking and one trusting) and getting the linker to
point calls to the right function.

I would be surprised if declaring a function as varadic and then not
defining it so is guaranteed to give a defined result.  Though the
picoJava self hosting doesn't need the patch any more and even if the
code is valid as it stands, I think that the patch or something
similar is a (tiny) step to cleaner code.

Steve


> 
>   > These patches add typedefs for the four different signatures uses of
>   > insn_gen_fn, replaces the GEN_FCN macro with GEN_FCN_<n> macros, and
>   > change all the uses in the source of GEN_FCN to the appropriate
>   > GEN_FCN_<n>.
> This may still be a reasonable thing to do, but I don't want to do it 
> simply to work around a poorly designed ABI.  It would need to stand on
> its own.
> 
> jeff


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