[compiler-rt] r345174 - [sanitizer] Avoid calling a nullptr in MonotonicNanoTime if interceptors are not yet initialized

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 11:40:08 PDT 2018


Author: kuba.brecka
Date: Wed Oct 24 11:40:08 2018
New Revision: 345174

URL: http://llvm.org/viewvc/llvm-project?rev=345174&view=rev
Log:
[sanitizer] Avoid calling a nullptr in MonotonicNanoTime if interceptors are not yet initialized

There's a TSan startup crash on Linux when used in Swift programs, where MonotonicNanoTime will try to call real_clock_gettime and then jump to NULL because interceptors are not yet initialized. This is on Ubuntu 18.04. Looks like TSan's main Initialize() function is called at a point where __progname is already set, but interceptors aren't yet set up. Let's fix this by checking whether interceptors are initialized in MonotonicNanoTime.

Differential Revision: https://reviews.llvm.org/D53528


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=345174&r1=345173&r2=345174&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Wed Oct 24 11:40:08 2018
@@ -782,12 +782,15 @@ INLINE bool CanUseVDSO() {
 
 // MonotonicNanoTime is a timing function that can leverage the vDSO by calling
 // clock_gettime. real_clock_gettime only exists if clock_gettime is
-// intercepted, so define it weakly and use it if available.
+// intercepted, so define it weakly and use it if available. MonotonicNanoTime
+// might also be called when interceptors are not yet initialized, so check for
+// that as well.
 extern "C" SANITIZER_WEAK_ATTRIBUTE
 int real_clock_gettime(u32 clk_id, void *tp);
+namespace __interception { int (*real_clock_gettime)(u32 clk_id, void *tp); }
 u64 MonotonicNanoTime() {
   timespec ts;
-  if (CanUseVDSO()) {
+  if (CanUseVDSO() && __interception::real_clock_gettime) {
     if (&real_clock_gettime)
       real_clock_gettime(CLOCK_MONOTONIC, &ts);
     else




More information about the llvm-commits mailing list