diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-01-21 10:51:18 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-01-21 10:51:18 +0000 |
commit | 6ad1d7809d1ea4b9c21af8dc6349f5a6a5df217e (patch) | |
tree | b718e4d34b3937d7639cc1b8022a1b64244abb10 /compiler-rt | |
parent | f940b2e3818f429364129a6c1bec5c402ab5a084 (diff) | |
download | bcm5719-llvm-6ad1d7809d1ea4b9c21af8dc6349f5a6a5df217e.tar.gz bcm5719-llvm-6ad1d7809d1ea4b9c21af8dc6349f5a6a5df217e.zip |
ASan: build unit tests with -fsanitize-address-zero-base-shadow on Linux and Android
llvm-svn: 173021
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/lib/asan/asan_intercepted_functions.h | 2 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_mapping.h | 4 | ||||
-rw-r--r-- | compiler-rt/lib/asan/tests/CMakeLists.txt | 44 | ||||
-rw-r--r-- | compiler-rt/lib/asan/tests/asan_noinst_test.cc | 3 |
4 files changed, 34 insertions, 19 deletions
diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h index 7f978c15bef..d4e8a8d39b9 100644 --- a/compiler-rt/lib/asan/asan_intercepted_functions.h +++ b/compiler-rt/lib/asan/asan_intercepted_functions.h @@ -255,6 +255,6 @@ DECLARE_FUNCTION_AND_WRAPPER(void, dispatch_source_set_cancel_handler, # endif // MAC_INTERPOSE_FUNCTIONS # endif // __APPLE__ } // extern "C" -#endif // defined(__APPLE__) || (defined(_WIN32) && !defined(_DLL)) +#endif // defined(__APPLE__) || (defined(_WIN32) && !defined(_DLL)) #endif // ASAN_INTERCEPTED_FUNCTIONS_H diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h index 5e3067031f4..8decdf337b3 100644 --- a/compiler-rt/lib/asan/asan_mapping.h +++ b/compiler-rt/lib/asan/asan_mapping.h @@ -111,6 +111,10 @@ static inline bool AddrIsInShadow(uptr a) { } static inline bool AddrIsInShadowGap(uptr a) { + // In zero-based shadow mode we treat addresses near zero as addresses + // in shadow gap as well. + if (ASAN_FLEXIBLE_MAPPING_AND_OFFSET) + return a <= kShadowGapEnd; return a >= kShadowGapBeg && a <= kShadowGapEnd; } diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index 272950bc545..132304a67b8 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -15,6 +15,13 @@ include(CompilerRTCompile) include_directories(..) include_directories(../..) +# Use zero-based shadow on Linux and Android. +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(ASAN_TESTS_USE_ZERO_BASE_SHADOW TRUE) +else() + set(ASAN_TESTS_USE_ZERO_BASE_SHADOW FALSE) +endif() + set(ASAN_UNITTEST_HEADERS asan_mac_test.h asan_test_config.h @@ -32,39 +39,38 @@ set(ASAN_UNITTEST_COMMON_CFLAGS -O2 ) +if(ASAN_TESTS_USE_ZERO_BASE_SHADOW) + list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -fPIE) +endif() if(SUPPORTS_NO_VARIADIC_MACROS_FLAG) list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -Wno-variadic-macros) endif() # Use -D instead of definitions to please custom compile command. +list(APPEND ASAN_UNITTEST_COMMON_CFLAGS + -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 + -DASAN_HAS_BLACKLIST=1 + -DASAN_HAS_EXCEPTIONS=1 + -DASAN_UAR=0) 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 - ) + -DASAN_NEEDS_SEGV=0) else() list(APPEND ASAN_UNITTEST_COMMON_CFLAGS - -DASAN_HAS_BLACKLIST=1 - -DASAN_HAS_EXCEPTIONS=1 - -DASAN_NEEDS_SEGV=1 - -DASAN_UAR=0 - ) + -DASAN_LOW_MEMORY=0 + -DASAN_NEEDS_SEGV=1) endif() set(ASAN_LINK_FLAGS) -if(ANDROID) - # On Android, we link with ASan runtime manually +if(ASAN_TESTS_USE_ZERO_BASE_SHADOW) list(APPEND ASAN_LINK_FLAGS -pie) -else() - # On other platforms, we depend on Clang driver behavior, - # passing -fsanitize=address flag. +endif() +# 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_LINK_FLAGS -fsanitize=address) endif() - # Unit tests on Mac depend on Foundation. if(APPLE) list(APPEND ASAN_LINK_FLAGS -framework Foundation) @@ -84,6 +90,10 @@ set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS -mllvm -asan-mapping-offset-log=-1 # default will be used -mllvm -asan-use-after-return=0 ) +if(ASAN_TESTS_USE_ZERO_BASE_SHADOW) + list(APPEND ASAN_UNITTEST_INSTRUMENTED_CFLAGS + -fsanitize-address-zero-base-shadow) +endif() # Compile source for the given architecture, using compiler # options in ${ARGN}, and add it to the object list. diff --git a/compiler-rt/lib/asan/tests/asan_noinst_test.cc b/compiler-rt/lib/asan/tests/asan_noinst_test.cc index 576312bf319..36dd3b2747f 100644 --- a/compiler-rt/lib/asan/tests/asan_noinst_test.cc +++ b/compiler-rt/lib/asan/tests/asan_noinst_test.cc @@ -330,7 +330,8 @@ TEST(AddressSanitizer, MemsetWildAddressTest) { // Prevent inlining of memset(). volatile memset_p libc_memset = (memset_p)memset; EXPECT_DEATH(libc_memset((void*)(kLowShadowBeg + 200), 0, 100), - "unknown-crash.*low shadow"); + ASAN_FLEXIBLE_MAPPING_AND_OFFSET ? "unknown-crash.*shadow gap" + : "unknown-crash.*low shadow"); EXPECT_DEATH(libc_memset((void*)(kShadowGapBeg + 200), 0, 100), "unknown-crash.*shadow gap"); EXPECT_DEATH(libc_memset((void*)(kHighShadowBeg + 200), 0, 100), |