From 4ae78639f5b385cbe6a21b743c51b37b08aee981 Mon Sep 17 00:00:00 2001 From: Piotr Tworek Date: Mon, 2 Nov 2020 22:05:46 +0100 Subject: [PATCH] base-hw: Fix invalid structure alignments. According to C++11 reference: "If the strictest (largest) alignas on a declaration is weaker than the alignment it would have without any alignas specifiers (that is, weaker than its natural alignment or weaker than alignas on another declaration of the same object or type), the program is ill-formed:" https://en.cppreference.com/w/cpp/language/alignas The code requests 4 byte alignment for Genode::Arm_cpu::Context. The Context structure inherits Genode::Arm_cpu::Fpu_context which has minimum alignment requirement of 8 bytes, due to uint64_t d0_d31 member. This makes the 4 byte value in Context's alignas specifier invalid (smaller than allowed minimum). Similar situation takes place in Arm_64 case. The claimed minimum alignment of Context is 8 bytes, but the fpu_state member imposes 16 bytes alignment (explicitly specified in Fpu_state declaration). In both cases the code builds fine with GCC 8.3.0, but fails with clang which claims that "requested alignment is less than minimum alignment of X for type", where X is 8 on ARM and 16 on AArch64. Ref: https://eel.is/c++draft/dcl.align#5 Issue #4421 --- repos/base-hw/src/core/spec/arm/cpu_support.h | 2 +- repos/base-hw/src/core/spec/arm_v8/cpu.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/repos/base-hw/src/core/spec/arm/cpu_support.h b/repos/base-hw/src/core/spec/arm/cpu_support.h index 3fa86f1a07..4654daf93e 100644 --- a/repos/base-hw/src/core/spec/arm/cpu_support.h +++ b/repos/base-hw/src/core/spec/arm/cpu_support.h @@ -47,7 +47,7 @@ struct Genode::Arm_cpu : public Hw::Arm_cpu uint64_t d0_d31[32]; /* VFP/SIMD - general purpose registers */ }; - struct alignas(4) Context : Cpu_state, Fpu_context + struct alignas(8) Context : Cpu_state, Fpu_context { Context(bool privileged); }; diff --git a/repos/base-hw/src/core/spec/arm_v8/cpu.h b/repos/base-hw/src/core/spec/arm_v8/cpu.h index 502d9ca62a..29fa1f547a 100644 --- a/repos/base-hw/src/core/spec/arm_v8/cpu.h +++ b/repos/base-hw/src/core/spec/arm_v8/cpu.h @@ -71,7 +71,7 @@ struct Genode::Cpu : Hw::Arm_64_cpu Genode::uint64_t fpcr; }; - struct alignas(8) Context : Cpu_state + struct alignas(16) Context : Cpu_state { Genode::uint64_t pstate { }; Genode::uint64_t exception_type { RESET };