[all-commits] [llvm/llvm-project] 6a4c39: [scudo] Add the thread-safety annotations

ChiaHungDuan via All-commits all-commits at lists.llvm.org
Tue Feb 14 17:20:59 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6a4c39596d688955f203351bb28f72c7bc1e93d6
      https://github.com/llvm/llvm-project/commit/6a4c39596d688955f203351bb28f72c7bc1e93d6
  Author: Chia-hung Duan <chiahungduan at google.com>
  Date:   2023-02-15 (Wed, 15 Feb 2023)

  Changed paths:
    M compiler-rt/lib/scudo/standalone/CMakeLists.txt
    M compiler-rt/lib/scudo/standalone/combined.h
    M compiler-rt/lib/scudo/standalone/fuchsia.cpp
    M compiler-rt/lib/scudo/standalone/linux.cpp
    M compiler-rt/lib/scudo/standalone/mutex.h
    M compiler-rt/lib/scudo/standalone/primary32.h
    M compiler-rt/lib/scudo/standalone/primary64.h
    M compiler-rt/lib/scudo/standalone/quarantine.h
    M compiler-rt/lib/scudo/standalone/release.h
    M compiler-rt/lib/scudo/standalone/secondary.h
    M compiler-rt/lib/scudo/standalone/stats.h
    M compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
    M compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
    M compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp
    M compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
    A compiler-rt/lib/scudo/standalone/thread_annotations.h
    M compiler-rt/lib/scudo/standalone/trusty.cpp
    M compiler-rt/lib/scudo/standalone/tsd.h
    M compiler-rt/lib/scudo/standalone/tsd_exclusive.h
    M compiler-rt/lib/scudo/standalone/tsd_shared.h

  Log Message:
  -----------
  [scudo] Add the thread-safety annotations

This CL adds the proper thread-safety annotations for most of the
functions and variables. However, given the restriction of the current
architecture, in some cases, we may not be able to use the annotations
easily. The followings are two exceptions,

1. enable()/disable(): Many structures in scudo are enabled/disabled by
   acquiring the lock in each instance. This makes those structure act
   like a `lock`. We can't mark those functions with ACQUIRE()/RELEASE()
   because that makes the entire allocator become another `lock`. In the
   end, that implies we need to *acquire* the `allocator` before each
   malloc et al. request. Therefore, adding a variable to tell the
   status of those structures may be a better way to cooperate with
   thread-safety annotation.

2. TSD/TSD shared/TSD exclusive: These three have simiar restrictions as
   mentioned above. In addition, they don't always need to be released
   if it's a thread local instance. However, thread-safety analysis
   doesn't support conditional branch. Which means we can't mark the
   proper annotations around the uses of TSDs. We may consider to make
   it consistent and which makes the code structure simpler.

This CL is supposed to introduce the annotations with the least code
refactoring. So only trivial thread safety issues will be addressed
here. For example, lacking of acquiring certain lock before accessing
certain variables will have the ScopedLock inserted. Other than that,
they are supposed to be done in the later changes.

Reviewed By: cferris

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




More information about the All-commits mailing list