diff options
| author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2012-09-11 11:55:45 +0000 | 
|---|---|---|
| committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2012-09-11 11:55:45 +0000 | 
| commit | 1a8f8fa6c0eb8ad8ba78fa8ba9e255000d1d6a17 (patch) | |
| tree | 99d92d105182a2b4ff14628755c70b1b48159be1 | |
| parent | 68f23444b49bac771b202645ef54b38b51c72215 (diff) | |
| download | bcm5719-llvm-1a8f8fa6c0eb8ad8ba78fa8ba9e255000d1d6a17.tar.gz bcm5719-llvm-1a8f8fa6c0eb8ad8ba78fa8ba9e255000d1d6a17.zip  | |
CMake build rules for ASan Android runtime and tests.
llvm-svn: 163613
| -rw-r--r-- | compiler-rt/CMakeLists.txt | 21 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/CMakeLists.txt | 41 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/tests/CMakeLists.txt | 55 | ||||
| -rw-r--r-- | compiler-rt/lib/interception/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/CMakeLists.txt | 4 | 
5 files changed, 83 insertions, 42 deletions
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 1ad91715edc..d336eedda6c 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -48,20 +48,6 @@ try_compile(CAN_TARGET_I386 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE32}              COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}"              CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}") -if(LLVM_ANDROID_TOOLCHAIN_DIR) -  if(EXISTS ${LLVM_ANDROID_TOOLCHAIN_DIR}/arm-linux-androideabi) -    set(CAN_TARGET_ARM_ANDROID 1) -    set(TARGET_ARM_ANDROID_CFLAGS -      -target arm-linux-androideabi -      --sysroot=${LLVM_ANDROID_TOOLCHAIN_DIR}/sysroot -      -B${LLVM_ANDROID_TOOLCHAIN_DIR} -      ) -  else() -    set(CAN_TARGET_ARM_ANDROID 0) -  endif() -  # TODO: support i686 and MIPS Android toolchains -endif() -  function(filter_available_targets out_var)    set(archs)    foreach(arch ${ARGN}) @@ -106,6 +92,13 @@ function(set_target_compile_flags target)    set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")  endfunction() +function(set_target_link_flags target) +  foreach(arg ${ARGN}) +    set(argstring "${argstring} ${arg}") +  endforeach() +  set_property(TARGET ${target} PROPERTY LINK_FLAGS "${argstring}") +endfunction() +  # Compute the Clang version from the LLVM version.  # FIXME: We should be able to reuse CLANG_VERSION variable calculated  #        in Clang cmake files, instead of copying the rules here. diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index 235087f831d..884a718987d 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -30,11 +30,20 @@ include_directories(..)  set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) -set(ASAN_COMMON_DEFINITIONS -  ASAN_HAS_EXCEPTIONS=1 -  ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 -  ASAN_NEEDS_SEGV=1 -  ) +if(ANDROID) +  set(ASAN_COMMON_DEFINITIONS +    ASAN_HAS_EXCEPTIONS=1 +    ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 +    ASAN_NEEDS_SEGV=0 +    ASAN_LOW_MEMORY=1 +    ) +else() +  set(ASAN_COMMON_DEFINITIONS +    ASAN_HAS_EXCEPTIONS=1 +    ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 +    ASAN_NEEDS_SEGV=1 +    ) +endif()  set(ASAN_DYLIB_DEFINITIONS    ${ASAN_COMMON_DEFINITIONS} @@ -54,6 +63,17 @@ if(APPLE)    set_target_properties(clang_rt.asan_osx PROPERTIES      OSX_ARCHITECTURES "${ASAN_TARGETS}")    list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx) +elseif(ANDROID) +  add_library(clang_rt.asan-arm-android SHARED +    ${ASAN_SOURCES} +    $<TARGET_OBJECTS:RTInterception.arm.android> +    $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> +    ) +  set_target_compile_flags(clang_rt.asan-arm-android +    ${ASAN_CFLAGS} +    ) +  target_link_libraries(clang_rt.asan-arm-android dl) +  list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)  else()    # Otherwise, build separate libraries for each target.    if(CAN_TARGET_X86_64) @@ -78,17 +98,6 @@ else()        )      list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-i386)    endif() -  if(CAN_TARGET_ARM_ANDROID) -    add_library(clang_rt.asan-arm-android STATIC -      ${ASAN_SOURCES} -      $<TARGET_OBJECTS:RTInterception.arm.android> -      $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> -      ) -    set_target_compile_flags(clang_rt.asan-arm-android -      ${ASAN_CFLAGS} ${TARGET_ARM_ANDROID_CFLAGS} -      ) -    list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) -  endif()  endif()  set_property(TARGET ${ASAN_RUNTIME_LIBRARIES} APPEND PROPERTY diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index a998cd81fd7..b8ff061128e 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -15,17 +15,32 @@ include_directories(..)  include_directories(../..)  set(ASAN_UNITTEST_COMMON_CFLAGS -  # Use -D instead of definitions to please custom compile command. -  -DASAN_HAS_BLACKLIST=1 -  -DASAN_HAS_EXCEPTIONS=1 -  -DASAN_NEEDS_SEGV=1 -  -DASAN_UAR=0    -Wall    -Wno-format    -fvisibility=hidden    -g    -O2  ) + +# Use -D instead of definitions to please custom compile command. +if(ANDROID) +  list(APPEND ASAN_UNITTEST_COMMON_CFLAGS +    -DASAN_LOW_MEMORY=1 +    -DASAN_HAS_BLACKLIST=1 +    -DASAN_HAS_EXCEPTIONS=1 +    -DASAN_NEEDS_SEGV=0 +    -DASAN_UAR=0 +    -fPIE +  ) +else() +  list(APPEND ASAN_UNITTEST_COMMON_CFLAGS +    -DASAN_HAS_BLACKLIST=1 +    -DASAN_HAS_EXCEPTIONS=1 +    -DASAN_NEEDS_SEGV=1 +    -DASAN_UAR=0 +  ) +endif() +  # Support 64-bit and 32-bit builds.  if(LLVM_BUILD_32_BITS)    list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -m32) @@ -60,6 +75,8 @@ function(add_asan_test testsuite testname)      set_property(TARGET ${testname} APPEND PROPERTY                   LINK_FLAGS "-framework Foundation")      target_link_libraries(${testname} clang_rt.asan_osx) +  elseif (ANDROID) +    target_link_libraries(${testname} clang_rt.asan-arm-android)    elseif (UNIX)      # Linux-specific linker flags.      set_property(TARGET ${testname} APPEND PROPERTY @@ -89,7 +106,8 @@ set(ASAN_INST_TEST_OBJECTS)  # We only support building instrumented tests when we're not cross compiling  # and targeting a unix-like system where we can predict viable compilation and  # linking strategies. -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX) +# We use a different approach to build these tests for Android. See below. +if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID)    # This function is a custom routine to manage manually compiling source files    # for unit tests with the just-built Clang binary, using the ASan @@ -128,5 +146,26 @@ endif()  # Main AddressSanitizer unit tests.  add_custom_target(AsanUnitTests)  set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests") -add_asan_test(AsanUnitTests AsanTest ${ASAN_NOINST_TEST_SOURCES} -                                     ${ASAN_INST_TEST_OBJECTS}) + +if(ANDROID) +  set(ASAN_INST_TEST_SOURCES asan_globals_test.cc asan_test.cc) +  add_library(asan_noinst_test OBJECT +    ${ASAN_NOINST_TEST_SOURCES} +    ) +  set_target_compile_flags(asan_noinst_test +    ${ASAN_UNITTEST_COMMON_CFLAGS} ${ASAN_GTEST_INCLUDE_CFLAGS} +    ) +  add_asan_test(AsanUnitTests AsanTest +    ${ASAN_INST_TEST_SOURCES} +    $<TARGET_OBJECTS:asan_noinst_test> +    ) +  set_target_compile_flags(AsanTest +    ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${ASAN_GTEST_INCLUDE_CFLAGS} +    ) +  set_target_link_flags(AsanTest +    -pie +    ) +else() +  add_asan_test(AsanUnitTests AsanTest ${ASAN_NOINST_TEST_SOURCES} +    ${ASAN_INST_TEST_OBJECTS}) +endif() diff --git a/compiler-rt/lib/interception/CMakeLists.txt b/compiler-rt/lib/interception/CMakeLists.txt index 2c7619b68d1..00a3e8bf1e9 100644 --- a/compiler-rt/lib/interception/CMakeLists.txt +++ b/compiler-rt/lib/interception/CMakeLists.txt @@ -34,9 +34,9 @@ else()      set_target_compile_flags(RTInterception.i386        ${INTERCEPTION_CFLAGS} ${TARGET_I386_CFLAGS})    endif() -  if(CAN_TARGET_ARM_ANDROID) +  if(ANDROID)      add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES})      set_target_compile_flags(RTInterception.arm.android -      ${INTERCEPTION_CFLAGS} ${TARGET_ARM_ANDROID_CFLAGS}) +      ${INTERCEPTION_CFLAGS})    endif()  endif() diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt index c43e747fc89..4c24fceb3ed 100644 --- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt @@ -44,10 +44,10 @@ else()        ${SANITIZER_CFLAGS} ${TARGET_I386_CFLAGS})      list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.i386)    endif() -  if(CAN_TARGET_ARM_ANDROID) +  if(ANDROID)      add_library(RTSanitizerCommon.arm.android OBJECT ${SANITIZER_SOURCES})      set_target_compile_flags(RTSanitizerCommon.arm.android -      ${SANITIZER_CFLAGS} ${TARGET_ARM_ANDROID_CFLAGS}) +      ${SANITIZER_CFLAGS})      list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.arm.android)    endif()  endif()  | 

