title: llvm: How to generate x64 code avoiding RIP-based addressing mode?
body: <p>I am using clang assembly language output for a custom assembler and linker. I feel pretty comfortable with x86 mode, but not with x64 mode, where PC-relative addressing. Consider the following toy example.</p>
  
  <p>C code:</p>
  
  <pre><code>void sum()
  {
      static int a, b;
      static int c;
      c = a + b;
  }
  </code></pre>
  
  <p>x86 output fragment:</p>
  
  <pre><code>sum:
      call    .L0$pb
  .L0$pb:
      pop     EAX
  .Ltmp0:
      add     EAX, _GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb)
      mov     ECX, DWORD PTR [EAX + sum.a@GOTOFF]
      add     ECX, DWORD PTR [EAX + sum.b@GOTOFF]
      mov     DWORD PTR [EAX + sum.c@GOTOFF], ECX
      ret
  </code></pre>
  
  <p>x64 output fragment:</p>
  
  <pre><code>sum:
      mov     EAX, DWORD PTR [RIP + sum.a]
      add     EAX, DWORD PTR [RIP + sum.b]
      mov     DWORD PTR [RIP + sum.c], EAX
      ret
  </code></pre>
  
  <p>My question is: Is there any command line switch that would allow me to generate x64 code without using RIP-based addressing mode? If not, is it possible to modify the LLVM code to avoid RIP-based addressing mode generation for x64 mode and how?</p>