This is an archive of the discontinued LLVM Phabricator instance.

tsan: introduce LazyInitialize
ClosedPublic

Authored by dvyukov on Jul 29 2021, 6:42 AM.

Details

Summary

We call non-inlinable Initialize from all interceptors/syscalls,
but most of the time runtime is already initialized and this just
introduces unnecessary overhead.
Add LazyInitialize that (1) inlinable, (2) does nothing if
.preinit_array is enabled (expected case on Linux).

Depends on D107071.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Jul 29 2021, 6:42 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 29 2021, 6:42 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Jul 29 2021, 8:12 AM
melver added inline comments.
compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
391

Is it the case that now Initialize() should only be called if !is_initialized?

In which case CHECK(!is_initialized) could say if this is wrongly used instead of LazyInitialize().

This revision is now accepted and ready to land.Jul 29 2021, 8:12 AM
dvyukov added inline comments.Jul 29 2021, 8:17 AM
compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
391

No, it's not the case.

.preinit_array and module constructors call tsan_init multiple times.
tsan_init needs to call Initialize, it can't call LazyInitialize, because LazyInitialize is a nop if .preinit_array is enabled. So if we call LazyInitialize from .preinit_array, it won't actually initialize.

This revision was automatically updated to reflect the committed changes.