[compiler-rt] r218605 - [sanitizer] Android build cleanup.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Sep 29 06:18:56 PDT 2014


Author: eugenis
Date: Mon Sep 29 08:18:55 2014
New Revision: 218605

URL: http://llvm.org/viewvc/llvm-project?rev=218605&view=rev
Log:
[sanitizer] Android build cleanup.

* Detect Android toolchain target arch and set correct runtime library name.
* Merged a lot of Android and non-Android code paths.
* Android is only supported in standalone build of compiler-rt now.
* Linking lsan-common in ASan-Android (makes lsan annotations work).
* Relying on -fsanitize=address linker flag when building tests (again,
  unification with non-Android path).
* Runtime library moved from lib/asan to lib/linux.

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/asan/scripts/asan_device_setup
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/interception/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
    compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
    compiler-rt/trunk/test/asan/CMakeLists.txt
    compiler-rt/trunk/test/asan/lit.cfg
    compiler-rt/trunk/test/asan/lit.site.cfg.in

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -207,7 +207,8 @@ option(COMPILER_RT_DEBUG "Build runtimes
 pythonize_bool(COMPILER_RT_DEBUG)
 
 # We have to support both static and dynamic/shared runtime on Windows.
-if(WIN32)
+# Android only works with dynamic runtime.
+if(WIN32 OR ANDROID)
 option(COMPILER_RT_BUILD_SHARED_ASAN "Build shared version of AddressSanitizer runtime" ON)
 else()
 option(COMPILER_RT_BUILD_SHARED_ASAN "Build shared version of AddressSanitizer runtime" OFF)

Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Mon Sep 29 08:18:55 2014
@@ -43,7 +43,8 @@ endmacro()
 # add_compiler_rt_runtime(<name> <arch> {STATIC,SHARED}
 #                         SOURCES <source files>
 #                         CFLAGS <compile flags>
-#                         DEFS <compile definitions>)
+#                         DEFS <compile definitions>
+#                         OUTPUT_NAME <output library name>)
 macro(add_compiler_rt_runtime name arch type)
   if(CAN_TARGET_${arch})
     parse_arguments(LIB "SOURCES;CFLAGS;DEFS;OUTPUT_NAME" "" ${ARGN})
@@ -59,7 +60,10 @@ macro(add_compiler_rt_runtime name arch
     set_target_properties(${name} PROPERTIES
       ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
       LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
-    if (LIB_OUTPUT_NAME)
+    if ("${LIB_OUTPUT_NAME}" STREQUAL "")
+      set_target_properties(${name} PROPERTIES
+        OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX})
+    else()
       set_target_properties(${name} PROPERTIES
         OUTPUT_NAME ${LIB_OUTPUT_NAME})
     endif()

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Mon Sep 29 08:18:55 2014
@@ -79,16 +79,47 @@ macro(test_target_arch arch)
               CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
   if(${CAN_TARGET_${arch}})
     list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
-  elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}" OR
-         "${arch}" STREQUAL "arm_android")
+  elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}")
     # Bail out if we cannot target the architecture we plan to test.
     message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
   endif()
 endmacro()
 
+# Add $arch as supported with no additional flags.
+macro(add_default_target_arch arch)
+  set(TARGET_${arch}_CFLAGS "")
+  set(CAN_TARGET_${arch} 1)
+  list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
+endmacro()
+
+macro(detect_target_arch)
+  check_symbol_exists(__arm__ "" __ARM)
+  check_symbol_exists(__aarch64__ "" __AARCH64)
+  check_symbol_exists(__x86_64__ "" __X86_64)
+  check_symbol_exists(__i386__ "" __I386)
+  check_symbol_exists(__mips__ "" __MIPS)
+  check_symbol_exists(__mips64__ "" __MIPS64)
+  if(__ARM)
+    add_default_target_arch(arm)
+  elseif(__AARCH64)
+    add_default_target_arch(aarch64)
+  elseif(__X86_64)
+    add_default_target_arch(x86_64)
+  elseif(__I386)
+    add_default_target_arch(i386)
+  elseif(__MIPS64) # must be checked before __MIPS
+    add_default_target_arch(mips64)
+  elseif(__MIPS)
+    add_default_target_arch(mips)
+  endif()
+endmacro()
+
 # Generate the COMPILER_RT_SUPPORTED_ARCH list.
 if(ANDROID)
-  test_target_arch(arm_android "")
+  # Can't rely on LLVM_NATIVE_ARCH in cross-compilation.
+  # Examine compiler output instead.
+  detect_target_arch()
+  set(COMPILER_RT_OS_SUFFIX "-android")
 else()
   if("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
     if (NOT MSVC)
@@ -105,8 +136,11 @@ else()
     test_target_arch(arm "-march=armv7-a")
     test_target_arch(aarch64 "-march=armv8-a")
   endif()
+  set(COMPILER_RT_OS_SUFFIX "")
 endif()
 
+message("Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
+
 # Takes ${ARGN} and puts only supported architectures in @out_var list.
 function(filter_available_targets out_var)
   set(archs)
@@ -120,11 +154,10 @@ function(filter_available_targets out_va
 endfunction()
 
 # Arhcitectures supported by compiler-rt libraries.
-# FIXME: add arm_android here
 filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
-  x86_64 i386 powerpc64 arm aarch64 mips arm_android)
+  x86_64 i386 powerpc64 arm aarch64 mips)
 filter_available_targets(ASAN_SUPPORTED_ARCH
-  x86_64 i386 powerpc64 arm mips arm_android)
+  x86_64 i386 powerpc64 arm mips)
 filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
 filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
 # LSan common files should be available on all architectures supported
@@ -173,7 +206,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_COMMON_SUPPORTED_ARCH AND
-    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Android")
   set(COMPILER_RT_HAS_LSAN_COMMON TRUE)
 else()
   set(COMPILER_RT_HAS_LSAN_COMMON FALSE)

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -66,6 +66,8 @@ append_if(COMPILER_RT_HAS_LIBM m ASAN_DY
 append_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
 append_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ ASAN_DYNAMIC_LIBS)
 
+append_if(ANDROID log ASAN_DYNAMIC_LIBS)
+
 # Compile ASan sources into an object library.
 if(APPLE)
   foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
@@ -75,11 +77,6 @@ if(APPLE)
       CFLAGS ${ASAN_CFLAGS}
       DEFS ${ASAN_COMMON_DEFINITIONS})
   endforeach()
-elseif(ANDROID)
-  add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES} ${ASAN_CXX_SOURCES})
-  set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
-  set_property(TARGET RTAsan.arm.android APPEND PROPERTY
-    COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
 else()
   foreach(arch ${ASAN_SUPPORTED_ARCH})
     add_compiler_rt_object_library(RTAsan ${arch}
@@ -114,21 +111,6 @@ if(APPLE)
       DEFS ${ASAN_COMMON_DEFINITIONS})
     add_dependencies(asan clang_rt.asan_${os}_dynamic)
   endforeach()
-
-elseif(ANDROID)
-  add_library(clang_rt.asan-arm-android SHARED
-    $<TARGET_OBJECTS:RTAsan.arm.android>
-    $<TARGET_OBJECTS:RTInterception.arm.android>
-    $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
-  set_target_compile_flags(clang_rt.asan-arm-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 log)
-  add_dependencies(asan clang_rt.asan-arm-android)
-  install(TARGETS clang_rt.asan-arm-android
-          ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-          LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
 else()
   # Build separate libraries for each target.
   foreach(arch ${ASAN_SUPPORTED_ARCH})
@@ -136,7 +118,7 @@ else()
       $<TARGET_OBJECTS:RTInterception.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
-    if (NOT WIN32)
+    if(NOT WIN32)
       # We can't build Leak Sanitizer on Windows yet.
       list(APPEND ASAN_COMMON_RUNTIME_OBJECTS
            $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
@@ -164,9 +146,9 @@ else()
       add_dependencies(asan clang_rt.asan-preinit-${arch})
 
       if (WIN32)
-         set(SHARED_ASAN_NAME clang_rt.asan_dynamic-${arch})
+         set(SHARED_ASAN_NAME clang_rt.asan_dynamic-${arch}${COMPILER_RT_OS_SUFFIX})
       else()
-         set(SHARED_ASAN_NAME clang_rt.asan-${arch})
+         set(SHARED_ASAN_NAME clang_rt.asan-${arch}${COMPILER_RT_OS_SUFFIX})
       endif()
 
       add_compiler_rt_runtime(clang_rt.asan-dynamic-${arch} ${arch} SHARED

Modified: compiler-rt/trunk/lib/asan/scripts/asan_device_setup
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_device_setup?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/scripts/asan_device_setup (original)
+++ compiler-rt/trunk/lib/asan/scripts/asan_device_setup Mon Sep 29 08:18:55 2014
@@ -107,8 +107,8 @@ elif [[ -f "$HERE/$ASAN_RT" ]]; then
     ASAN_RT_PATH="$HERE"
 elif [[ $(basename "$HERE") == "bin" ]]; then
     # We could be in the toolchain's base directory.
-    # Consider ../lib, ../lib/asan and ../lib/clang/$VERSION/lib/linux.
-    P=$(ls "$HERE"/../lib/"$ASAN_RT" "$HERE"/../lib/asan/"$ASAN_RT" "$HERE"/../lib/clang/*/lib/linux/"$ASAN_RT" 2>/dev/null | sort | tail -1)
+    # Consider ../lib, ../lib/asan, ../lib/linux and ../lib/clang/$VERSION/lib/linux.
+    P=$(ls "$HERE"/../lib/"$ASAN_RT" "$HERE"/../lib/asan/"$ASAN_RT" "$HERE"/../lib/linux/"$ASAN_RT" "$HERE"/../lib/clang/*/lib/linux/"$ASAN_RT" 2>/dev/null | sort | tail -1)
     if [[ -n "$P" ]]; then
         ASAN_RT_PATH="$(dirname "$P")"
     fi

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=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -73,16 +73,16 @@ endif()
 
 set(ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS
   ${ASAN_UNITTEST_COMMON_LINKFLAGS})
-# On Android, we link with ASan runtime manually. On other platforms we depend
-# on Clang driver behavior, passing -fsanitize=address flag.
-if(NOT ANDROID)
-  list(APPEND ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS -fsanitize=address)
-endif()
+list(APPEND ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS -fsanitize=address)
 
 set(ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS
   ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}
   -shared-libasan)
 
+set(ASAN_UNITTEST_INSTRUMENTED_LIBS)
+# NDK r10 requires -latomic almost always.
+append_if(ANDROID atomic ASAN_UNITTEST_INSTRUMENTED_LIBS)
+
 set(ASAN_UNITTEST_NOINST_LINKFLAGS ${ASAN_UNITTEST_COMMON_LINKFLAGS})
 append_if(COMPILER_RT_HAS_LIBM -lm ASAN_UNITTEST_NOINST_LINKFLAGS)
 append_if(COMPILER_RT_HAS_LIBDL -ldl ASAN_UNITTEST_NOINST_LINKFLAGS)
@@ -90,6 +90,12 @@ append_if(COMPILER_RT_HAS_LIBPTHREAD -pt
 append_if(COMPILER_RT_HAS_LIBPTHREAD -pthread
           ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS)
 
+# TODO(eugenis): move all -l flags above to _LIBS?
+set(ASAN_UNITTEST_NOINST_LIBS)
+append_if(ANDROID log ASAN_UNITTEST_NOINST_LIBS)
+# NDK r10 requires -latomic almost always.
+append_if(ANDROID atomic ASAN_UNITTEST_NOINST_LIBS)
+
 # Compile source for the given architecture, using compiler
 # options in ${ARGN}, and add it to the object list.
 macro(asan_compile obj_list source arch kind)
@@ -198,7 +204,7 @@ macro(add_asan_tests_for_arch_and_kind a
       $<TARGET_OBJECTS:RTInterception.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
-    if(NOT MSVC)
+    if(NOT WIN32)
       list(APPEND ASAN_TEST_RUNTIME_OBJECTS
            $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
     endif()
@@ -242,31 +248,31 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT
 endif()
 
 if(ANDROID)
-  # We assume that unit tests on Android are built in a build
-  # tree with fresh Clang as a host compiler.
-  
-  # Test w/o ASan instrumentation. Link it with ASan statically.
-  add_executable(AsanNoinstTest
-    $<TARGET_OBJECTS:RTAsan.arm.android>
-    $<TARGET_OBJECTS:RTInterception.arm.android>
-    $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>
-    ${COMPILER_RT_GTEST_SOURCE}
-    ${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
-    ${COMPILER_RT_GTEST_SOURCE}
-    ${ASAN_INST_TEST_SOURCES})
-  set_target_compile_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS})
-  set_target_link_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS})
-  target_link_libraries(AsanTest clang_rt.asan-arm-android)
-
-  # Setup correct output directory and link flags.
-  set_target_properties(AsanNoinstTest AsanTest PROPERTIES
-    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-  # Add unit test to test suite.
-  add_dependencies(AsanUnitTests AsanNoinstTest AsanTest)
+  foreach(arch ${ASAN_SUPPORTED_ARCH})
+    # Test w/o ASan instrumentation. Link it with ASan statically.
+    add_executable(AsanNoinstTest # FIXME: .arch?
+      $<TARGET_OBJECTS:RTAsan.${arch}>
+      $<TARGET_OBJECTS:RTInterception.${arch}>
+      $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
+      $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+      ${COMPILER_RT_GTEST_SOURCE}
+      ${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 ${ASAN_UNITTEST_NOINST_LIBS})
+
+    # Test with ASan instrumentation. Link with ASan dynamic runtime.
+    add_executable(AsanTest
+      ${COMPILER_RT_GTEST_SOURCE}
+      ${ASAN_INST_TEST_SOURCES})
+    set_target_compile_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS})
+    set_target_link_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS})
+    target_link_libraries(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LIBS})
+
+    # Setup correct output directory and link flags.
+    set_target_properties(AsanNoinstTest AsanTest PROPERTIES
+      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+    # Add unit tests to the test suite.
+    add_dependencies(AsanUnitTests AsanNoinstTest AsanTest)
+  endforeach()
 endif()

Modified: compiler-rt/trunk/lib/interception/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/interception/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -20,10 +20,6 @@ if(APPLE)
       SOURCES ${INTERCEPTION_SOURCES}
       CFLAGS ${INTERCEPTION_CFLAGS})
   endforeach()
-elseif(ANDROID)
-  add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES})
-  set_target_compile_flags(RTInterception.arm.android
-    ${INTERCEPTION_CFLAGS})
 else()
   # Otherwise, build separate libraries for each target.
   foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})

Modified: compiler-rt/trunk/lib/lsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -25,7 +25,7 @@ if(APPLE)
       SOURCES ${LSAN_COMMON_SOURCES}
       CFLAGS ${LSAN_CFLAGS})
   endforeach()
-elseif(NOT ANDROID)
+else()
   foreach(arch ${LSAN_COMMON_SUPPORTED_ARCH})
     add_compiler_rt_object_library(RTLSanCommon ${arch}
       SOURCES ${LSAN_COMMON_SOURCES}

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -121,14 +121,6 @@ if(APPLE)
       DEFS ${SANITIZER_COMMON_DEFINITIONS})
     list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${os})
   endforeach()
-elseif(ANDROID)
-  add_library(RTSanitizerCommon.arm.android OBJECT
-    ${SANITIZER_SOURCES} ${SANITIZER_LIBCDEP_SOURCES})
-  set_target_compile_flags(RTSanitizerCommon.arm.android
-    ${SANITIZER_CFLAGS})
-  set_property(TARGET RTSanitizerCommon.arm.android APPEND PROPERTY
-    COMPILE_DEFINITIONS ${SANITIZER_COMMON_DEFINITIONS})
-  list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.arm.android)
 else()
   # Otherwise, build separate libraries for each target.
   foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Mon Sep 29 08:18:55 2014
@@ -472,7 +472,7 @@ namespace __sanitizer {
   typedef long __sanitizer___kernel_off_t;
 #endif
 
-#if defined(__powerpc__) || defined(__aarch64__) || defined(__mips__)
+#if defined(__powerpc__) || defined(__mips__)
   typedef unsigned int __sanitizer___kernel_old_uid_t;
   typedef unsigned int __sanitizer___kernel_old_gid_t;
 #else

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=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -57,6 +57,11 @@ if(NOT MSVC)
   list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON --driver-mode=g++)
 endif()
 
+set(SANITIZER_TEST_LINK_LIBS)
+append_if(ANDROID log SANITIZER_TEST_LINK_LIBS)
+# NDK r10 requires -latomic almost always.
+append_if(ANDROID atomic SANITIZER_TEST_LINK_LIBS)
+
 append_if(COMPILER_RT_HAS_LIBDL -ldl SANITIZER_TEST_LINK_FLAGS_COMMON)
 append_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SANITIZER_TEST_LINK_FLAGS_COMMON)
 # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. Also,
@@ -172,20 +177,21 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT
 endif()
 
 if(ANDROID)
-  # We assume that unit tests on Android are built in a build
-  # tree with fresh Clang as a host compiler.
-  add_executable(SanitizerTest
-    ${SANITIZER_UNITTESTS}
-    ${COMPILER_RT_GTEST_SOURCE}
-    $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
-  set_target_compile_flags(SanitizerTest
-    ${SANITIZER_COMMON_CFLAGS}
-    ${SANITIZER_TEST_CFLAGS_COMMON})
-  # Setup correct output directory and link flags.
-  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)
+  foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})
+    add_executable(SanitizerTest
+      ${SANITIZER_UNITTESTS}
+      ${COMPILER_RT_GTEST_SOURCE}
+      $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
+      $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
+    set_target_compile_flags(SanitizerTest
+      ${SANITIZER_COMMON_CFLAGS}
+      ${SANITIZER_TEST_CFLAGS_COMMON})
+    # Setup correct output directory and link flags.
+    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 ${SANITIZER_TEST_LINK_LIBS})
+    # Add unit test to test suite.
+    add_dependencies(SanitizerUnitTests SanitizerTest)
+  endforeach()
 endif()

Modified: compiler-rt/trunk/test/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/CMakeLists.txt?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/asan/CMakeLists.txt Mon Sep 29 08:18:55 2014
@@ -2,113 +2,132 @@ set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_
 
 set(ASAN_TESTSUITES)
 
-if(CAN_TARGET_arm_android)
-  # This is only true if we are cross-compiling.
-  # Build all tests with host compiler and use host tools.
-  set(ASAN_TEST_TARGET_CC ${CMAKE_C_COMPILER})
-  set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
-  get_filename_component(ASAN_TEST_LLVM_TOOLS_DIR ${CMAKE_C_COMPILER} PATH)
-  set(ASAN_TEST_CONFIG_SUFFIX "-arm-android")
-  set(ASAN_TEST_BITS "32")
-  set(ASAN_TEST_DYNAMIC True)
-  set(ASAN_TEST_TARGET_ARCH "arm-android")
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/ARMAndroidConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/ARMAndroidConfig)
-endif()
+macro(get_bits_for_arch arch bits)
+  if (${arch} STREQUAL "arm" OR
+      ${arch} STREQUAL "i386" OR
+      ${arch} STREQUAL "mips")
+    set(bits 32)
+  elseif (${arch} STREQUAL "aarch64" OR
+      ${arch} STREQUAL "x86_64" OR
+      ${arch} STREQUAL "mips64")
+    set(bits 64)
+  else()
+    message(FATAL_ERROR "Unknown target architecture: ${arch}")
+  endif()
+endmacro()
 
-if(CAN_TARGET_arm)
-  # This is only true if we are cross-compiling.
-  # Build all tests with host compiler and use host tools.
-  set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
-  set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
-  set(ASAN_TEST_CONFIG_SUFFIX "-arm-linux")
-  set(ASAN_TEST_BITS "32")
-  set(ASAN_TEST_DYNAMIC False)
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/ARMLinuxConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/ARMLinuxConfig)
-endif()
+# TODO: merge with non-ANDROID case
+if(ANDROID)
+  foreach(arch ${ASAN_SUPPORTED_ARCH})
+    set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+    set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+    set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-android")
+    get_bits_for_arch(${arch} ASAN_TEST_BITS)
+    set(ASAN_TEST_DYNAMIC True)
+    set(ASAN_TEST_TARGET_ARCH "${arch}-android")
+    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+    set(CONFIG ${ARCH_UPPER_CASE}AndroidConfig)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG}/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG})
+  endforeach()
+
+else()  # Not Android
+
+  if(CAN_TARGET_arm)
+    # This is only true if we are cross-compiling.
+    # Build all tests with host compiler and use host tools.
+    set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+    set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+    set(ASAN_TEST_CONFIG_SUFFIX "-arm-linux")
+    set(ASAN_TEST_BITS "32")
+    set(ASAN_TEST_DYNAMIC False)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/ARMLinuxConfig/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/ARMLinuxConfig)
+  endif()
 
-if(CAN_TARGET_aarch64)
-  # This is only true if we are cross-compiling.
-  # Build all tests with host compiler and use host tools.
-  set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
-  set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
-  set(ASAN_TEST_CONFIG_SUFFIX "-aarch64-linux")
-  set(ASAN_TEST_BITS "64")
-  set(ASAN_TEST_DYNAMIC False)
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig)
-endif()
+  if(CAN_TARGET_aarch64)
+    # This is only true if we are cross-compiling.
+    # Build all tests with host compiler and use host tools.
+    set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+    set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+    set(ASAN_TEST_CONFIG_SUFFIX "-aarch64-linux")
+    set(ASAN_TEST_BITS "64")
+    set(ASAN_TEST_DYNAMIC False)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig)
+  endif()
 
-if(CAN_TARGET_x86_64 OR CAN_TARGET_powerpc64)
-  set(ASAN_TEST_CONFIG_SUFFIX "64")
-  set(ASAN_TEST_BITS "64")
-  set(ASAN_TEST_TARGET_CFLAGS ${TARGET_64_BIT_CFLAGS})
-  set(ASAN_TEST_DYNAMIC False)
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig)
-  if(COMPILER_RT_BUILD_SHARED_ASAN)
-    set(ASAN_TEST_CONFIG_SUFFIX "64-Dynamic")
-    set(ASAN_TEST_DYNAMIC True)
+  if(CAN_TARGET_x86_64 OR CAN_TARGET_powerpc64)
+    set(ASAN_TEST_CONFIG_SUFFIX "64")
+    set(ASAN_TEST_BITS "64")
+    set(ASAN_TEST_TARGET_CFLAGS ${TARGET_64_BIT_CFLAGS})
+    set(ASAN_TEST_DYNAMIC False)
     configure_lit_site_cfg(
       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-      ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic/lit.site.cfg)
-    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic)
+      ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig)
+    if(COMPILER_RT_BUILD_SHARED_ASAN)
+      set(ASAN_TEST_CONFIG_SUFFIX "64-Dynamic")
+      set(ASAN_TEST_DYNAMIC True)
+      configure_lit_site_cfg(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+        ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic/lit.site.cfg)
+      list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/64bitConfig-dynamic)
+    endif()
   endif()
-endif()
 
-if(CAN_TARGET_i386)
-  set(ASAN_TEST_CONFIG_SUFFIX "32")
-  set(ASAN_TEST_BITS "32")
-  set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
-  set(ASAN_TEST_DYNAMIC False)
-  set(ASAN_TEST_TARGET_ARCH "i386")
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
-  if(COMPILER_RT_BUILD_SHARED_ASAN)
-    set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
-    set(ASAN_TEST_DYNAMIC True)
+  if(CAN_TARGET_i386)
+    set(ASAN_TEST_CONFIG_SUFFIX "32")
+    set(ASAN_TEST_BITS "32")
+    set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
+    set(ASAN_TEST_DYNAMIC False)
+    set(ASAN_TEST_TARGET_ARCH "i386")
     configure_lit_site_cfg(
       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-      ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
-    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
+      ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
+    if(COMPILER_RT_BUILD_SHARED_ASAN)
+      set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
+      set(ASAN_TEST_DYNAMIC True)
+      configure_lit_site_cfg(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+        ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
+      list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
+    endif()
   endif()
-endif()
 
-if(CAN_TARGET_mips)
-  set(ASAN_TEST_CONFIG_SUFFIX "32")
-  set(ASAN_TEST_BITS "32")
-  set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
-  set(ASAN_TEST_DYNAMIC False)
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-    ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
-    )
-  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
-  if(COMPILER_RT_BUILD_SHARED_ASAN)
-    set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
-    set(ASAN_TEST_DYNAMIC True)
+  if(CAN_TARGET_mips)
+    set(ASAN_TEST_CONFIG_SUFFIX "32")
+    set(ASAN_TEST_BITS "32")
+    set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
+    set(ASAN_TEST_DYNAMIC False)
     configure_lit_site_cfg(
       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-      ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
-    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
+      ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
+      )
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
+    if(COMPILER_RT_BUILD_SHARED_ASAN)
+      set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
+      set(ASAN_TEST_DYNAMIC True)
+      configure_lit_site_cfg(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+        ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
+      list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
+    endif()
   endif()
-endif()
+endif()  # Not Android
 
 if(COMPILER_RT_INCLUDE_TESTS)
   configure_lit_site_cfg(
@@ -124,7 +143,7 @@ else()
 endif()
 
 # FIXME: support unit test in the android test runner
-if(COMPILER_RT_INCLUDE_TESTS AND NOT CAN_TARGET_arm_android)
+if(COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID)
   list(APPEND ASAN_TEST_DEPS AsanUnitTests)
   list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
 endif()

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Mon Sep 29 08:18:55 2014
@@ -55,7 +55,7 @@ else:
   config.available_features.add("asan-static-runtime")
 
 asan_lit_source_dir = get_required_attr(config, "asan_lit_source_dir")
-if config.android == "TRUE":
+if config.android == "1":
   config.available_features.add('android')
   clang_wrapper = os.path.join(asan_lit_source_dir,
                                "android_commands", "android_compile.py") + " "
@@ -108,7 +108,7 @@ python_exec = get_required_attr(config,
 config.substitutions.append( ("%sancov", python_exec + " " + sancov + " ") )
 
 # Determine kernel bitness
-if config.host_arch.find('64') != -1 and config.android != "TRUE":
+if config.host_arch.find('64') != -1 and config.android != "1":
   kernel_bits = '64'
 else:
   kernel_bits = '32'

Modified: compiler-rt/trunk/test/asan/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.site.cfg.in?rev=218605&r1=218604&r2=218605&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/asan/lit.site.cfg.in Mon Sep 29 08:18:55 2014
@@ -6,9 +6,9 @@ config.name_suffix = "@ASAN_TEST_CONFIG_
 config.asan_lit_source_dir = "@ASAN_LIT_SOURCE_DIR@"
 config.target_cflags = "@ASAN_TEST_TARGET_CFLAGS@"
 config.clang = "@ASAN_TEST_TARGET_CC@"
-config.llvm_tools_dir = "@ASAN_TEST_LLVM_TOOLS_DIR@"
+config.llvm_tools_dir = "@LLVM_TOOLS_BINARY_DIR@"
 config.bits = "@ASAN_TEST_BITS@"
-config.android = "@CAN_TARGET_arm_android@"
+config.android = "@ANDROID@"
 config.asan_dynamic = @ASAN_TEST_DYNAMIC@
 config.target_arch = "@ASAN_TEST_TARGET_ARCH@"
 





More information about the llvm-commits mailing list