title: How to restrict access to symbols in shared object?
body: <p>I have a plug-in in the form of a shared library (bar.so) that links into a larger program (foo). Both foo and bar.so depend on the same third party library (baz) but they need to keep their implementations of baz completely separate. So when I link foo (using the supplied object files and archives) I need it to ignore any use of baz in bar.so and vice versa.</p>
  
  <p>Right now if I link foo with <code>--trace-symbol=baz_fun</code> where baz_fun is one of the offending symbols I get the following output:</p>
  
  <pre><code>bar.so: definition of baz_fun
  foo/src.a(baz.o): reference to baz_fun
  </code></pre>
  
  <p>I believe this is telling me that foo is referencing baz_fun from bar.so (and execution of foo confirms this).</p>
  
  <p>Solutions that I have tried:</p>
  
  <ul>
  <li>Using <code>objcopy</code> to "localize" the symbols of interest: <code>objcopy --localize-symbols=local.syms bar.so</code> where local.syms contains all of the symbols of interest. I think I might just be confused here and maybe "local" doesn't mean what I think it means. Regardless, I get the same output from the link above. I should note that if I run the <code>nm</code> tool on bar.so prior to using <code>objcopy</code> all of the symbols in question have the <code>T</code> flag (upper-case indicating global) and after <code>objcopy</code> they have a <code>t</code> indicating they are local now. So it appears I am using <code>objcopy</code> correctly.</li>
  <li>Compiling with <code>-fvisibility=hidden</code> however due to some other constraints I need to use GCC 3.3 which doesn't appear to support that feature. I might be able to upgrade to a newer version of GCC but would like confirmation that compiling with this flag will help me before heading down that road.</li>
  </ul>
  
  <p>Other things to note:</p>
  
  <ul>
  <li>I do not have access to the source code of either foo or baz</li>
  <li>I would prefer to keep all of my plug-in in one shared object (bar.so). baz is actually a licensing library so I don't want it separated</li>
  </ul>