title: symbol lookup in shared libraries
body: <p>I have tested such a simple program below</p>
  
  <pre><code>/* a shared library */
  dispatch_write_hello(void)
  {
          fprintf(stderr, "hello\n");
  }
  
  extern void
  print_hello(void)
  {
          dispatch_write_hello();
  }
  </code></pre>
  
  <p>My main program is like this:</p>
  
  <pre><code>extern void
  dispatch_write_hello(void)
  {
          fprintf(stderr, "overridden\n");
  }
  
  int
  main(int argc, char **argv)
  {
          print_hello();
          return 0;
  }
  </code></pre>
  
  <p>The result of the program is "overriden".<br> To figure this out why this happens, I used gdb. The call chain is like this: <br>
  <code>_dl_runtime_resolve -&gt; _dl_fixup -&gt;_dl_lookup_symbol_x</code> <br>
  I found the definition of <code>_dl_lookup_symbol_x</code> in glibc is </p>
  
  <blockquote>
    <p>Search loaded objects' symbol tables for a definition of the symbol UNDEF_NAME, perhaps with a requested version for the symbol</p>
  </blockquote>
  
  <p>So I think when trying to find the symbol <code>dispatch_write_hello</code>, it first of all looks up in the main object file, and then in the shared library. This is the cause of this problem. Is my understanding right? Many thanks for your time.</p>