From 17db8efe0c74adb46a70d08bf00cc12e37f68c17 Mon Sep 17 00:00:00 2001 From: "danno@chromium.org" Date: Thu, 5 Apr 2012 15:12:28 +0000 Subject: [PATCH] MIPS: Ensure proper alignment of LazyInstance objects. The template system converts the actual struct type to an array of chars. Make sure the alignment is kept by the compiler. This fixes a lot of serialization-related HW tests, for example cctest test-serialize/Serialize. BUG= TEST=cctest test-serialize Review URL: https://chromiumcodereview.appspot.com/9702114 Patch from Daniel Kalmar . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11240 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/lazy-instance.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lazy-instance.h b/src/lazy-instance.h index 5bbe230..4c09b0d 100644 --- a/src/lazy-instance.h +++ b/src/lazy-instance.h @@ -111,9 +111,17 @@ struct LeakyInstanceTrait { // Traits that define how an instance is allocated and accessed. +// TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue +// on MIPS with other compilers. +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) +#define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) +#else +#define LAZY_ALIGN(x) +#endif + template struct StaticallyAllocatedInstanceTrait { - typedef char StorageType[sizeof(T)]; + typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); static T* MutableInstance(StorageType* storage) { return reinterpret_cast(storage); @@ -125,6 +133,8 @@ struct StaticallyAllocatedInstanceTrait { } }; +#undef LAZY_ALIGN + template struct DynamicallyAllocatedInstanceTrait { @@ -212,7 +222,8 @@ struct LazyInstanceImpl { mutable OnceType once_; // Note that the previous field, OnceType, is an AtomicWord which guarantees - // the correct alignment of the storage field below. + // 4-byte alignment of the storage field below. If compiling with GCC (>4.2), + // the LAZY_ALIGN macro above will guarantee correctness for any alignment. mutable StorageType storage_; }; -- 2.7.4