[asan] Delay system log initialization on Android.
Writing to system log requires libc interceptors to be initialized. Fixes crashes with verbosity=1 on newer Android builds. llvm-svn: 217764
This commit is contained in:
parent
c4f23419bb
commit
bc496dab07
|
@ -592,6 +592,11 @@ static void AsanInitInternal() {
|
|||
|
||||
InitializeAsanInterceptors();
|
||||
|
||||
// Enable system log ("adb logcat") on Android.
|
||||
// Doing this before interceptors are initialized crashes in:
|
||||
// AsanInitInternal -> android_log_write -> __interceptor_strcmp
|
||||
AndroidLogInit();
|
||||
|
||||
ReplaceSystemMalloc();
|
||||
|
||||
uptr shadow_start = kLowShadowBeg;
|
||||
|
|
|
@ -544,10 +544,13 @@ F IndirectExternCall(F f) {
|
|||
#endif
|
||||
|
||||
#if SANITIZER_ANDROID
|
||||
// Initialize Android logging. Any writes before this are silently lost.
|
||||
void AndroidLogInit();
|
||||
void AndroidLogWrite(const char *buffer);
|
||||
void GetExtraActivationFlags(char *buf, uptr size);
|
||||
void SanitizerInitializeUnwinder();
|
||||
#else
|
||||
INLINE void AndroidLogInit() {}
|
||||
INLINE void AndroidLogWrite(const char *buffer_unused) {}
|
||||
INLINE void GetExtraActivationFlags(char *buf, uptr size) { *buf = '\0'; }
|
||||
INLINE void SanitizerInitializeUnwinder() {}
|
||||
|
|
|
@ -836,11 +836,19 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
|
|||
#endif // defined(__x86_64__) && SANITIZER_LINUX
|
||||
|
||||
#if SANITIZER_ANDROID
|
||||
static atomic_uint8_t android_log_initialized;
|
||||
|
||||
void AndroidLogInit() {
|
||||
atomic_store(&android_log_initialized, 1, memory_order_release);
|
||||
}
|
||||
// This thing is not, strictly speaking, async signal safe, but it does not seem
|
||||
// to cause any issues. Alternative is writing to log devices directly, but
|
||||
// their location and message format might change in the future, so we'd really
|
||||
// like to avoid that.
|
||||
void AndroidLogWrite(const char *buffer) {
|
||||
if (!atomic_load(&android_log_initialized, memory_order_acquire))
|
||||
return;
|
||||
|
||||
char *copy = internal_strdup(buffer);
|
||||
char *p = copy;
|
||||
char *q;
|
||||
|
|
Loading…
Reference in New Issue