This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Use runtime checks instead of API level for Android logging
ClosedPublic

Authored by cryptoad on Nov 15 2017, 2:17 PM.

Details

Summary

Recent Bionic have a slew of async_safe_* logging functions that are
basically the liblog ones but included within the libc. They have the advantage
of not allocating memory. async_safe_write_log does no formatting and is
likely the best candidate for logging.

Use a weak definition to try and use it. Also, avoid API level checks (as
the toolchain is compiled at a rather low API level) for __android_log_write
in favor of a weak definition as well.

Keep the fallback to syslog if nothing else was found.

I tried to overhaul the code block to only have a single #if SANITIZER_ANDROID
but I am not particularly attached to the form. LMKWYT.

Event Timeline

cryptoad created this revision.Nov 15 2017, 2:17 PM
eugenis accepted this revision.Nov 15 2017, 2:49 PM
eugenis added inline comments.
lib/sanitizer_common/sanitizer_linux_libcdep.cc
542

Please preserve the comment about syslog being broken pre-L. This is another reason why we prefer __android_log_write when both are available.

__android_log_write may not allocate memory, but it does call pthread_mutex_lock sometimes.

567

nullptr

This revision is now accepted and ready to land.Nov 15 2017, 2:49 PM
cryptoad updated this revision to Diff 123092.Nov 15 2017, 3:11 PM
cryptoad marked 2 inline comments as done.

Addressing review comments.

cryptoad closed this revision.Nov 16 2017, 8:19 AM