[llvm-commits] [compiler-rt] r159255 - in /compiler-rt/trunk: CMakeLists.txt lib/asan/CMakeLists.txt lib/asan/tests/CMakeLists.txt
Alexey Samsonov
samsonov at google.com
Thu Jun 28 02:37:11 PDT 2012
+llvm-commits (accidentally lost in previous reply)
On Wed, Jun 27, 2012 at 4:38 PM, Alexey Samsonov <samsonov at google.com>wrote:
> OK, I can also launch asan unit tests (on Linux). However, it didn't work
> for me out-of-the-box
> (when I re-enabled cmake build of compiler-rt). I had to patch
> .../asan/tests/CMakeLists.txt as follows
>
> Before that custom "clang w/asan" compilation of tests that should be
> instrumented failed due
> to missing gtest headers.
>
> Index: tests/CMakeLists.txt
> ===================================================================
> --- tests/CMakeLists.txt (revision 159260)
> +++ tests/CMakeLists.txt (working copy)
> @@ -30,6 +30,13 @@
> asan_break_optimization.cc
> )
>
> +set(ASAN_EXTRA_CFLAGS
> + -I${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include
> + -I${LLVM_MAIN_SRC_DIR}/include
> + -I${LLVM_BINARY_DIR}/include
> + -D__STDC_CONSTANT_MACROS
> + -D__STDC_LIMIT_MACROS
> +)
>
> # 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
> @@ -43,7 +50,7 @@
> add_custom_command(
> OUTPUT "${source}.asan.o"
> COMMAND clang
> - -faddress-sanitizer ${ASAN_CFLAGS}
> + -faddress-sanitizer ${ASAN_CFLAGS} ${ASAN_EXTRA_CFLAGS}
> -mllvm
> "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"
> -DASAN_HAS_BLACKLIST=1
> -DASAN_HAS_EXCEPTIONS=1
>
I've just submitted this patch as r159343. PTAL if it's actually ok. This
implies, that in cmake build we don't
depend (and don't include) our custom checkout of googletest anymore and
use the one in LLVM trunk.
>
>
> Now it works for me like this:
> $ export LLVM_CHECKOUT=/home/samsonov/llvm-project/llvm2
> $ export CMAKE_DEFINES=-DCMAKE_BUILD_TYPE=Debug
> $ CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake $CMAKE_DEFINES $LLVM_CHECKOUT
> $ cd projects/compiler-rt/lib/asan/tests/
> $ make AsanTests
> $ ./Debug/AsanInstrumentationTests
> $ ./Debug/AsanNoInstrumentationTests --gtest_death_test_style=threadsafe
>
> Didn't check that this works on Mac, will take a look tomorrow.
> Will you change the structure of cmake files, or we can try to make it
> work for tsan?
>
> There are also llvm-regtest-like (that use FileCheck) output tests in both
> *san projects,
> what do we need to do to intergrate them to cmake build system as well?
>
> On Wed, Jun 27, 2012 at 1:01 PM, Chandler Carruth <chandlerc at gmail.com>wrote:
>
>> Author: chandlerc
>> Date: Wed Jun 27 04:01:24 2012
>> New Revision: 159255
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=159255&view=rev
>> Log:
>> Add support for building the ASan instrumentation unit tests with the
>> just-built Clang binary, and linking them against the just-built ASan
>> runtime.
>>
>> This is *very* brittle. I expect it will require tweaking, and I've
>> pro-actively disabled it on non-Unix builds and on cross-builds.
>>
>> It is also currently missing dependency edges on GoogleTest header files
>> and a few other corner cases, but those can be fixed. This is the major
>> milestone of a mini-bootstrap-like build of the unittest.
>>
>> Modified:
>> compiler-rt/trunk/CMakeLists.txt
>> compiler-rt/trunk/lib/asan/CMakeLists.txt
>> compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
>>
>> Modified: compiler-rt/trunk/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/CMakeLists.txt (original)
>> +++ compiler-rt/trunk/CMakeLists.txt Wed Jun 27 04:01:24 2012
>> @@ -48,6 +48,16 @@
>> COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}"
>> CMAKE_FLAGS
>> "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}")
>>
>> +# Because compiler-rt spends a lot of time setting up custom compile
>> flags,
>> +# define a handy helper function for it. The compile flags setting in
>> CMake
>> +# has serious issues that make its syntax challenging at best.
>> +function(set_target_compile_flags target)
>> + foreach(arg ${ARGN})
>> + set(argstring "${argstring} ${arg}")
>> + endforeach()
>> + set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")
>> +endfunction()
>> +
>> add_subdirectory(lib)
>>
>> if(LLVM_INCLUDE_TESTS)
>>
>> Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
>> +++ compiler-rt/trunk/lib/asan/CMakeLists.txt Wed Jun 27 04:01:24 2012
>> @@ -23,7 +23,12 @@
>>
>> include_directories(..)
>>
>> -set(ASAN_CFLAGS "-fPIC -fno-exceptions -funwind-tables
>> -fvisibility=hidden")
>> +set(ASAN_CFLAGS
>> + -fPIC
>> + -fno-exceptions
>> + -funwind-tables
>> + -fvisibility=hidden
>> + )
>>
>> set(ASAN_COMMON_DEFINITIONS
>> ASAN_HAS_EXCEPTIONS=1
>> @@ -36,8 +41,10 @@
>> $<TARGET_OBJECTS:RTInterception.x86_64>
>> $<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
>> )
>> - set_property(TARGET clang_rt.asan-x86_64 PROPERTY COMPILE_FLAGS
>> - "${ASAN_CFLAGS} ${TARGET_X86_64_CFLAGS}")
>> + set_target_compile_flags(clang_rt.asan-x86_64
>> + ${ASAN_CFLAGS}
>> + ${TARGET_X86_64_CFLAGS}
>> + )
>> set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY
>> COMPILE_DEFINITIONS
>> ${ASAN_COMMON_DEFINITIONS})
>> endif()
>> @@ -47,8 +54,10 @@
>> $<TARGET_OBJECTS:RTInterception.i386>
>> $<TARGET_OBJECTS:RTSanitizerCommon.i386>
>> )
>> - set_property(TARGET clang_rt.asan-i386 PROPERTY COMPILE_FLAGS
>> - "${ASAN_CFLAGS} ${TARGET_I386_CFLAGS}")
>> + set_target_compile_flags(clang_rt.asan-i386
>> + ${ASAN_CFLAGS}
>> + ${TARGET_I386_CFLAGS}
>> + )
>> set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY
>> COMPILE_DEFINITIONS
>> ${ASAN_COMMON_DEFINITIONS})
>> endif()
>>
>> 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=159255&r1=159254&r2=159255&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
>> +++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Wed Jun 27 04:01:24
>> 2012
>> @@ -30,26 +30,39 @@
>> 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)
>> +# 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)
>> +
>> + # This function is a custom routine to manage manually compiling
>> source files
>> + # for unit tests with the just-built Clang binary, using the ASan
>> + # instrumentation, and linking them into a test executable.
>> + function(add_asan_compile_command source)
>> + add_custom_command(
>> + OUTPUT "${source}.asan.o"
>> + COMMAND clang
>> + -faddress-sanitizer ${ASAN_CFLAGS}
>> + -mllvm
>> "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"
>> + -DASAN_HAS_BLACKLIST=1
>> + -DASAN_HAS_EXCEPTIONS=1
>> + -DASAN_NEEDS_SEGV=1
>> + -DASAN_UAR=0
>> + -c -o "${source}.asan.o"
>> + ${CMAKE_CURRENT_SOURCE_DIR}/${source}
>> + MAIN_DEPENDENCY ${source}
>> + DEPENDS clang ${ARGN}
>> + )
>> + endfunction()
>> +
>> + add_asan_compile_command(asan_globals_test.cc)
>> + add_asan_compile_command(asan_test.cc)
>> +
>> add_asan_test(AsanInstrumentationTests
>> - asan_globals_test.cc
>> - asan_test.cc
>> + asan_globals_test.cc.asan.o
>> + asan_test.cc.asan.o
>> 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()
>>
>> +endif()
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
>
> --
> Alexey Samsonov, MSK
>
>
--
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120628/3e10d15e/attachment.html>
More information about the llvm-commits
mailing list