title: Labels in GCC inline assembly
body: <p>In my ongoing experimentation with GCC inline assembly, I've run into a new problem regarding labels and inlined code.</p>
  
  <p>Consider the following simple jump:</p>
  
  <pre><code>__asm__
  (
      "jmp out;"
      "out:;"
      :
      :
  );
  </code></pre>
  
  <p>This does nothing except jump to the <code>out</code> label.  As is, this code compiles fine.  But if you place it inside a function, and then compile with optimization flags, the compiler complains: "Error: symbol 'out' is already defined".</p>
  
  <p>What seems to be happening is that the compiler is repeating this assembly code every time it inlines the function.  This causes the label <code>out</code> to get duplicated, leading to multiple <code>out</code> labels.</p>
  
  <p>So, how do I work around this?  Is it really not possible to use labels in inline assembly?  This <a href="http://www.linux-tutorial.info/modules.php?name=Howto&amp;pagename=Assembly-HOWTO/gcc.html" rel="noreferrer">tutorial on GCC inline assembly</a> mentions that:</p>
  
  <blockquote>
    <p>Thus, you can make put your assembly
    into CPP macros, and inline C
    functions, so anyone can use it in as
    any C function/macro. Inline functions
    resemble macros very much, but are
    sometimes cleaner to use. Beware that
    in all those cases, code will be
    duplicated, so only <strong>local labels</strong> (of
    1: style) should be defined in that
    asm code.</p>
  </blockquote>
  
  <p>I tried to find more information about these "local labels", but can't seem to find anything relating to inline assembly.  It looks like the tutorial is saying that a local label is a number followed by a colon, (like <code>1:</code>), so I tried using a label like that.  Interestingly, the code compiled, but at run time it simply triggered a Segmentation Fault.  Hmm...</p>
  
  <p>So any suggestions, hints, answers...?</p>