+llvm-commits (accidentally lost in previous reply)<div><br></div><div><br><div><br><div class="gmail_quote">On Wed, Jun 27, 2012 at 4:38 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:arial,helvetica,sans-serif"><font><div>OK, I can also launch asan unit tests (on Linux). However, it didn't work for me out-of-the-box</div>
<div>(when I re-enabled cmake build of compiler-rt). I had to patch .../asan/tests/CMakeLists.txt as follows</div>
<div><br></div><div>Before that custom "clang w/asan" compilation of tests that should be instrumented failed due</div><div>to missing gtest headers.</div><div><br></div><div>Index: tests/CMakeLists.txt</div><div>
<div>===================================================================</div><div>--- tests/CMakeLists.txt<span style="white-space:pre-wrap"> </span>(revision 159260)</div><div>+++ tests/CMakeLists.txt<span style="white-space:pre-wrap"> </span>(working copy)</div>
<div>@@ -30,6 +30,13 @@</div><div> <span style="white-space:pre-wrap"> </span>asan_break_optimization.cc</div><div> <span style="white-space:pre-wrap"> </span>)</div><div> </div><div>+set(ASAN_EXTRA_CFLAGS</div>
<div>+ -I${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include</div><div>+ -I${LLVM_MAIN_SRC_DIR}/include</div><div>+ -I${LLVM_BINARY_DIR}/include</div><div>+ -D__STDC_CONSTANT_MACROS</div><div>+ -D__STDC_LIMIT_MACROS</div>
<div>+)</div><div class="im"><div> </div><div> # We only support building instrumented tests when we're not cross compiling</div></div><div class="im"><div> # and targeting a unix-like system where we can predict viable compilation and</div>
</div><div>@@ -43,7 +50,7 @@</div>
<div> add_custom_command(</div><div> OUTPUT "${source}.asan.o"</div><div> COMMAND clang</div><div>- -faddress-sanitizer ${ASAN_CFLAGS}</div><div>+ -faddress-sanitizer ${ASAN_CFLAGS} ${ASAN_EXTRA_CFLAGS}</div>
<div> -mllvm "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"</div><div> -DASAN_HAS_BLACKLIST=1</div><div> -DASAN_HAS_EXCEPTIONS=1</div></div></font></div>
</blockquote><div><br></div><div>I've just submitted this patch as r159343. PTAL if it's actually ok. This implies, that in cmake build we don't</div><div>depend (and don't include) our custom checkout of googletest anymore and use the one in LLVM trunk.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:arial,helvetica,sans-serif"><font><div><br></div>
<div><br></div><div>Now it works for me like this:</div><div><div>$ export LLVM_CHECKOUT=/home/samsonov/llvm-project/llvm2</div><div><div>$ export CMAKE_DEFINES=-DCMAKE_BUILD_TYPE=Debug</div><div>$ CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake $CMAKE_DEFINES $LLVM_CHECKOUT</div>
</div><div>$ cd projects/compiler-rt/lib/asan/tests/</div><div>$ make AsanTests</div><div>$ ./Debug/AsanInstrumentationTests</div><div>$ ./Debug/AsanNoInstrumentationTests --gtest_death_test_style=threadsafe</div><div><br>
</div><div>Didn't check that this works on Mac, will take a look tomorrow.</div><div>Will you change the structure of cmake files, or we can try to make it work for tsan?</div><div><br></div><div>There are also llvm-regtest-like (that use FileCheck) output tests in both *san projects,</div>
<div>what do we need to do to intergrate them to cmake build system as well?</div><div><br></div></div><div><div class="h5"><div class="gmail_quote">On Wed, Jun 27, 2012 at 1:01 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chandlerc<br>
Date: Wed Jun 27 04:01:24 2012<br>
New Revision: 159255<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=159255&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=159255&view=rev</a><br>
Log:<br>
Add support for building the ASan instrumentation unit tests with the<br>
just-built Clang binary, and linking them against the just-built ASan<br>
runtime.<br>
<br>
This is *very* brittle. I expect it will require tweaking, and I've<br>
pro-actively disabled it on non-Unix builds and on cross-builds.<br>
<br>
It is also currently missing dependency edges on GoogleTest header files<br>
and a few other corner cases, but those can be fixed. This is the major<br>
milestone of a mini-bootstrap-like build of the unittest.<br>
<br>
Modified:<br>
compiler-rt/trunk/CMakeLists.txt<br>
compiler-rt/trunk/lib/asan/CMakeLists.txt<br>
compiler-rt/trunk/lib/asan/tests/CMakeLists.txt<br>
<br>
Modified: compiler-rt/trunk/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/CMakeLists.txt Wed Jun 27 04:01:24 2012<br>
@@ -48,6 +48,16 @@<br>
COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}"<br>
CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}")<br>
<br>
+# Because compiler-rt spends a lot of time setting up custom compile flags,<br>
+# define a handy helper function for it. The compile flags setting in CMake<br>
+# has serious issues that make its syntax challenging at best.<br>
+function(set_target_compile_flags target)<br>
+ foreach(arg ${ARGN})<br>
+ set(argstring "${argstring} ${arg}")<br>
+ endforeach()<br>
+ set_property(TARGET ${target} PROPERTY COMPILE_FLAGS "${argstring}")<br>
+endfunction()<br>
+<br>
add_subdirectory(lib)<br>
<br>
if(LLVM_INCLUDE_TESTS)<br>
<br>
Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Wed Jun 27 04:01:24 2012<br>
@@ -23,7 +23,12 @@<br>
<br>
include_directories(..)<br>
<br>
-set(ASAN_CFLAGS "-fPIC -fno-exceptions -funwind-tables -fvisibility=hidden")<br>
+set(ASAN_CFLAGS<br>
+ -fPIC<br>
+ -fno-exceptions<br>
+ -funwind-tables<br>
+ -fvisibility=hidden<br>
+ )<br>
<br>
set(ASAN_COMMON_DEFINITIONS<br>
ASAN_HAS_EXCEPTIONS=1<br>
@@ -36,8 +41,10 @@<br>
$<TARGET_OBJECTS:RTInterception.x86_64><br>
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64><br>
)<br>
- set_property(TARGET clang_rt.asan-x86_64 PROPERTY COMPILE_FLAGS<br>
- "${ASAN_CFLAGS} ${TARGET_X86_64_CFLAGS}")<br>
+ set_target_compile_flags(clang_rt.asan-x86_64<br>
+ ${ASAN_CFLAGS}<br>
+ ${TARGET_X86_64_CFLAGS}<br>
+ )<br>
set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS<br>
${ASAN_COMMON_DEFINITIONS})<br>
endif()<br>
@@ -47,8 +54,10 @@<br>
$<TARGET_OBJECTS:RTInterception.i386><br>
$<TARGET_OBJECTS:RTSanitizerCommon.i386><br>
)<br>
- set_property(TARGET clang_rt.asan-i386 PROPERTY COMPILE_FLAGS<br>
- "${ASAN_CFLAGS} ${TARGET_I386_CFLAGS}")<br>
+ set_target_compile_flags(clang_rt.asan-i386<br>
+ ${ASAN_CFLAGS}<br>
+ ${TARGET_I386_CFLAGS}<br>
+ )<br>
set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS<br>
${ASAN_COMMON_DEFINITIONS})<br>
endif()<br>
<br>
Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=159255&r1=159254&r2=159255&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Wed Jun 27 04:01:24 2012<br>
@@ -30,26 +30,39 @@<br>
asan_break_optimization.cc<br>
)<br>
<br>
-# FIXME: Currently, this detection isn't working. Assume we're doing<br>
-# a bootstrap build for now.<br>
-set(HOST_HAS_ASAN on)<br>
-#check_cxx_compiler_flag("-faddress-sanitizer" HOST_HAS_ASAN)<br>
<br>
-if(HOST_HAS_ASAN)<br>
+# We only support building instrumented tests when we're not cross compiling<br>
+# and targeting a unix-like system where we can predict viable compilation and<br>
+# linking strategies.<br>
+if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX)<br>
+<br>
+ # This function is a custom routine to manage manually compiling source files<br>
+ # for unit tests with the just-built Clang binary, using the ASan<br>
+ # instrumentation, and linking them into a test executable.<br>
+ function(add_asan_compile_command source)<br>
+ add_custom_command(<br>
+ OUTPUT "${source}.asan.o"<br>
+ COMMAND clang<br>
+ -faddress-sanitizer ${ASAN_CFLAGS}<br>
+ -mllvm "-asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore"<br>
+ -DASAN_HAS_BLACKLIST=1<br>
+ -DASAN_HAS_EXCEPTIONS=1<br>
+ -DASAN_NEEDS_SEGV=1<br>
+ -DASAN_UAR=0<br>
+ -c -o "${source}.asan.o"<br>
+ ${CMAKE_CURRENT_SOURCE_DIR}/${source}<br>
+ MAIN_DEPENDENCY ${source}<br>
+ DEPENDS clang ${ARGN}<br>
+ )<br>
+ endfunction()<br>
+<br>
+ add_asan_compile_command(asan_globals_test.cc)<br>
+ add_asan_compile_command(asan_test.cc)<br>
+<br>
add_asan_test(AsanInstrumentationTests<br>
- asan_globals_test.cc<br>
- asan_test.cc<br>
+ asan_globals_test.cc.asan.o<br>
+ asan_test.cc.asan.o<br>
asan_break_optimization.cc<br>
)<br>
- set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS<br>
- " -faddress-sanitizer ${ASAN_CFLAGS}")<br>
- set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS<br>
- " -mllvm -asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore")<br>
- set_property(TARGET AsanInstrumentationTests APPEND PROPERTY COMPILE_DEFINITIONS<br>
- ASAN_HAS_BLACKLIST=1<br>
- ASAN_HAS_EXCEPTIONS=1<br>
- ASAN_NEEDS_SEGV=1<br>
- ASAN_UAR=0<br>
- )<br>
-endif()<br>
<br>
+endif()<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>Alexey Samsonov, MSK</div><br>
</font></span></font></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>
</div></div>