[all-commits] [llvm/llvm-project] 0c4863: Reland "[TSan][libdispatch] Add interceptors for d...

Julian Lettner via All-commits all-commits at lists.llvm.org
Tue Aug 18 18:35:38 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 0c4863a253957db04549815be218237d6650e5be
      https://github.com/llvm/llvm-project/commit/0c4863a253957db04549815be218237d6650e5be
  Author: Julian Lettner <julian.lettner at apple.com>
  Date:   2020-08-18 (Tue, 18 Aug 2020)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_libdispatch.cpp
    A compiler-rt/test/tsan/libdispatch/async_and_wait.c

  Log Message:
  -----------
  Reland "[TSan][libdispatch] Add interceptors for dispatch_async_and_wait()"

The linker errors caused by this revision have been addressed.

Add interceptors for `dispatch_async_and_wait[_f]()` which was added in
macOS 10.14.  This pair of functions is similar to `dispatch_sync()`,
but does not force a context switch of the queue onto the caller thread
when the queue is active (and hence is more efficient).  For TSan, we
can apply the same semantics as for `dispatch_sync()`.

>From the header docs:
> Differences with dispatch_sync()
>
> When the runtime has brought up a thread to invoke the asynchronous
> workitems already submitted to the specified queue, that servicing
> thread will also be used to execute synchronous work submitted to the
> queue with dispatch_async_and_wait().
>
> However, if the runtime has not brought up a thread to service the
> specified queue (because it has no workitems enqueued, or only
> synchronous workitems), then dispatch_async_and_wait() will invoke the
> workitem on the calling thread, similar to the behaviour of functions
> in the dispatch_sync family.

Additional context:
> The guidance is to use `dispatch_async_and_wait()` instead of
> `dispatch_sync()` when it is necessary to mix async and sync calls on
> the same queue. `dispatch_async_and_wait()` does not guarantee
> execution on the caller thread which allows to reduce context switches
> when the target queue is active.
> https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057

rdar://35757961

Reviewed By: kubamracek

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


  Commit: 686fe293e6c5fd51fa0a3c86a43c2d9a652d53b1
      https://github.com/llvm/llvm-project/commit/686fe293e6c5fd51fa0a3c86a43c2d9a652d53b1
  Author: Julian Lettner <julian.lettner at apple.com>
  Date:   2020-08-18 (Tue, 18 Aug 2020)

  Changed paths:
    M compiler-rt/lib/tsan/rtl/tsan_dispatch_defs.h
    M compiler-rt/lib/tsan/rtl/tsan_interceptors_libdispatch.cpp

  Log Message:
  -----------
  [TSan][libdispatch] Ensure TSan dylib works on old systems

`dispatch_async_and_wait()` was introduced in macOS 10.14, which is
greater than our minimal deployment target.  We need to forward declare
it as a "weak import" to ensure we generate a weak reference so the TSan
dylib continues to work on older systems.  We cannot simply `#include
<dispatch.h>` or use the Darwin availability macros since this file is
multi-platform.

In addition, we want to prevent building these interceptors at all when
building with older SDKs because linking always fails.

Before:
```
➤ dyldinfo -bind ./lib/clang/12.0.0/lib/darwin/libclang_rt.tsan_osx_dynamic.dylib | grep dispatch_async_and_wait
__DATA  __interpose      0x000F5E68    pointer      0 libSystem        _dispatch_async_and_wait_f
```

After:
```
➤ dyldinfo -bind ./lib/clang/12.0.0/lib/darwin/libclang_rt.tsan_osx_dynamic.dylib | grep dispatch_async_and_wait
__DATA  __got            0x000EC0A8    pointer      0 libSystem        _dispatch_async_and_wait (weak import)
__DATA  __interpose      0x000F5E78    pointer      0 libSystem        _dispatch_async_and_wait (weak import)
```

This is a follow-up to D85854 and should fix:
https://reviews.llvm.org/D85854#2221529

Reviewed By: kubamracek

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


  Commit: 40ae296bc39a2780ec4cd99edd87cce35585b9ad
      https://github.com/llvm/llvm-project/commit/40ae296bc39a2780ec4cd99edd87cce35585b9ad
  Author: Julian Lettner <julian.lettner at apple.com>
  Date:   2020-08-18 (Tue, 18 Aug 2020)

  Changed paths:
    M compiler-rt/test/tsan/libdispatch/async_and_wait.c

  Log Message:
  -----------
  [TSan][libdispatch] Guard test execution on old platforms

`dispatch_async_and_wait()` was introduced in macOS 10.14.  Let's
forward declare it to ensure we can compile the test with older SDKs and
guard execution by checking if the symbol is available.  (We can't use
`__builtin_available()`, because that itself requires a higher minimum
deployment target.)  We also need to specify the `-undefined
dynamic_lookup` compiler flag.

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


Compare: https://github.com/llvm/llvm-project/compare/f9dc2b707935...40ae296bc39a


More information about the All-commits mailing list