title: How to specify default global variable alignment for gcc?
body: <p>How do I get rid of alignment (<code>.align 4</code> below) for all global variables by default with GCC, without having to specify <code>__attribute__((aligned(1)))</code> for each variable?</p>
  
  <p>I know that what I ask for is a bad idea to apply universally, becuase on some architectures an alignment of 1 wouldn't work, because e.g. the CPU is not able to dereference an unaligned pointer. Bit in my case I'm writing an i386 bootloader, and unaligned pointers are fine (but slower) there.</p>
  
  <p>Source code (<code>a.c</code>):</p>
  
  <pre><code>__attribute__((aligned(1))) int answer0 = 41;
  int answer = 42;
  </code></pre>
  
  <p>Compiled with: <code>gcc -m32 -Os -S a.c</code></p>
  
  <p>Assembly output (<code>a.s</code>):</p>
  
  <pre><code>    .file   "a.c"
      .globl  answer
      .data
      .align 4
      .type   answer, @object
      .size   answer, 4
  answer:
      .long   42
      .globl  answer0
      .type   answer0, @object
      .size   answer0, 4
  answer0:
      .long   41
      .ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
      .section        .note.GNU-stack,"",@progbits
  </code></pre>
  
  <p>The flag <code>gcc -fpack-struct=1</code> changes the alignment of all struct members and structs to 1. For example, with that flag</p>
  
  <pre><code>struct x { char a; int b; };
  struct y { int v : sizeof(char) + sizeof(int) == sizeof(struct x); };
  struct z { int b; };
  struct x x = { 1, 1 };
  int i = 42;
  struct z z = { 2 };
  </code></pre>
  
  <p>compiles to no alignment for variables <code>x' and</code>z', but it still has an <code>.align 4</code> for the variable <code>i</code> (of type <code>int</code>). I need a solution which also makes <code>int i = 42;</code> unaligned, without having to specify something extra for each such variable.</p>