This is an archive of the discontinued LLVM Phabricator instance.

[tsan] Modify the tls_race.cc and tls_race2.cc tests to pass on OS X
ClosedPublic

Authored by kubamracek on Nov 20 2015, 7:07 AM.

Details

Summary

On OS X, __thread variables are lazily heap-allocated (with malloc). Therefore, they're recognized as heap blocks (which is what they are) and not as TLS variables in TSan reports. Figuring out if a heap block is a TLS or not is difficult (in malloc interceptor we could analyze the caller and then mark the object), so let's instead modify the tests so that we expect the report to say "Location is heap block" instead of "Location is TLS".

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 40780.Nov 20 2015, 7:07 AM
kubamracek retitled this revision from to [tsan] Modify the tls_race.cc and tls_race2.cc tests to pass on OS X.
kubamracek updated this object.
kubamracek added reviewers: dvyukov, samsonov, kcc, glider.
dvyukov added inline comments.Nov 20 2015, 8:31 AM
test/tsan/tls_race.cc
23

How does the heap block allocation stack look like? Is it possible to figure out that this is TLS from the stack?

test/tsan/tls_race2.cc
28–30

revert this back to "thread T1"

kubamracek added inline comments.Nov 20 2015, 9:06 AM
test/tsan/tls_race.cc
23

The stack looks like this:

* frame #0: 0x0000000100077890 libclang_rt.tsan_osx_dynamic.dylib`::wrap_malloc(size=4294971592) at sanitizer_malloc_mac.inc:96
  frame #1: 0x00007fff86555d7d libdyld.dylib`tlv_allocate_and_initialize_for_key + 370
  frame #2: 0x00007fff8655652c libdyld.dylib`tlv_get_addr + 296
  frame #3: 0x0000000100000dc7 tls_race.cc.tmp`main + 55 at tls_race.cc:14 [opt]
  frame #4: 0x00007fff865565ad libdyld.dylib`start + 1

To figure out this is a TLS, we could recognize that the caller is tlv_allocate_and_initialize_for_key, but for that we'd need to symbolicate first. FYI, there are no other calls to malloc from tlv_allocate_and_initialize_for_key. This function is internal (non-interceptible). If you have any easy solution in mind, please tell me.

dvyukov added inline comments.Nov 20 2015, 9:32 AM
test/tsan/tls_race.cc
23

OK, let's leave it as is for now.

Updating patch.

dvyukov accepted this revision.Nov 22 2015, 11:03 PM
dvyukov edited edge metadata.
This revision is now accepted and ready to land.Nov 22 2015, 11:03 PM
This revision was automatically updated to reflect the committed changes.