From: Gabe Black Date: Wed, 14 Oct 2020 08:09:21 +0000 (-0700) Subject: misc: Wrap __attribute__((aligned())) in a macro in compiler.hh. X-Git-Tag: develop-gem5-snapshot~602 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=215e12b884d634dd4866b8222bd5435a511d4de6;p=gem5.git misc: Wrap __attribute__((aligned())) in a macro in compiler.hh. This attribute is gcc specific (also implemented by clang for compatibility), and so should be behind a level of abstraction to make using different compilers easier. Change-Id: I7495f011f617268dd7a589dc0bcf1b3b7f515046 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/35976 Reviewed-by: Daniel Carvalho Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/arch/arm/linux/linux.hh b/src/arch/arm/linux/linux.hh index 5fd6cdc0c..ad773cd3b 100644 --- a/src/arch/arm/linux/linux.hh +++ b/src/arch/arm/linux/linux.hh @@ -43,6 +43,7 @@ #define __ARCH_ARM_LINUX_LINUX_HH__ #include "arch/arm/utility.hh" +#include "base/compiler.hh" #include "kern/linux/linux.hh" class ArmLinux : public Linux @@ -219,9 +220,9 @@ class ArmLinux32 : public ArmLinux uint32_t st_gid; uint64_t st_rdev; uint8_t __pad3[4]; - int64_t __attribute__ ((aligned (8))) st_size; + M5_ALIGNED(8) int64_t st_size; uint32_t st_blksize; - uint64_t __attribute__ ((aligned (8))) st_blocks; + M5_ALIGNED(8) uint64_t st_blocks; uint32_t st_atimeX; uint32_t st_atime_nsec; uint32_t st_mtimeX; diff --git a/src/arch/mips/linux/aligned.hh b/src/arch/mips/linux/aligned.hh index db4896afa..84157a2d8 100644 --- a/src/arch/mips/linux/aligned.hh +++ b/src/arch/mips/linux/aligned.hh @@ -30,18 +30,8 @@ #define __ARCH_MIPS_LINUX_ALIGNED_HH__ -/* GCC 3.3.X has a bug in which attributes+typedefs don't work. 3.2.X is fine - * as in 3.4.X, but the bug is marked will not fix in 3.3.X so here is - * the work around. - */ -#if (__GNUC__ == 3 && __GNUC_MINOR__ != 3) || __GNUC__ > 3 -typedef uint64_t uint64_ta __attribute__ ((aligned (8))) ; -typedef int64_t int64_ta __attribute__ ((aligned (8))) ; -typedef Addr Addr_a __attribute__ ((aligned (8))) ; -#else -#define uint64_ta uint64_t __attribute__ ((aligned (8))) -#define int64_ta int64_t __attribute__ ((aligned (8))) -#define Addr_a Addr __attribute__ ((aligned (8))) -#endif /* __GNUC__ __GNUC_MINOR__ */ +typedef M5_ALIGNED(8) uint64_t uint64_ta; +typedef M5_ALIGNED(8) int64_t int64_ta; +typedef M5_ALIGNED(8) Addr Addr_a; #endif /* __ARCH_MIPS_LINUX_ALIGNED_HH__ */ diff --git a/src/base/compiler.hh b/src/base/compiler.hh index 4565143b1..643352cd0 100644 --- a/src/base/compiler.hh +++ b/src/base/compiler.hh @@ -99,6 +99,9 @@ # define M5_LOCAL [[gnu::visibility("hidden")]] # define M5_WEAK [[gnu::weak]] +// Force an alignment for a variable. +# define M5_ALIGNED(alignment) [[gnu::aligned(alignment)]] + // Marker for what should be an unreachable point in the code. # define M5_UNREACHABLE __builtin_unreachable() diff --git a/src/base/statistics.hh b/src/base/statistics.hh index c66454053..2c1b1a121 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -657,7 +657,7 @@ class ScalarBase : public DataWrap protected: /** The storage of this stat. */ - char storage[sizeof(Storage)] __attribute__ ((aligned (8))); + M5_ALIGNED(8) char storage[sizeof(Storage)]; protected: /** @@ -1878,7 +1878,7 @@ class DistBase : public DataWrap protected: /** The storage for this stat. */ - char storage[sizeof(Storage)] __attribute__ ((aligned (8))); + M5_ALIGNED(8) char storage[sizeof(Storage)]; protected: /**