arm-elf-g++ alignment and packing



I’m trying to build boost ( using the ARM ELF GCC (4.0.1) toolchain. The build fails because of a check boost performs on struct packing. The following code will fail using ARM ELF, but will compile with ARM EABI (4.4.1)

class X
  short s;

struct Z
  short s;

void Test()
  BOOST_STATIC_ASSERT(sizeof(X) == sizeof(short));
  BOOST_STATIC_ASSERT(sizeof(Z) == sizeof(short));

BOOST_STATIC_ASSERT is a compile-time assertion (static_assert)

I’ve checked the actual result of the sizeof operation and ARM ELF GCC produces 4 bytes and ARM EABI produces 2. How can I get ARM ELF to behave like ARM EABI, without having to specify -fpack-struct on the command line, as this breaks a number of other things?


First question is: why are you still using ARM ELF GCC? Please note that in relatively short term, new Open AT Releases won’t provide anymore libraries built with ARM ELF GCC. Unless you have a really good reason, it is recommended to migrate to ARM EABI GCC.
Anyhow, for this particular case, it seems there is no other alternative to add the -fpack-struct option, but maybe should you add it only to the files that are needing it (through right-click menu > Properties dialog on the concerned file: this allows to tune specific options on the selected file (or folder) only).


Thanks for the response.

I am trying to move to ARM EABI, see [url]].
Getting boost to build for ELF is plan B.