[llvm-dev] Using TSAN along with custom llvm IR pass

Dmitry Vyukov via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 28 05:11:48 PDT 2017

On Tue, Jun 27, 2017 at 6:00 PM, Dmitry Vyukov <dvyukov at google.com> wrote:
> On Tue, Jun 27, 2017 at 4:18 PM, Nischai Vinesh
> <nischai.vinesh at gmail.com> wrote:
>> Hello,
>> I have written a custom pass to do some tasks and I want to run this pass on
>> a source code file along with TSAN instrumentation.
>> Steps I followed:
>> 1. I compiled the code file with -fsanitize=thread and -emit-llvm to get the
>> byte code of the file
>> 2.  Used opt to run my custom pass on the TSAN instrumented .bc file
>> 3. Run the final .bc file using lli with proper inputs
>> This gives me a "LLVM ERROR: Program used external function '__tsan_init'
>> which could not be resolved!"


I don't know what is lli, but from the error message it seems that the
problem is that you don't link in tsan runtime (tsan runtime provides
__tsan_init function).
I think you need to compile you instrumented file into object file
first (.o), and then link it with clang -fsanitize=thread (which will
link in runtime).

>> I tried to instrument TSAN on a later step, as follows:
>> 1. Used -emit-llvm to get the .bc file
>> 2. Used opt to run my custom pass on the .bc file
>> 3. Used llc to compile the program to native assembly
>> 4. Used gcc/clang along with -fsanitize=thread to assemble it into a program
>> This does not throws any tsan warnings!  (There are some data race errors
>> intentionally coded in the program to test this)
>> Is there any ways to do this, instrumenting the source code with tsan and
>> use a custom pass to do some other tasks on the same binary?
>> Thank you
> +llvm-dev mailing list

More information about the llvm-dev mailing list