From ec1b77c9e1fcca6c0984539d72e8c324f063a624 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Wed, 8 Apr 2015 14:50:27 -0700 Subject: [PATCH] Linux: GCC static data is 16byte aligned, messes up param GCC 4.8 and higher implement 16 byte static data alignment on 64-bit. This means that the 24-byte param_info_s variables are 16 byte aligned by GCC and that messes up the assumption that the address of the second parameter is at ¶m[0]+sizeof(param[0]). When compiled with clang it is true, with gcc is is not true. See https://llvm.org/bugs/show_bug.cgi?format=multiple&id=18006 The fix is needed for GCC >=4.8 only. Clang works fine without this. Added __attribute__((aligned(16))) to first member of param_info_s. Signed-off-by: Mark Charlebois --- src/modules/systemlib/param/param.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modules/systemlib/param/param.h b/src/modules/systemlib/param/param.h index b29a7e51d6..8f53a5d730 100644 --- a/src/modules/systemlib/param/param.h +++ b/src/modules/systemlib/param/param.h @@ -374,6 +374,7 @@ union param_value_u { void *p; int32_t i; float f; + long long x; }; /** @@ -383,7 +384,23 @@ union param_value_u { * instead. */ struct param_info_s { - const char *name; + const char *name + +// GCC 4.8 and higher don't implement proper alignment of static data on +// 64-bit. This means that the 24-byte param_info_s variables are +// 16 byte aligned by GCC and that messes up the assumption that +// sequential items in the __param segment can be addressed as an array. +// The assumption is that the address of the second parameter is at +// ¶m[0]+sizeof(param[0]). When compiled with clang it is +// true, with gcc is is not true. +// See https://llvm.org/bugs/show_bug.cgi?format=multiple&id=18006 +// The following hack is for GCC >=4.8 only. Clang works fine without +// this. +#ifdef __PX4_LINUX + __attribute__((aligned(16))); +#else + ; +#endif param_type_t type; union param_value_u val; };