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 &param[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 <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-04-20 11:35:48 -07:00
parent 5d988381e6
commit ec1b77c9e1
+18 -1
View File
@@ -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
// &param[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;
};