title: What does compiling WITH_PIC (-DWITH_PIC, --with-pic) actually do?
body: <p>When compiling binaries from source, what are the real-world differences between generating <a href="http://en.wikipedia.org/wiki/Position-independent_code" rel="noreferrer">PIC objects</a> or not? At what point down the road would someone say, "I should have generated/used PIC objects when I compiled MySQL." Or not?</p>
  
  <p>I've read <a href="http://www.gentoo.org/proj/en/hardened/pic-guide.xml" rel="noreferrer">Gentoo's Introduction to Position Independent Code</a>, <a href="http://www.gentoo.org/proj/en/hardened/pic-internals.xml" rel="noreferrer">Position Independent Code internals</a>, <a href="http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&amp;chap=3" rel="noreferrer">HOWTO fix -fPIC errors</a>, <a href="http://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html" rel="noreferrer">Libtool's Creating object files</a>, and <a href="http://www.sourceware.org/autobook/autobook/autobook_71.html" rel="noreferrer">Position Independent Code</a>.</p>
  
  <p>From PHP's <code>./configure --help</code>:</p>
  
  <blockquote>
    <p>--with-pic: Try to use only PIC/non-PIC objects [default=use both].</p>
  </blockquote>
  
  <p>From MySQL's <code>cmake -LAH .</code>:</p>
  
  <blockquote>
    <p>-DWITH_PIC: Generate PIC objects</p>
  </blockquote>
  
  <p>That info is a good start, but leaves me with a lot of questions.</p>
  
  <p>From what I understand, it turns on <code>-fPIC</code> in the compiler, which in turn generates PIC objects in the resulting binaries/libraries. Why would I want to do that? Or vice-versa. Maybe it's riskier or could potentially make the binary less stable? Maybe it should be avoided when compiling on certain architectures (amd64/x86_64 in my case)?</p>
  
  <p>The default MySQL build sets PIC=OFF. The official MySQL release build sets PIC=ON. And PHP "tries to use both." In my tests setting <code>-DWITH_PIC=ON</code> results in slightly larger binaries:</p>
  
  <pre><code>          PIC=OFF     PIC=ON
  mysql     776,160    778,528
  mysqld  7,339,704  7,476,024
  </code></pre>