title: symbol relocation - extern,static and no storage class
body: <p>I have 3 sample codes below(all .so files):</p>
  
  <p>1)</p>
  
  <pre><code>int myglob = 42;
  
  int fun(int a, int b)
  {
      return myglob + a + b;
  }
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>static int myglob = 42;
  
  int fun(int a, int b)
  {
      return myglob + a + b;
  }
  </code></pre>
  
  <p>3)  </p>
  
  <pre><code>extern int myglob;
  
  int fun(int a, int b)
  {
      return myglob + a + b;
  }
  </code></pre>
  
  <p>How do relocations work in these three cases? How are they different from each other? </p>
  
  <hr>
  
  <p><strong>My guesses</strong> : </p>
  
  <p>Since <code>myglob</code> in the 3rd case is <code>extern</code>, it uses the <code>GOT</code> table.</p>
  
  <p>In the 2nd case, I don't think we need to use the GOT table since <code>myglob</code> is defined in the object itself and linker knows about the offset between the <code>.text</code> and <code>.data</code> sections, so we can add the known <em>offset</em> to the current instruction pointer to access <code>myglob</code> in the data section.</p>
  
  <p>1st one is declared in the <em>file scope</em> and don't specify a storage class, then it defaults to <em>external linkage</em>. So this should behave similar to the 3rd case.</p>
  
  <p>Am I correct?</p>