This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Implement `IsGlobalVar` for Darwin
Needs ReviewPublic

Authored by ismailp on Nov 9 2015, 1:00 PM.

Details

Summary

This is one of the oldest patches made for TSan on Darwin.
It could be wrong, and possibly missing some cases.

Diff Detail

Event Timeline

ismailp updated this revision to Diff 39741.Nov 9 2015, 1:00 PM
ismailp retitled this revision from to [tsan] Implement `IsGlobalVar` for Darwin.
ismailp updated this object.
ismailp added subscribers: llvm-commits, zaks.anna.
dvyukov edited edge metadata.Nov 10 2015, 12:08 AM

IsGlobalData is used only to detect global mutexes.
We use so-called "linker initialized" mutexes as global vars so that they are not subject to initialization and exit races:
https://code.google.com/p/chromium/codesearch#search/&q=LINKER_INITIALIZED&sq=package:chromium&type=cs
But we failed to fit an additional bit into mutex state to explicitly track such mutexes, so now tsan just conservatively assumes that all mutexes are linked-initialized.

I guess we need only SECT_DATA/SECT_COMMON as a mutex cannot be in a const section.
This can also improve performance for some programs.

Also this all must be #ifndef SANITIZER_GO. In fact, whole IsGlobalVar function is not needed for Go.

glider added inline comments.Nov 10 2015, 4:43 PM
lib/tsan/rtl/tsan_platform_mac.cc
43

Please keep the list of includes sorted alphabetically.