Page MenuHomePhabricator

[compiler-rt] Fall back to internal_uname() when called early
ClosedPublic

Authored by iii on Mar 27 2020, 5:07 AM.

Details

Summary

Commit 5f5fb56c68e4 ("[compiler-rt] Intercept the uname() function")
broke sanitizer-x86_64-linux and clang-cmake-thumbv7-full-sh (again)
builds:

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/26313
http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh/builds/4324

The reason is that uname() can be called as early as
__pthread_initialize_minimal_internal(). When intercepted, this
triggers ASan initialization, which eventually calls dlerror(), which
in turn uses pthreads, causing all sorts of issues.

Fix by falling back to internal_uname() when interceptor runs before
ASan is initialized. This is only for Linux at the moment.

Diff Detail

Event Timeline

iii created this revision.Mar 27 2020, 5:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2020, 5:07 AM
Herald added subscribers: Restricted Project, dberris. · View Herald Transcript

It looks like msan does not define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED.
Does it need to? Why is it not broken the same way right now?

iii added a comment.Mar 27 2020, 11:40 AM

msan does not call Symbolizer::LateInitialize(), which is Symbolizer::GetOrInit() + InitializeSwiftDemangler(). It calls only Symbolizer::GetOrInit(), and it's exactly InitializeSwiftDemangler() that triggers dlerror(). So for now it looks safe, but not particularly future-proof. #define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED (!msan_inited) might be a good idea. Should I try to do this here, or separately?

eugenis accepted this revision.Mar 27 2020, 12:16 PM

Sounds like a good idea, as a separate change.
Thank you!
LGTM

This revision is now accepted and ready to land.Mar 27 2020, 12:16 PM
vitalybuka added inline comments.Mar 27 2020, 1:36 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
9751

Can you please remove "#if SANITIZER_LINUX" ?
I don't see why we need this constrain.

iii added a comment.Mar 27 2020, 3:10 PM

internal_uname() is available only on Linux right now. I thought it's ok to postpone adding macOS/*BSD/etc implementations until that is really necessary.

In D76919#1947069, @iii wrote:

internal_uname() is available only on Linux right now. I thought it's ok to postpone adding macOS/*BSD/etc implementations until that is really necessary.

ack

vitalybuka accepted this revision.Mar 27 2020, 3:30 PM
This revision was automatically updated to reflect the committed changes.