From 469866b6c90c1de8a8581347a357e33a3dfd908c Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Fri, 24 Jul 2020 22:46:05 -0400 Subject: [PATCH] mpegplayer: Fix aliasing rules violation on multi-core targets As the PP series has no sense of cache coherency between its multiple cores, we need to ensure the vo_data structure does not share cachelines with anything else. This was previously done by defining a uint8_t array and trying to access it via typecasting hell, triggering a large pile of aliasing violation warnings on newer toolchains and/or higher optimization levels. Instead of violating the C spec in an undefined-behaviour-sort-of-way, create a union of the right size and alignment, and make one of its members the structure we care about. Voila, everyone is happy. Change-Id: Iad78f8132225437cd4aa10e6e5f6ae58ba996c19 --- apps/plugins/mpegplayer/video_out_rockbox.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/plugins/mpegplayer/video_out_rockbox.c b/apps/plugins/mpegplayer/video_out_rockbox.c index b05a229083..ee5c3400c5 100644 --- a/apps/plugins/mpegplayer/video_out_rockbox.c +++ b/apps/plugins/mpegplayer/video_out_rockbox.c @@ -47,9 +47,11 @@ struct vo_data #if NUM_CORES > 1 /* Cache aligned and padded to avoid clobbering other processors' cacheable * data */ -static uint8_t __vo_data[CACHEALIGN_UP(sizeof(struct vo_data))] - CACHEALIGN_ATTR; -#define vo (*((struct vo_data *)__vo_data)) +static union { + uint8_t __vo_data[CACHEALIGN_UP(sizeof(struct vo_data))]; + struct vo_data vo; +} vo_raw CACHEALIGN_ATTR; +#define vo vo_raw.vo #else static struct vo_data vo; #endif