title: How to combine AddressSanitizer with dynamically linked Pthreads library?
body: <p>I am trying to use <em>AddressSanitizer</em> for a program that is multi threaded and uses pthread library functions. However instead of statically linking with <code>-lpthread</code> flag during compilation with gcc, I am using dynamic link <code>-ldl -rdynamic $filename.so</code> which provides implementation of pthread functions. I have read that AddressSanitizer should be the first linked library, so I added it like this: </p>
  
  <pre><code>export LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/7/libasan.so
  </code></pre>
  
  <p>The problem I have is that while executing the program, it gets stuck at pthread_create. As I understand because this function is not provided statically, it's looked for in dynamically linked libraries, in <code>libasan.so</code> first and it gets blocked there, not moving to the second library that actually contains implementation of pthread_create function. 
  I also tried using <code>-fsanitize=address (with -lasan)</code> to link with AddressSanitizer during compilation but I got the same result.</p>
  
  <p>Is there anything else I could try to make these two libraries work together? </p>