title: Referencing memory operands in .intel_syntax GNU C inline assembly
body: <p>I'm catching a link error when compiling and linking a source file with inline assembly.</p>
  
  <p>Here are the test files:</p>
  
  <pre><code>via:$ cat test.cxx
  extern int libtest();
  int main(int argc, char* argv[])
  {
      return libtest();
  }
  
  $ cat lib.cxx
  #include &lt;stdint.h&gt;
  int libtest()
  {
      uint32_t rnds_00_15;    
      __asm__ __volatile__
      (
          ".intel_syntax noprefix         ;\n\t"
          "mov DWORD PTR [rnds_00_15], 1  ;\n\t"
          "cmp DWORD PTR [rnds_00_15], 1  ;\n\t"
          "je  done                       ;\n\t"
          "done:                          ;\n\t"
          ".att_syntax noprefix           ;\n\t"
          :
          : [rnds_00_15] "m" (rnds_00_15)
          : "memory", "cc"
      );
  
      return 0;
  }
  </code></pre>
  
  <p>Compiling and linking the program results in:</p>
  
  <pre><code>via:$ g++ -fPIC test.cxx lib.cxx -c
  via:$ g++ -fPIC lib.o test.o -o test.exe
  lib.o: In function `libtest()':
  lib.cxx:(.text+0x1d): undefined reference to `rnds_00_15'
  lib.cxx:(.text+0x27): undefined reference to `rnds_00_15'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>The real program is more complex. The routine is out of registers so the flag <code>rnds_00_15</code> must be a memory operand. Use of <code>rnds_00_15</code> is local to the asm block. It is declared in the C code to ensure the memory is allocated on the stack and nothing more. We don't read from it or write to it as far as the C code is concerned. We list it as a memory input so GCC knows we use it and wire up the "C variable name" in the extended ASM.</p>
  
  <p>Why am I receiving a link error, and how do I fix it?</p>