title: assembly - use symbols in other object files as immediate values
body: <p>I'm writing a toy OS for my raspberry pi, and I'm using <a href="http://pdos.csail.mit.edu/6.828/xv6/" rel="nofollow">xv6</a> as a reference.</p>
  
  <p>My code has a compile error, when I tried to load an "entrypgdir" symbol that's defined in another file (which is in C).</p>
  
  <p>_start.S:</p>
  
  <pre><code>#include "mem.h"
  
  .globl entry
  entry:
      mov r0, #(V2P_NOCAST(entrypgdir))
  </code></pre>
  
  <p>V2P_NOCAST is a simple macro defined in a .h file as</p>
  
  <p>mem.h:</p>
  
  <pre><code>#define V2P_NOCAST(va) ((va) - KERNBASE)
  </code></pre>
  
  <p>And the error:</p>
  
  <pre><code>$ arm-none-eabi-gcc -c -o build/_start.o source/_start.S
  source/_start.S: Assembler messages:
  source/_start.S:17: Error: undefined symbol entrypgdir used as an immediate value
  </code></pre>
  
  <p>I'm curious since that's how xv6 does it,</p>
  
  <pre><code>movl    $(V2P_WO(entrypgdir)), %eax
  </code></pre>
  
  <p>And it compiles fine,</p>
  
  <pre><code>$ gcc -m32 -c -o entry.o entry.S
  </code></pre>
  
  <p>Is it something with my toolchain? Or it's not possible in ARM?</p>