[compiler-rt] r199887 - [asan] Android logging.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Jan 23 03:34:42 PST 2014


Author: eugenis
Date: Thu Jan 23 05:34:41 2014
New Revision: 199887

URL: http://llvm.org/viewvc/llvm-project?rev=199887&view=rev
Log:
[asan] Android logging.

This change duplicates all ASan output to system log on Android.

Modified:
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
    compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
    compiler-rt/trunk/make/platform/clang_linux.mk

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Thu Jan 23 05:34:41 2014
@@ -104,7 +104,7 @@ elseif(ANDROID)
     ${ASAN_CFLAGS})
   set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
     COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
-  target_link_libraries(clang_rt.asan-arm-android dl)
+  target_link_libraries(clang_rt.asan-arm-android dl log)
   list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
 else()
   # Build separate libraries for each target.

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Thu Jan 23 05:34:41 2014
@@ -223,6 +223,7 @@ if(ANDROID)
     ${ASAN_NOINST_TEST_SOURCES})
   set_target_compile_flags(AsanNoinstTest ${ASAN_UNITTEST_COMMON_CFLAGS})
   set_target_link_flags(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LINKFLAGS})
+  target_link_libraries(AsanNoinstTest log)
 
   # Test with ASan instrumentation. Link with ASan dynamic runtime.
   add_executable(AsanTest

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Jan 23 05:34:41 2014
@@ -495,6 +495,12 @@ F IndirectExternCall(F f) {
   return f;
 }
 #endif
+
+#if SANITIZER_ANDROID
+void AndroidLogWrite(const char *buffer);
+#else
+INLINE void AndroidLogWrite(const char *buffer_unused) {}
+#endif
 }  // namespace __sanitizer
 
 inline void *operator new(__sanitizer::operator_new_size_type size,

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Jan 23 05:34:41 2014
@@ -48,6 +48,10 @@
 #include <sys/signal.h>
 #endif
 
+#if SANITIZER_ANDROID
+#include <android/log.h>
+#endif
+
 // <linux/time.h>
 struct kernel_timeval {
   long tv_sec;
@@ -646,6 +650,17 @@ uptr internal_clone(int (*fn)(void *), v
   return res;
 }
 #endif  // defined(__x86_64__)
+
+#if SANITIZER_ANDROID
+// 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) {
+  __android_log_write(ANDROID_LOG_INFO, NULL, buffer);
+}
+#endif
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LINUX

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_printf.cc Thu Jan 23 05:34:41 2014
@@ -272,6 +272,7 @@ static void SharedPrintfCode(bool append
     break;
   }
   RawWrite(buffer);
+  AndroidLogWrite(buffer);
   CallPrintfAndReportCallback(buffer);
   // If we had mapped any memory, clean up.
   if (buffer != local_buffer)

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Thu Jan 23 05:34:41 2014
@@ -165,6 +165,7 @@ if(ANDROID)
   set_target_properties(SanitizerTest PROPERTIES
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
   set_target_link_flags(SanitizerTest ${SANITIZER_TEST_LINK_FLAGS_COMMON})
+  target_link_libraries(SanitizerTest log)
   # Add unit test to test suite.
   add_dependencies(SanitizerUnitTests SanitizerTest)
 endif()

Modified: compiler-rt/trunk/make/platform/clang_linux.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_linux.mk?rev=199887&r1=199886&r2=199887&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_linux.mk (original)
+++ compiler-rt/trunk/make/platform/clang_linux.mk Thu Jan 23 05:34:41 2014
@@ -111,7 +111,7 @@ ANDROID_COMMON_FLAGS := -target arm-linu
 	-B$(LLVM_ANDROID_TOOLCHAIN_DIR)
 CFLAGS.asan-arm-android := $(CFLAGS) -fPIC -fno-builtin \
 	$(ANDROID_COMMON_FLAGS) -mllvm -arm-enable-ehabi -fno-rtti
-LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl -lm \
+LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl -lm -llog \
 	-Wl,-soname=libclang_rt.asan-arm-android.so -Wl,-z,defs
 
 # Use our stub SDK as the sysroot to support more portable building. For now we





More information about the llvm-commits mailing list