[PATCH] D24781: [ubsan] Respect log_to_syslog=1 on Darwin

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 16:27:55 PDT 2016


vsk removed a reviewer: samsonov.
vsk updated this revision to Diff 72131.
vsk added a comment.

Teach LogMessageOnPrintf to only write to syslog on Darwin if there is no danger of dead-locking. This is a little cleaner than introducing separate logging functions for ubsan. We also avoid stripping out color codes from the string passed to Printf twice, unnecessarily.

I tested this with a multi-threaded program with both asan+ubsan turned on. I verified that we get syslog output from ubsan but not asan, and that there are no deadlocks:

  // Test:
  //
  //   $ clang++ -std=c++11 -g -O0 -fsanitize=address,integer -fsanitize-recover=address,integer Buggy.cc -o /tmp/Buggy
  //   $ export ASAN_OPTIONS="abort_on_error=0:halt_on_error=0:log_to_syslog=1"
  //   $ export UBSAN_OPTIONS=$ASAN_OPTIONS
  //   $ /tmp/Buggy
  
  #include <thread>
  #include <vector>
  
  void Buggy() {
    for (unsigned I = 0; I < 10; ++I) {
      int *x = new int[4];
      x[0] = x[8] + 1000; //< ASAN: out-of-bounds
      x[0] <<= 30; //< UBSAN: invalid shift
    }
  }
  
  int main() {
    std::vector<std::thread> Threads;
    for (unsigned I = 0; I < 10; ++I)
      Threads.emplace_back(Buggy);
    for (unsigned I = 0; I < 10; ++I)
      Threads[I].join();
    return 0;
  }

I also ran check-sanitizer and check-{a,t,ub}san.


https://reviews.llvm.org/D24781

Files:
  lib/sanitizer_common/sanitizer_common.h
  lib/sanitizer_common/sanitizer_mac.cc
  lib/ubsan/ubsan_init.cc
  test/ubsan/TestCases/Misc/log-path_test.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24781.72131.patch
Type: text/x-patch
Size: 4801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160921/fc78c7ed/attachment.bin>


More information about the llvm-commits mailing list