Commit 17db8efe authored by danno@chromium.org's avatar danno@chromium.org

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 <kalmard@homejinni.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11240 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent db860431
......@@ -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 <typename T>
struct StaticallyAllocatedInstanceTrait {
typedef char StorageType[sizeof(T)];
typedef char StorageType[sizeof(T)] LAZY_ALIGN(T);
static T* MutableInstance(StorageType* storage) {
return reinterpret_cast<T*>(storage);
......@@ -125,6 +133,8 @@ struct StaticallyAllocatedInstanceTrait {
}
};
#undef LAZY_ALIGN
template <typename T>
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_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment