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

Chandler Carruth chandlerc at gmail.com
Mon Jun 25 05:57:43 PDT 2012


Author: chandlerc
Date: Mon Jun 25 07:57:43 2012
New Revision: 159134

URL: http://llvm.org/viewvc/llvm-project?rev=159134&view=rev
Log:
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.

Added:
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
Modified:
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/interception/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=159134&r1=159133&r2=159134&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Mon Jun 25 07:57:43 2012
@@ -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 @@
   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 @@
 	set_property(TARGET clang_rt.asan-x86_64 APPEND PROPERTY COMPILE_DEFINITIONS
 		${ASAN_COMMON_DEFINITIONS})
 endif()
+
+if(LLVM_INCLUDE_TESTS)
+  add_subdirectory(tests)
+endif()

Added: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=159134&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Mon Jun 25 07:57:43 2012
@@ -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()
+

Modified: compiler-rt/trunk/lib/interception/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/CMakeLists.txt?rev=159134&r1=159133&r2=159134&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/interception/CMakeLists.txt Mon Jun 25 07:57:43 2012
@@ -13,7 +13,7 @@
   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)

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=159134&r1=159133&r2=159134&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Mon Jun 25 07:57:43 2012
@@ -13,7 +13,7 @@
   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)





More information about the llvm-commits mailing list