This is the mail archive of the gcc@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: aliasing problem with va_arg


The sparc ABI does not align double-word arguments to a double-word boundary.
The sparc ldd instruction requires double-word alignment.  Thus we can't use
an ldd instruction to access a double-word value from the argument list because
it might not be properly aligned.  In any other case, a double-word value
will be double-word aligned.

We do want to use the ldd instruction for performance reasons, so the sparc
port is careful to make sure doubles are word-aligned.  We have to handle the
case of arguments specially though.  There is code in assign_parms in
function.c that will allocate a new stack slot and copy a parameter into it
if the place where it was passed was not sufficiently aligned.
      /* If we can't trust the parm stack slot to be aligned enough
         for its ultimate type, don't use that slot after entry.
         We'll make another stack slot, if we need one.  */

For stdarg/varargs, we make this work by explicitly copying one word at a time
into a double-word aligned temporary buffer, and then copying the double-word
out of the temporary buffer.

If there was a syntax for declaring a pointer to unaligned data, we could
perhaps solve the problem by using that in the va_arg macro.

Jim


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