title: create position independent object file from LLVM bit code
body: <p>I have a llvm module that i've dumped as bitcode file with <code>llvm::WriteBitcodeToFile</code>. I want to turn this bitcode file into an native dynamically loadable library that contains the functions in the module.</p>
  
  <p>How do i do this? i tried using <code>llc</code> for this, but this produces code that apparently is not relocatable, since after doing the following steps:</p>
  
  <pre><code>llc -enable-pie -cppgen=functions -filetype=asm executableModule -o em.s
  </code></pre>
  
  <p>then, assemblying with gnu <code>as</code> into an object file:</p>
  
  <pre><code>as -o mylib.o em.s
  </code></pre>
  
  <p>finally, trying to produce a shared library with:</p>
  
  <pre><code>gcc -shared -o libmyfile.so -fPIC mylib.o
  </code></pre>
  
  <p>fails with the error:</p>
  
  <pre><code>/usr/bin/ld: error: mylib.o: requires dynamic R_X86_64_PC32 reloc against 'X.foo' which may overflow at runtime; recompile with -fPIC
  collect2: ld returned 1 exit status
  </code></pre>