Hi Jeff,

On 07/03/18 17:02, Jeff Law wrote:
On 03/06/2018 08:21 AM, Renlin Li wrote:
Hi all,

The problem described here probably only affects targets whose ABI allow
to pass structured
arguments of certain size via registers.

If the mode of the parameter type is BLKmode, in the callee, during RTL
a stack slot will be reserved for this parameter, and the incoming value
will be copied into
the stack slot.

However, the stack slot for the parameter will not be aligned if the
alignment of parameter type
Chances are, unaligned memory access might cause run-time errors.
My recollection here (the PA has a ABI which mandates this kind of
stuff) is that you have to copy the object out of the potentially
unaligned location into a suitably aligned local.

The copy should be occurring in an alignment safe way.  It also has to
handle structures that are partially in registers, partially in memory
and structures which are justified in the wrong direction.

Yes, I also realize this as well. This is a case in arm pcs.
So indeed, the copy of parameter on the stack should also be aligned.

We never tried to optimize this stuff.  It was rare enough to not worry

From what I have observed, yes, gcc doesn't do any optimization regarding this.
For the following code without special alignment requirement.

#include <stdint.h>
struct U {
    uint32_t M0;
    uint32_t M1;

void tmp (struct U *);
void foo(struct U P0)
  struct U P1 = P0;
  tmp (&P1);

void bar(struct U P0)
  tmp (&P0);

int __attribute__ ((noinline)) x (struct U p)
  return p.M1;

in arm code-generation, the address return by foo function is 16-byte aligned.
It is because P1 is a local stack var, and its stack slot is aligned. There
is a copy operation to copy the data from stack slot of the parameter into the 
slot of the local variable.

The process is:
store r0-r1 into stack_slot_for_parm (this will be unaligned if large alignment 
is required)
load r0-r1 from stack_slot_for_parm
store r0-r1 into stack_slot_for_p1 (aligned)

For bar function, the address returned is the stack slot address for parameter 
copy, which could be not aligned.

In function x, to get the return value, it will load the data from the stack 
slot for parameter after
the parameter is saved into stack.



Reply via email to