[PATCH] D13729: [TSAN, PowerPC] Setjmp/longjmp handling for PowerPC

Bill Schmidt via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 09:30:07 PDT 2015


wschmidt created this revision.
wschmidt added reviewers: samsonov, hfinkel, simoatze, kcc, uweigand.
wschmidt added a subscriber: llvm-commits.
wschmidt set the repository for this revision to rL LLVM.

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.

Repository:
  rL LLVM

http://reviews.llvm.org/D13729

Files:
  lib/tsan/CMakeLists.txt
  lib/tsan/rtl/ppc-regs.h
  lib/tsan/rtl/tsan_interceptors.cc
  lib/tsan/rtl/tsan_rtl_ppc64.S
  test/tsan/race_on_mutex.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13729.37354.patch
Type: text/x-patch
Size: 11182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/fc09e2f0/attachment.bin>


More information about the llvm-commits mailing list