title: Variable alignement with Cortex-M0 under GCC
body: <p>I'm trying to find a good way to align variables on a bondary of 32 bits or 16 bits with GCC. </p>
  
  <p>I'm working on a Cortex-M0 that doesn't support the missaligned data acess. I have this problem when I use <code>-Os</code>. I use arm-none-eabi version 4.6.2. I have this small test case:</p>
  
  <pre><code>#include "stdint.h"
  
  typedef struct Struct_HdrPrefix{
      uint8_t Prefix;
      uint16_t Type;
  }__attribute((packed))Struct_HdrPrefix;
  
  volatile Struct_HdrPrefix test;
  volatile Struct_HdrPrefix test1;
  
  int main(void)
  {
      test.Type = 0;
      while(1)
          __asm("nop");
  }
  
  void HardFault_Handler(void)
  {
      while(1)
          __asm("nop");
  }
  </code></pre>
  
  <p>When I compile this I get a non aligned variable test.</p>
  
  <p>Here is the result in the map file:</p>
  
  <pre><code>COMMON         0x20000000        0x6 ./SRC/main.o
                 0x20000000                test1
                 0x20000003                test
  </code></pre>
  
  <p>So now I got to hardfault. If I add this to the vars:</p>
  
  <pre><code>volatile Struct_HdrPrefix test __attribute((aligned (4)));
  volatile Struct_HdrPrefix test1 __attribute((aligned (4)));
  </code></pre>
  
  <p>This is working as expected since <code>test</code> is now aligned.</p>
  
  <p>I can't use the align attribute on the struct since this struct could be part of another one packed too.</p>
  
  <p>Is there a way to tell GCC or LD to align packed variables on a 32 bits boundary?</p>
  
  <p>Regards</p>