This is an archive of the discontinued LLVM Phabricator instance.

tsan: don't call dlsym during exit
ClosedPublic

Authored by dvyukov on Sep 21 2021, 6:31 AM.

Details

Summary

dlsym calls into dynamic linker which calls malloc and other things.
It's problematic to do it during the actual exit, because
it can happen from a singal handler or from within the runtime
after we reported the first bug, etc.
See https://github.com/google/sanitizers/issues/1440 for an example
(captured in the added test).
Initialize the callbacks during startup instead.

Depends on D110159.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Sep 21 2021, 6:31 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2021, 6:31 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vlovich added inline comments.
compiler-rt/test/tsan/signal_exit.cpp
20

Using raise might be nicer as it’s guaranteed to only return once the signal handler has run. Avoids the need for a non-deterministic sleep.

dvyukov updated this revision to Diff 373948.Sep 21 2021, 8:45 AM

use raise instead of kill

dvyukov marked an inline comment as done.Sep 21 2021, 8:45 AM
dvyukov added inline comments.
compiler-rt/test/tsan/signal_exit.cpp
20

Done. Please take another look.

vitalybuka added inline comments.Sep 21 2021, 1:18 PM
compiler-rt/lib/tsan/rtl/tsan_platform_posix.cpp
76–77
compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
39–42
61

Maybe: Probably cleaner to cast just after dlsym and do not keep them as void*.

compiler-rt/lib/tsan/rtl/tsan_rtl.h
989–990
vitalybuka accepted this revision.Sep 21 2021, 2:12 PM

LGTM with nits

This revision is now accepted and ready to land.Sep 21 2021, 2:12 PM
dvyukov marked 2 inline comments as done.Sep 21 2021, 10:07 PM
dvyukov added inline comments.
compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
39–42

I like more encapsulation, but tsan_rtl.cpp is mostly abstract logic independent of platform. It's not a good idea to include <dlfcn.h> here and call dlsym (at the very least won't compile for windows).

I can't think of a simple way to do this. So I fixed types of the callbacks, but kept code where it is.
If you have any suggestions, I will fix.

61

Done.

dvyukov updated this revision to Diff 374110.Sep 21 2021, 10:08 PM
dvyukov marked an inline comment as done.

use real types for the callbacks

dvyukov updated this revision to Diff 374111.Sep 21 2021, 10:10 PM

remove unnecessary parent revision

This revision was landed with ongoing or failed builds.Sep 21 2021, 10:12 PM
This revision was automatically updated to reflect the committed changes.