title: calculating the address of global offset table in arm literal pool
body: <p>I am trying to understand the arm assembly code for writing the Literal Pool and Global OFFSET table</p>
  
  <p>Compiling the C code with GNU ARM GCC</p>
  
  <pre><code>extern int i;
  int foo(int j)
  {
  int t = i;
  i = j;
  return t;
  }
  </code></pre>
  
  <p>GCC generates following code:</p>
  
  <pre><code>foo:
      ldr     r3, .L2        
      ldr     r2, .L2+4      
  .LPIC0:
      add     r3, pc         
      ldr     r3, [r3, r2]   
      @ sp needed for prologue
      ldr     r2, [r3]
      str     r0, [r3]
      mov     r0, r2
      bx      lr
  
  .L3:
      .align  2
  
  .L2:
      .word   _GLOBAL_OFFSET_TABLE_-(.LPIC0+4)  
      .word   i(GOT)
  </code></pre>
  
  <p>I want to  manually handle the global offset table in arm assembly.
  Now I am facing difficulty to understand the above code.
  Can any one please describe the literal pool calculation following lines of code?</p>
  
  <pre><code>.L2:
      .word   _GLOBAL_OFFSET_TABLE_-(.LPIC0+4) 
      .word   i(GOT) 
  </code></pre>