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
This commit is contained in:
Piotr Tworek 2020-11-02 22:05:46 +01:00 committed by Norman Feske
parent 468057638b
commit 4ae78639f5
2 changed files with 2 additions and 2 deletions

View File

@ -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);
};

View File

@ -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 };