Bug 216318

Summary: WebKit should support building with clang ThreadSanitizer enabled
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: Tools / TestsAssignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, ap, benjamin, cdumez, cmarcelo, darin, ddkilzer, ews-watchlist, gyuyoung.kim, jbedard, mark.lam, ryuan.choi, saam, sergio, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 216746    
Attachments:
Description Flags
WIP Patch v1
ddkilzer: review-, ews-feeder: commit-queue-
WIP Patch v2
ews-feeder: commit-queue-
WIP Patch v3
none
Patch v4 none

Description David Kilzer (:ddkilzer) 2020-09-09 10:34:33 PDT
WebKit should support building with clang ThreadSanitizer (TSan) enabled.

The biggest challenge here is to instrument WebKit's custom locking mechanisms so TSan is able to reason correctly about threaded memory accesses.

Also need to make it easy to make it easy to build with TSan enabled like we do with ASan using `set-webkit-configuration --[no-]asan`.

<rdar://problem/31615729>
Comment 1 David Kilzer (:ddkilzer) 2020-09-09 10:38:41 PDT
Created attachment 408340 [details]
WIP Patch v1

This is a WIP that implements basic TSan instrumentation for malloc::Mutex and WTF::Lock classes.

It does not provide a way to enable TSan when building yet, though one can enable ASan and change ENABLE_ADDRESS_SANITIZER=YES to ENABLE_THREAD_SANITIZER=YES in Tools/asan/asan.xcconfig for Apple platforms.
Comment 2 David Kilzer (:ddkilzer) 2020-09-09 16:21:14 PDT
Created attachment 408381 [details]
WIP Patch v2

This adds build support with `make TSAN=YES` and `set-webkit-configuration --[no-]tsan`.

It also fixes the build errors from "WIP Patch v1".

Still not complete since we need to instrument more WTF lock classes.  (I wonder if we can get away with just instrumenting the WTF::Locker class, too.)

Also, I'm not sure if we should instrument malloc::Mutex or not.  We may just end up tossing the bmalloc changes in this patch.
Comment 3 David Kilzer (:ddkilzer) 2020-09-09 18:35:52 PDT
Created attachment 408391 [details]
WIP Patch v3

Fix style issues and make builds.
Comment 4 David Kilzer (:ddkilzer) 2020-09-13 11:18:43 PDT
Created attachment 408656 [details]
Patch v4
Comment 5 EWS 2020-09-15 19:53:41 PDT
Committed r267130: <https://trac.webkit.org/changeset/267130>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 408656 [details].