riscv32 : -mno-strict-align has no effect

Jim Wilson jimw@sifive.com
Mon Jan 20 22:24:00 GMT 2020

On Sun, Jan 19, 2020 at 5:39 PM Alex Rocha Prado <alex.prado@nxp.com> wrote:
> It happens that both line generate the same code, so there is some kind of problem with gcc, correct ?

-mno-strict-align does have an effect, but it isn't very useful.  The
problem here is that gcc knows that the target does not support
unaligned accesses, so it is refusing to produce them even when
-mno-strict-align is used.  Unfortunately, the only supported target
with unaligned accesses is the fake -mtune=size target, which exists
only for use with the -Os option.  So if you use -mtune=size
-mno-strict-align you can get the result you probably want.  However,
I wouldn't recommend doing that, as I can't guarantee that -mtune=size
will work the same in the future.  If you do have a target that
supports unaligned accesses, then you should add support for that
target to gcc, and then using -mtune=yourtarget -mno-strict-align will
work.  If you don't have a target that supports unaligned accesses,
then why do you want the compiler to emit broken code?

This alignment stuff should probably be rewritten at some point to
make the usage of the options more obvious, but I have no idea when
that will happen.  At the moment, there is no incentive, as gcc
doesn't have support for any RISC-V targets that support unaligned


More information about the Gcc-help mailing list