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 | 34fc56c43f60be0b85a0e3ce30658fd98951f0b8 (patch) | |
tree | f4737661cd3d631d5ee616f03854deecd063425e /lib | |
parent | 7e72e45e3b725ef29b82fd4386c6571d64f9b6cc (diff) |
CMake build rules for ASan Android runtime and tests.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163613 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asan/CMakeLists.txt | 41 | ||||
-rw-r--r-- | lib/asan/tests/CMakeLists.txt | 55 | ||||
-rw-r--r-- | lib/interception/CMakeLists.txt | 4 | ||||
-rw-r--r-- | lib/sanitizer_common/CMakeLists.txt | 4 |
4 files changed, 76 insertions, 28 deletions
diff --git a/lib/asan/CMakeLists.txt b/lib/asan/CMakeLists.txt index 235087f83..884a71898 100644 --- a/lib/asan/CMakeLists.txt +++ b/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/lib/asan/tests/CMakeLists.txt b/lib/asan/tests/CMakeLists.txt index a998cd81f..b8ff06112 100644 --- a/lib/asan/tests/CMakeLists.txt +++ b/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/lib/interception/CMakeLists.txt b/lib/interception/CMakeLists.txt index 2c7619b68..00a3e8bf1 100644 --- a/lib/interception/CMakeLists.txt +++ b/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/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt index c43e747fc..4c24fceb3 100644 --- a/lib/sanitizer_common/CMakeLists.txt +++ b/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() |