Browse Source

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>
sbg
Mark Charlebois 10 years ago
parent
commit
ec1b77c9e1
  1. 19
      src/modules/systemlib/param/param.h

19
src/modules/systemlib/param/param.h

@ -374,6 +374,7 @@ union param_value_u { @@ -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 { @@ -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;
};

Loading…
Cancel
Save