title: ld: 32-bit RIP relative reference out of range in simple gcc program
body: <p>related to <a href="https://stackoverflow.com/questions/35608151/ld-32-bit-rip-relative-reference-out-of-range-on-mac-osx">&quot;ld: 32-bit RIP relative reference out of range&quot; on Mac OSX</a> but not solved and in a more complex context.  the relevant computer(s) have >32GB of RAM.</p>
  
  <pre><code>static const int K=1024;
  static const int M=K*K;
  static const int G=K*M;
  
  const int MC = G;
  
  void donada(float *rvec, const int MC) { rvec[MC-1]= 1.0; return; }
  
  float notused[1][MC]; // 4GB, ramp up with first index
  float used[MC]; // 4GB
  
  int main() {
    donada( used, MC );
    donada( notused[1], MC );
  }
  </code></pre>
  
  <p>and <code>gcc -Wall -o test test.cc</code>.  compiling this program not on osx yields</p>
  
  <blockquote>
    <p>ld: 32-bit RIP relative reference out of range (4294967395 max is
    +/-2GB): from _main (0x100000F92) to _used (0x200001000) in '_main' from /var/folders/yl/8gp3pgbn1l562ywg_q86rk6800\ 00z9/T/test-b3bebf.o
    for architecture x86_64</p>
  </blockquote>
  
  <p>on linux, there is a similar error</p>
  
  <blockquote>
    <p>test.cc:(.text+0x18): relocation truncated to fit: R_X86_64_32 against symbol `used' defined in .bss section in /tmp/ccqcNh2C.o</p>
  </blockquote>
  
  <p>I first thought compiler flag <code>-Os</code> would fix this, but it does not.  It would be appropriate for gcc or clang to provide a more suggestive error message.</p>