summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-09-15 11:37:40 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-09-15 11:37:40 +0000
commitbc496dab073a0b0145aea4d4f7f583eb84bea4c4 (patch)
tree3ddac47bb67de0268f346ddaa253306146fa4605
parentc4f23419bb6fc4b871867ccbd8fa3943c51db86c (diff)
downloadbcm5719-llvm-bc496dab073a0b0145aea4d4f7f583eb84bea4c4.tar.gz
bcm5719-llvm-bc496dab073a0b0145aea4d4f7f583eb84bea4c4.zip
[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
-rw-r--r--compiler-rt/lib/asan/asan_rtl.cc5
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common.h3
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_linux.cc8
3 files changed, 16 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc
index b8644c406e5..33c78228372 100644
--- a/compiler-rt/lib/asan/asan_rtl.cc
+++ b/compiler-rt/lib/asan/asan_rtl.cc
@@ -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;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index c974188d485..b265f297d8d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -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() {}
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
index e661fcf1a22..98640f7ce13 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
@@ -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;
OpenPOWER on IntegriCloud