altos/arm: Align data so that gcc 5.4 doesn't do byte-accesses. Add -Wcast-align
authorKeith Packard <keithp@keithp.com>
Sun, 18 Dec 2016 04:58:36 +0000 (20:58 -0800)
committerBdale Garbee <bdale@gag.com>
Wed, 25 Jan 2017 19:21:43 +0000 (12:21 -0700)
commitfe25510fc23031f1a3c1b42edd37067d1989a9f6
tree3cdc98d2c3d1c8d9bd95045771be7d15226d246b
parent4163d88ed36ce8863218366f1fb504f7061a4ca5
altos/arm: Align data so that gcc 5.4 doesn't do byte-accesses. Add -Wcast-align

Gcc 5.4.1 tracks alignment of data through assignments, so that a
uint32_t pointer which comes from byte-aligned uint8_t data:

extern uint8_t foo[];

uint32_t *q = (void *) foo;

Fetches and stores through this pointer are done bytewise. This is
slow (meh), but if q references a device register, things to bad very
quickly.

This patch works around this bug in the compiler by adding
__attribute__((aligned(4))) tags to some variables, or changing them
from uint8_t to uint32_t. Places doing this will now be caught as I've
added -Wcast-align to the compiler flags. That required adding (void
*) casts, after the relevant code was checked to make sure the
compiler could tell that the addresses were aligned.

Signed-off-by: Keith Packard <keithp@keithp.com>
16 files changed:
src/aes/ao_aes.c
src/drivers/ao_gps_ublox.c
src/drivers/ao_trng_send.c
src/kernel/ao_list.h
src/kernel/ao_pyro.c
src/kernel/ao_task.h
src/stm/Makefile.defs
src/stm/ao_arch_funcs.h
src/stm/ao_eeprom_stm.c
src/stm/ao_usb_stm.c
src/stm/stm32l.h
src/stmf0/Makefile-stmf0.defs
src/stmf0/ao_adc_fast.h
src/stmf0/ao_arch_funcs.h
src/stmf0/ao_usb_stm.c
src/stmf0/stm32f0.h