[compiler-rt] r201680 - Add rudimentary support for running compiler-rt lit tests with GCC

Alexey Samsonov samsonov at google.com
Wed Feb 19 07:13:15 PST 2014


Author: samsonov
Date: Wed Feb 19 09:13:14 2014
New Revision: 201680

URL: http://llvm.org/viewvc/llvm-project?rev=201680&view=rev
Log:
Add rudimentary support for running compiler-rt lit tests with GCC

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/test/asan/lit.cfg
    compiler-rt/trunk/test/dfsan/lit.cfg
    compiler-rt/trunk/test/lit.common.cfg
    compiler-rt/trunk/test/lit.common.configured.in
    compiler-rt/trunk/test/lsan/lit.common.cfg
    compiler-rt/trunk/test/msan/lit.cfg
    compiler-rt/trunk/test/tsan/lit.cfg
    compiler-rt/trunk/test/ubsan/lit.common.cfg

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Wed Feb 19 09:13:14 2014
@@ -42,6 +42,7 @@ if (NOT COMPILER_RT_STANDALONE_BUILD)
          ${LLVM_INCLUDE_TESTS})
   # Use just-built Clang to compile/link tests.
   set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+  set(COMPILER_RT_TEST_COMPILER_ID Clang)
 else()
   # Take output dir and install path from the user.
   set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
@@ -51,6 +52,7 @@ else()
   option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF)
   # Use a host compiler to compile/link tests.
   set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER})
+  set(COMPILER_RT_TEST_COMPILER_ID ${CMAKE_C_COMPILER_ID})
 
   set(LLVM_CONFIG_PATH "" CACHE PATH "Path to llvm-config binary")
   if (NOT LLVM_CONFIG_PATH)

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Feb 19 09:13:14 2014
@@ -17,16 +17,22 @@ config.name = 'AddressSanitizer' + confi
 # Setup source root.
 config.test_source_root = os.path.dirname(__file__)
 
+# GCC-ASan doesn't link in all the necessary libraries automatically, so
+# we have to do it ourselves.
+if config.compiler_id == 'GNU':
+  extra_linkflags = ["-lpthread", "-lstdc++", "-ldl"]
+else:
+  extra_linkflags = []
 # Setup default compiler flags used with -fsanitize=address option.
 # FIXME: Review the set of required flags and check if it can be reduced.
-target_cflags = [get_required_attr(config, "target_cflags")]
-target_cxxflags = ["--driver-mode=g++"] + target_cflags
+target_cflags = [get_required_attr(config, "target_cflags")] + extra_linkflags
+target_cxxflags = config.cxx_mode_flags + target_cflags
 clang_asan_cflags = ["-fsanitize=address",
                      "-mno-omit-leaf-frame-pointer",
                      "-fno-omit-frame-pointer",
                      "-fno-optimize-sibling-calls",
                      "-g"] + target_cflags
-clang_asan_cxxflags = ["--driver-mode=g++"] + clang_asan_cflags
+clang_asan_cxxflags = config.cxx_mode_flags + clang_asan_cflags
 
 asan_lit_source_dir = get_required_attr(config, "asan_lit_source_dir")
 if config.android == "TRUE":
@@ -63,6 +69,15 @@ config.available_features.add("asan-" +
 if config.host_os == 'Linux' and config.bits == '64':
   config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
 
+# GCC-ASan uses dynamic runtime by default, so we have to set LD_LIBRARY_PATH
+# to pick it up properly.
+if config.compiler_id == 'GNU':
+  gcc_dir = os.path.dirname(config.clang)
+  libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits)
+  new_ld_library_path = os.path.pathsep.join(
+    (libasan_dir, config.environment['LD_LIBRARY_PATH']))
+  config.environment['LD_LIBRARY_PATH'] = new_ld_library_path
+
 # Default test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']
 

Modified: compiler-rt/trunk/test/dfsan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/dfsan/lit.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/dfsan/lit.cfg (original)
+++ compiler-rt/trunk/test/dfsan/lit.cfg Wed Feb 19 09:13:14 2014
@@ -10,7 +10,7 @@ config.test_source_root = os.path.dirnam
 
 # Setup default compiler flags used with -fsanitize=dataflow option.
 clang_dfsan_cflags = ["-fsanitize=dataflow"]
-clang_dfsan_cxxflags = ["--driver-mode=g++"] + clang_dfsan_cflags
+clang_dfsan_cxxflags = config.cxx_mode_flags + clang_dfsan_cflags
 
 def build_invocation(compile_flags):
   return " " + " ".join([config.clang] + compile_flags) + " "

Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Wed Feb 19 09:13:14 2014
@@ -14,9 +14,17 @@ execute_external = (platform.system() !=
 config.test_format = lit.formats.ShTest(execute_external)
 
 # Setup clang binary.
-clang_path = getattr(config, 'clang', None)
-if (not clang_path) or (not os.path.exists(clang_path)):
-  lit_config.fatal("Can't find Clang on path %r" % clang_path)
+compiler_path = getattr(config, 'clang', None)
+if (not compiler_path) or (not os.path.exists(compiler_path)):
+  lit_config.fatal("Can't find compiler on path %r" % compiler_path)
+
+compiler_id = getattr(config, 'compiler_id', None)
+if compiler_id == "Clang":
+  config.cxx_mode_flags = ["--driver-mode=g++"]
+elif compiler_id == 'GNU':
+  config.cxx_mode_flags = ["-x c++"]
+else:
+  lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
 
 # Clear some environment variables that might affect Clang.
 possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',

Modified: compiler-rt/trunk/test/lit.common.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.configured.in?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.configured.in (original)
+++ compiler-rt/trunk/test/lit.common.configured.in Wed Feb 19 09:13:14 2014
@@ -16,6 +16,7 @@ set_default("llvm_obj_root", "@LLVM_BINA
 set_default("compiler_rt_src_root", "@COMPILER_RT_SOURCE_DIR@")
 set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@")
 set_default("clang", "@COMPILER_RT_TEST_COMPILER@")
+set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@")
 set_default("compiler_rt_arch", "@COMPILER_RT_SUPPORTED_ARCH@")
 set_default("python_executable", "@PYTHON_EXECUTABLE@")
 set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)

Modified: compiler-rt/trunk/test/lsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lsan/lit.common.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/lsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lsan/lit.common.cfg Wed Feb 19 09:13:14 2014
@@ -30,7 +30,7 @@ else:
   lit_config.fatal("Unknown LSan test mode: %r" % lsan_lit_test_mode)
 
 clang_cflags = ["-g", "-O0", "-m64"]
-clang_cxxflags = ["--driver-mode=g++"] + clang_cflags
+clang_cxxflags = config.cxx_mode_flags + clang_cflags
 clang_lsan_cflags = clang_cflags + lsan_cflags
 clang_lsan_cxxflags = clang_cxxflags + lsan_cflags
 

Modified: compiler-rt/trunk/test/msan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/lit.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/lit.cfg (original)
+++ compiler-rt/trunk/test/msan/lit.cfg Wed Feb 19 09:13:14 2014
@@ -15,7 +15,7 @@ clang_msan_cflags = ["-fsanitize=memory"
                      "-fno-optimize-sibling-calls",
                      "-g",
                      "-m64"]
-clang_msan_cxxflags = ["--driver-mode=g++"] + clang_msan_cflags
+clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags
 
 def build_invocation(compile_flags):
   return " " + " ".join([config.clang] + compile_flags) + " "

Modified: compiler-rt/trunk/test/tsan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/lit.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/lit.cfg (original)
+++ compiler-rt/trunk/test/tsan/lit.cfg Wed Feb 19 09:13:14 2014
@@ -30,7 +30,7 @@ clang_tsan_cflags = ["-fsanitize=thread"
                      "-lpthread",
                      "-ldl",
                      "-m64"]
-clang_tsan_cxxflags = ["--driver-mode=g++"] + clang_tsan_cflags
+clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags
 
 def build_invocation(compile_flags):
   return " " + " ".join([config.clang] + compile_flags) + " "

Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=201680&r1=201679&r2=201680&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Wed Feb 19 09:13:14 2014
@@ -28,7 +28,7 @@ else:
 def build_invocation(compile_flags):
   return " " + " ".join([config.clang] + compile_flags) + " "
 
-clang_ubsan_cxxflags = ["--driver-mode=g++"] + clang_ubsan_cflags
+clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
 
 # Define %clang and %clangxx substitutions to use in test RUN lines.
 config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )





More information about the llvm-commits mailing list