title: What does -pie do exactly?
body: <p>I <code>file /bin/ls</code> and get the output:</p>
  
  <blockquote>
    <p>/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped</p>
  </blockquote>
  
  <p>And I found the reason is that my gentoo is compiling everything with -pie .</p>
  
  <p>If I pass -nopie to gcc, I will get the right answer:</p>
  
  <blockquote>
    <p>a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped</p>
  </blockquote>
  
  <p>Also, I find something at <a href="https://stackoverflow.com/questions/1449987/building-a-so-that-is-also-an-executable">building a .so that is also an executable</a>. It uses -pie to make a DSO executable.</p>
  
  <p>In gcc's man page, it describes in brief:</p>
  
  <blockquote>
    <p>-pie<br>
    Produce a position independent executable on targets that support it.</p>
  </blockquote>
  
  <p>So I'm wondering what -pie do exactly? How it makes my executable to be recognized as a shared object?</p>