This patch builds on Simone Atzeni's patches (D12840, D12841) to enable TSAN for Power. Simone wasn't comfortable attempting to write the assembly code for intercepting setjmp and sigsetjmp calls, so I've done that here.
The main part of the patch is the new tsan_rtl_ppc64.S file, based on what's done in tsan_rtl_amd64.S. Our version looks much more complicated because we can't do a tail call optimization on an indirect call on Power, since we need to restore the TOC pointer (r2) following the call. Therefore we have to stack a frame, leading to problems with correct manipulation of the jmpbuf. The solution used here (idea due to Ulrich Weigand) is to replace the tail call to the libc setjmp() with a hand-inlined version of the setjmp logic. Since kernels and libc must have the same view of a jmpbuf, it is safe to assume this will not change. We can then modify the code slightly to save the original stack pointer of our caller, and its mangled version, instead of the current stack pointer.
A header file, ppc-regs.h, is included to allow us to write more legible assembly code, distinguishing more easily between register numbers and constants.
The LongJmp interceptor in tsan_interceptors.cc is modified to look for the mangled stack pointer in the architected jmpbuf location for Power.
One test case, race_on_mutex.c, is modified to be sufficiently general for the test to pass on Power. There are two issues:
(1) The atomic read as part of pthread_mutex_init and pthread_mutex_lock is of size 8 on Power, as opposed to size 1 for existing targets. (2) The libc implementation of pthread_mutex_init on Power includes a memset, which is on top of the stack trace for the "previous write." So the position of pthread_mutex_init will be at #1 rather than #0 for Power. I've changed the test to verify that pthread_mutex_init and Thread1 are on the stack, but not necessarily right at the top.
These changes fix 6 of the 7 test case failures that remained after applying Simone's patches. The remaining java-related patch needs more investigation, but we might want to XFAIL that test for Power for now and go ahead with enabling TSAN when Simone is finished with his remaining investigations.
This patch will not be applied until Simone's work is complete.
remove comment