title: Doesn't PIC mean no relocations?
body: <p>I'm building an ELF SO for bada on ARM using GCC. The compiler options include -fpic. Yet in the built file, when I do <code>readelf -r</code>, there's a whole lot of relocation records, of following types:</p>
  
  <ul>
  <li>R_ARM_RELATIVE</li>
  <li>R_ARM_REL32</li>
  <li>R_ARM_ABS32</li>
  <li>R_ARM_GLOB_DAT</li>
  <li>R_ARM_JUMP_SLOT</li>
  </ul>
  
  <p>What am I misunderstanding here?</p>
  
  <p>EDIT: from what I can see, the PIC implementation in the compiler doesn't use GOT. Instead, they use PC-relative addressing with stored constants being offsets from point of use to the symbol address; that's resolved by the linker. Like this, to read a global variable:</p>
  
  <pre><code>    ldr r12, OffsetToVar
  PointOfUse:
      ldr r0, [r12, pc] 
  # r0 now has the value of MyVar
  
  #...
  
  # At function's end...
  OffsetToVar:
      .long MyVar-PointOfUse-8
  # Compiler can't resolve this, since it doesn't know
  # the address of MyVar, but linker can
  </code></pre>
  
  <p>Similar idea for cross-module function calls. When a project mixes ARM and Thumb code though, the latter may misfire. But I've worked around that.</p>