Dmitry Vyukov via llvm-dev
2017-Jun-28 12:11 UTC
[llvm-dev] Using TSAN along with custom llvm IR pass
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!"Hi, 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
Dmitry Vyukov via llvm-dev
2017-Jul-10 05:21 UTC
[llvm-dev] Using TSAN along with custom llvm IR pass
On Sun, Jul 9, 2017 at 3:50 PM, Nischai Vinesh <nischai.vinesh at gmail.com> wrote:> Hello, > > I tried that as well but there are no tsan warnings thrown at run time, even > though there are data race error! > > The steps I followed: > 1. Generate bitcode using 'clang -emit-llvm' command > 2. Using the 'opt -load ..' command, I instrumented the bitcode file with my > custom pass > 3. Using the command 'opt -tsan ..', instrumented the output bitcode file > from step 2 > 4. Using the llvm backend compiler, 'llc', compiled the program to native > assembly > 5. The output from step 4 is compiled again with 'clang -fsanitize=thread' > (linking tsan here) for the final object file. > > Executing this final output file works fine, except that it doesn't throws > any TSAN warnings!Hi Nischai, I see 3 possibilities: 1. Either the code is somehow ends up being non-instrumented, or 2. tsan does not consider what it sees a data race, or 3. the data race is masked by unrelated synchronization. For 1 you can check that the resulting code in fact contains __tsan_* callbacks. For 2 and 3 you can rebuilt tsan runtime with TSAN_DEBUG_OUTPUT=2 define, then it will print everything it sees (memory accesses and synchronization). This output will allow us to figure out why it does not report a race.