title: howto get subsection padding in gnu-assembler
body: <p>I'm using gnu assembler on a TI MCU (msp430) and want to define variables of mixed alignments in assembly; some are byte aligned, others must be word (16bit) aligned.  I am also needing to keep some variables private to an assembly language module, and others common (global).  So, I'd like to us .lcomm -- as the default, and then use .global to over-ride it when appropriate.</p>
  
  <p>But even after applying the byte align directive, I am getting alignment errors during linking of a GCC compiled program:</p>
  
  <p>ssegLED.c:200: dangerous relocation: unaligned address</p>
  
  <p>And that line is merely trying to access data that is supposed to be word aligned: </p>
  
  <p>if (knob) { ... }</p>
  
  <p>In the assembly language module causing the problem, I'm trying to make the data pack efficiently into memory;  So I want to use subsections to group like kinds of data together so that holes don't form between differently aligned data.  eg: all word aligned data I'd like in the default subsection (0) but unaligned data, I want in subsection 1.</p>
  
  <p>Here's the assembly / .s code used to define four variables:  keystroke, quadrature, keystate, and knob.  The first three are byte aligned, the last is word aligned.</p>
  
  <pre><code>.section    .bss    ;; doesn't matter if .bss or .section .bss -- same err.
  .subsection 1
  .balign     1 ;; can add a  ,0 -- but it changes nothing
  
  .global     keystroke
  .type       keystroke,@object
  .size       keystroke,1 ;; Tried with and without this line, no change...
  .lcomm      keystroke,1
  
  .lcomm      quadrature,1
  .lcomm      keystate,1  
  
  .section    .bss
  .subsection 0
  .balign     2 ;; tried adding ,0 -- but it fixes nothing
  
  .global     knob  ;; Present knob value
  .type       knob, @object
  .size       knob, 2     ;; doesn't affect error whether commented out/not
  .lcomm      knob, 2
  </code></pre>
  
  <p>Now, there are two things I am doing which ought to prevent mis-alignement issues;
  According to the GNU AS manual, subsection 0 should be placed in memory before subsection 1; therefore section 0 automatically starts out word aligned as the default section; and secondly, I'm using the .balign directive explicitly.</p>
  
  <p>But it doesn't work... and changing to .b2align doesn't fix it, etc.</p>
  
  <p>I <em>can</em> make the error go away by explicitly adding another byte aligned variable to the the subsection 1 variables keystroke, quadrature, and keystate; so that the whole subsection ends on a word boundary; but as the offending subsection has a lower number (0), the alignment of subsection (1) ought not have any effect....</p>
  
  <p>Secondly, if I change all the .lcomm into .comm the error also goes away; but I have no idea why.</p>
  
  <p>What's going on? and what am I doing wrong?</p>