forked from OSchip/llvm-project
Cleanup the handling of CFLAGS even more in the cmake build for ASan.
Add the initial support for building ASan tests. The first change here is to try to get the CFLAGS to more closely match those used by the old Makefile. There are probably still goofs here, ASan folks, your review would be appreciated. The second big change is to add support for building both instrumentation based an non-instrumentation based unittests for ASan. They are built a bit differently from how the old makefiles managed things. Specifically, there are two binaries, one for the non-instrumented case, and one for the instrumented case. Also, the instrumented unit tests rely on the host compiler supporting AddressSanitizer's intrumentation pass. This is kind-of gross, but I don't know of a better way yet. I've mailed llvmdev to discuss this issue. One big caveat is that the detection logic currently doesn't work. I've commented it out temporarily as I'd like to get feedback from the ASan developers, etc. llvm-svn: 159134
This commit is contained in:
parent
f0ad3606c7
commit
9359efa986
|
@ -1,7 +1,5 @@
|
|||
# Build for the AddressSanitizer runtime support library.
|
||||
|
||||
include_directories(..)
|
||||
|
||||
set(ASAN_SOURCES
|
||||
asan_allocator.cc
|
||||
asan_globals.cc
|
||||
|
@ -23,13 +21,14 @@ set(ASAN_SOURCES
|
|||
asan_win.cc
|
||||
)
|
||||
|
||||
set(ASAN_CFLAGS "-fvisibility=hidden")
|
||||
include_directories(..)
|
||||
|
||||
set(ASAN_CFLAGS "-fPIC -fno-exceptions -funwind-tables -fvisibility=hidden")
|
||||
|
||||
set(ASAN_COMMON_DEFINITIONS
|
||||
ASAN_UAR=0
|
||||
ASAN_HAS_EXCEPTIONS=1
|
||||
ASAN_HAS_BLACKLIST=1
|
||||
ASAN_NEEDS_SEGV=1)
|
||||
ASAN_NEEDS_SEGV=1
|
||||
)
|
||||
|
||||
if(CAN_TARGET_X86_64)
|
||||
add_library(clang_rt.asan-x86_64 STATIC
|
||||
|
@ -53,3 +52,7 @@ if(CAN_TARGET_I386)
|
|||
set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
${ASAN_COMMON_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
if(LLVM_INCLUDE_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
# Testing rules for AddressSanitizer.
|
||||
#
|
||||
# These are broken into two buckets. One set of tests directly interacts with
|
||||
# the runtime library and checks its functionality. These are the
|
||||
# no-instrumentation tests.
|
||||
#
|
||||
# Another group of tests relies upon the ability to compile the test with
|
||||
# address sanitizer instrumentation pass. These tests form "integration" tests
|
||||
# and have some elements of version skew -- they test the *host* compiler's
|
||||
# instrumentation against the just-built runtime library.
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
include_directories(..)
|
||||
include_directories(../..)
|
||||
|
||||
add_custom_target(AsanTests)
|
||||
set_target_properties(AsanTests PROPERTIES FOLDER "ASan tests")
|
||||
function(add_asan_test testname)
|
||||
add_unittest(AsanTests ${testname} ${ARGN})
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
target_link_libraries(${testname} clang_rt.asan-i386)
|
||||
else()
|
||||
target_link_libraries(${testname} clang_rt.asan-x86_64)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_asan_test(AsanNoInstrumentationTests
|
||||
asan_noinst_test.cc
|
||||
asan_break_optimization.cc
|
||||
)
|
||||
|
||||
# FIXME: Currently, this detection isn't working. Assume we're doing
|
||||
# a bootstrap build for now.
|
||||
set(HOST_HAS_ASAN on)
|
||||
#check_cxx_compiler_flag("-faddress-sanitizer" HOST_HAS_ASAN)
|
||||
|
||||
if(HOST_HAS_ASAN)
|
||||
add_asan_test(AsanInstrumentationTests
|
||||
asan_globals_test.cc
|
||||
asan_interface_test.cc
|
||||
asan_test.cc
|
||||
asan_break_optimization.cc
|
||||
)
|
||||
set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS
|
||||
" -faddress-sanitizer ${ASAN_CFLAGS}")
|
||||
set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS
|
||||
" -mllvm -asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore")
|
||||
set_property(TARGET AsanInstrumentationTests APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
ASAN_HAS_BLACKLIST=1
|
||||
ASAN_HAS_EXCEPTIONS=1
|
||||
ASAN_NEEDS_SEGV=1
|
||||
ASAN_UAR=0
|
||||
)
|
||||
endif()
|
||||
|
|
@ -13,7 +13,7 @@ if (APPLE)
|
|||
list(APPEND INTERCEPTION_SOURCES mach_override/mach_override.c)
|
||||
endif ()
|
||||
|
||||
set(INTERCEPTION_CFLAGS "-fvisibility=hidden")
|
||||
set(INTERCEPTION_CFLAGS "-fPIC -fno-exceptions -funwind-tables -fvisibility=hidden")
|
||||
|
||||
set(INTERCEPTION_COMMON_DEFINITIONS
|
||||
INTERCEPTION_HAS_EXCEPTIONS=1)
|
||||
|
|
|
@ -13,7 +13,7 @@ set(SANITIZER_SOURCES
|
|||
sanitizer_win.cc
|
||||
)
|
||||
|
||||
set(SANITIZER_CFLAGS "-fvisibility=hidden")
|
||||
set(SANITIZER_CFLAGS "-fPIC -fno-exceptions -funwind-tables -fvisibility=hidden")
|
||||
|
||||
set(SANITIZER_COMMON_DEFINITIONS
|
||||
SANITIZER_HAS_EXCEPTIONS=1)
|
||||
|
|
Loading…
Reference in New Issue