title: Using custom glibc with bazel
body: <p>I am in a non-root (debian) environment and when compiling a binary I got a </p>
  
  <pre><code>Failed to open library! - ./libdmlab.so
  dlopen: cannot load any more object with static TLS
  </code></pre>
  
  <p>I learned that this is a somewhat common problem and was circumvented in  <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=793689" rel="nofollow noreferrer">glibc/2.21.1</a> by increasing the limit. I am now trying to locally install a newer (2.22) version of glibc and link using it in bazel.</p>
  
  <p>I have compiled glibc from the sources and added appropriate things to <code>PATH</code>, <code>CPATH</code> and <code>LIBRARY_PATH</code>. Adding <code>glibc/lib</code> to <code>LD_LIBRARY_PATH</code> made <code>ldd</code> segfault, so I removed it.</p>
  
  <p>Now comes the question of using the locally installed glibc in bazel. I have tried using <code>-linkeropt</code> (as well as <code>-copt</code>) as:</p>
  
  <pre><code>bazel run --linkopt "-Wl,--rpath=/u/sygnowsj/bin/glibc -Wl,--dynamic-linker=/u/sygnowsj/bin/glibc/lib/ld-linux-x86-64.so.2" run //target
  </code></pre>
  
  <p>as described in <a href="https://stackoverflow.com/a/851229/1951176">this answer</a>, but it didn't change anything. I also tried adding</p>
  
  <pre><code>"-Wl,--rpath=/u/sygnowsj/bin/glibc",
  "-Wl,--dynamic-linker=/u/sygnowsj/bin/glibc/lib/ld-linux-x86-64.so.2",
  </code></pre>
  
  <p>to the <code>linkeropts</code> of the problematic library in the <code>BUILD</code> file, but it didn't help either.</p>
  
  <p>How can I make <code>bazel</code> link against my version of <code>glibc</code> for all of the targets? Can I in any other way circumvent the problem of hitting static TLS limit?</p>