-mstrict-align necessary with PPC?

Michael Davidsaver mdavidsaver at gmail.com
Fri Jul 5 16:54:34 UTC 2019


In troubleshooting


two questions have come up.

1. Should all PPC BSPs build with -mstrict-align?

Based on the description in the GCC documentation, I would expect
this to be needed unless the target handles alignment exceptions
to fixup unaligned access.


It looks like some, but not all, RTEMS BSPs provide this flag.
With relevant exceptions being mvme5500 and beatnik.


2. Is/should __builtin_memcpy() assume destination alignment.

We're seeing a fault from a memcpy() when copies a double into an
unaligned byte buffer is optimized to the builtin.

> char *buf = ...;
> double value = ...;
> memcpy(buf, &value, sizeof(value));

In the absence of -mstrict-align this memcpy() is sometimes ("-mcpu=7400 -O3")
optimized to a single "stfd" which faults because 'buf' is not 8 byte aligned.

I feel like there is a bug here.  My question is whether this is the
builtin making an overzealous assumption about destination alignment,
or our usage of memcpy() being incorrect somehow.

My understanding is that memcpy() has no requirements on alignment.

However, it should be noted that we have reports of similar code
faulting after being compiled in MSVC with optimizations enabled.

More information about the users mailing list