[llvm-commits] [compiler-rt] r159255 - in /compiler-rt/trunk: CMakeLists.txt lib/asan/CMakeLists.txt lib/asan/tests/CMakeLists.txt

Chandler Carruth chandlerc at gmail.com
Wed Jun 27 02:01:24 PDT 2012


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()





More information about the llvm-commits mailing list