Browse Source

arm: gicv3: Fix compiler dependent behavior

C99 standard: "What constitutes an access to an object that has
volatile-qualified type is implementation-defined".

GCC is not considering the cast to void of volatile structures as an
access and so is not actually issuing reads.

Clang does read those structures by copying them on the stack, which in
this case creates an overflow because of their large size.

This patch removes the cast to void and instead uses the USED attribute
to tell the compiler to retain the static variables.

Change-Id: I952b5056e3f6e91841e7ef9558434352710ab80d
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
	       Zelalem Aweke <zelalem.aweke@arm.com>
pull/1937/head
Ambroise Vincent 5 years ago
committed by Zelalem
parent
commit
d01969118f
  1. 6
      include/lib/utils.h
  2. 9
      plat/arm/common/arm_gicv3.c

6
include/lib/utils.h

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@ -82,9 +82,7 @@ void zeromem(void *mem, u_register_t length);
static inline u_register_t load_addr_## _name(void) \
{ \
u_register_t v; \
/* Create a void reference to silence compiler */ \
(void) _name; \
__asm__ volatile ("ldr %0, =" #_name : "=r" (v)); \
__asm__ volatile ("ldr %0, =" #_name : "=r" (v) : "X" (#_name));\
return v; \
}

9
plat/arm/common/arm_gicv3.c

@ -44,12 +44,11 @@ static const interrupt_prop_t arm_interrupt_props[] = {
/*
* We save and restore the GICv3 context on system suspend. Allocate the
* data in the designated EL3 Secure carve-out memory. The `volatile`
* is used to prevent the compiler from removing the gicv3 contexts even
* though the DEFINE_LOAD_SYM_ADDR creates a dummy reference to it.
* data in the designated EL3 Secure carve-out memory. The `used` attribute
* is used to prevent the compiler from removing the gicv3 contexts.
*/
static volatile gicv3_redist_ctx_t rdist_ctx __section("arm_el3_tzc_dram");
static volatile gicv3_dist_ctx_t dist_ctx __section("arm_el3_tzc_dram");
static gicv3_redist_ctx_t rdist_ctx __section("arm_el3_tzc_dram") __used;
static gicv3_dist_ctx_t dist_ctx __section("arm_el3_tzc_dram") __used;
/* Define accessor function to get reference to the GICv3 context */
DEFINE_LOAD_SYM_ADDR(rdist_ctx)

Loading…
Cancel
Save